a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
atproto bluesky typescript npm
101
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(oauth-cab)!: alter the client code a little

Mary ad63f242 9ab26de2

+8 -54
+2 -2
packages/oauth/cab/README.md
··· 67 67 ### client-side (browser) 68 68 69 69 ```ts 70 - import { createCABFetcher } from '@atcute/oauth-cab/client'; 70 + import { createCabFetcher } from '@atcute/oauth-cab/client'; 71 71 import { configureOAuth } from '@atcute/oauth-browser-client'; 72 72 73 73 configureOAuth({ 74 74 // ... other options 75 - fetchClientAssertion: createCABFetcher(), // defaults to location.origin 75 + fetchClientAssertion: createCabFetcher(), // defaults to location.origin 76 76 }); 77 77 ```
+6 -17
packages/oauth/cab/lib/client/index.ts
··· 1 1 import { Client, simpleFetchHandler } from '@atcute/client'; 2 - 3 - // import lexicon types to augment XRPCProcedures 4 - import '../lexicons/index.js'; 5 - 6 - import type { 7 - ClientAssertionCredentials, 8 - ClientAssertionFetcher, 9 - FetchClientAssertionParams, 10 - } from './types.js'; 2 + import type { ClientAssertionFetcher } from '@atcute/oauth-browser-client'; 11 3 12 - const CLIENT_ASSERTION_TYPE_JWT_BEARER = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'; 4 + import type {} from '../lexicons/index.js'; 13 5 14 6 /** 15 7 * options for creating a CAB fetcher 16 8 */ 17 - export interface CreateCABFetcherOptions { 9 + export interface CreateCabFetcherOptions { 18 10 /** URL of CAB backend (defaults to location.origin) */ 19 11 service?: string | URL; 20 12 /** optional custom fetch implementation */ ··· 29 21 * @param options fetcher configuration 30 22 * @returns client assertion fetcher for use with oauth-browser-client 31 23 */ 32 - export const createCABFetcher = (options: CreateCABFetcherOptions = {}): ClientAssertionFetcher => { 24 + export const createCabFetcher = (options: CreateCabFetcherOptions = {}): ClientAssertionFetcher => { 33 25 const serviceUrl = new URL(options.service ?? location.origin); 34 26 35 27 const client = new Client({ ··· 39 31 }), 40 32 }); 41 33 42 - return async (params: FetchClientAssertionParams): Promise<ClientAssertionCredentials> => { 34 + return async (params) => { 43 35 const { aud, createDpopProof } = params; 44 36 45 37 // build the endpoint URL for DPoP proof (htu is origin + pathname only) ··· 76 68 const { client_assertion } = response.data; 77 69 78 70 return { 71 + client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer', 79 72 client_assertion, 80 - client_assertion_type: CLIENT_ASSERTION_TYPE_JWT_BEARER, 81 73 }; 82 74 }; 83 75 }; 84 - 85 - // re-export types for convenience 86 - export type { ClientAssertionCredentials, ClientAssertionFetcher, FetchClientAssertionParams };
-35
packages/oauth/cab/lib/client/types.ts
··· 1 - /** 2 - * client assertion credentials returned from a CAB backend. 3 - */ 4 - export interface ClientAssertionCredentials { 5 - /** the signed JWT assertion */ 6 - client_assertion: string; 7 - /** the assertion type (always jwt-bearer) */ 8 - client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'; 9 - } 10 - 11 - /** 12 - * parameters for fetching a client assertion. 13 - */ 14 - export interface FetchClientAssertionParams { 15 - /** JWK thumbprint of the DPoP key to bind the assertion to */ 16 - jkt: string; 17 - /** authorization server issuer (audience for the assertion) */ 18 - aud: string; 19 - 20 - /** 21 - * create a DPoP proof to prove you possess the key for the claimed jkt. 22 - * 23 - * @param htu origin and pathname to the CAB backend 24 - * @param nonce optional DPoP nonce from the server 25 - * @returns DPoP proof that can be included in the request 26 - */ 27 - createDpopProof: (htu: string, nonce?: string) => Promise<string>; 28 - } 29 - 30 - /** 31 - * function that fetches a client assertion from a CAB backend. 32 - */ 33 - export type ClientAssertionFetcher = ( 34 - params: FetchClientAssertionParams, 35 - ) => Promise<ClientAssertionCredentials>;