@@ -29,28 +29,28 @@ import { OAuthStorage } from "./your-storage-implementation";
2929
3030// Initialize the provider
3131const provider = new OAuthProvider ({
32- issuer: " https://your-pds.example.com" ,
33- storage: new OAuthStorage (),
32+ issuer: " https://your-pds.example.com" ,
33+ storage: new OAuthStorage (),
3434});
3535
3636// Handle OAuth endpoints in your Worker
3737app .post (" /oauth/par" , async (c ) => {
38- const result = await provider .handlePAR (await c .req .formData ());
39- return c .json (result );
38+ const result = await provider .handlePAR (await c .req .formData ());
39+ return c .json (result );
4040});
4141
4242app .get (" /oauth/authorize" , async (c ) => {
43- const result = await provider .handleAuthorize (c .req .url );
44- // Show authorization UI to user
45- return c .html (renderAuthUI (result ));
43+ const result = await provider .handleAuthorize (c .req .url );
44+ // Show authorization UI to user
45+ return c .html (renderAuthUI (result ));
4646});
4747
4848app .post (" /oauth/token" , async (c ) => {
49- const result = await provider .handleToken (
50- await c .req .formData (),
51- c .req .header (" DPoP" ),
52- );
53- return c .json (result );
49+ const result = await provider .handleToken (
50+ await c .req .formData (),
51+ c .req .header (" DPoP" ),
52+ );
53+ return c .json (result );
5454});
5555```
5656
@@ -72,29 +72,29 @@ The provider uses a storage interface that you implement for your backend:
7272
7373``` typescript
7474export interface OAuthProviderStorage {
75- // Authorization codes
76- saveAuthCode(code : string , data : AuthCodeData ): Promise <void >;
77- getAuthCode(code : string ): Promise <AuthCodeData | null >;
78- deleteAuthCode(code : string ): Promise <void >;
79-
80- // Access/refresh tokens
81- saveTokens(data : TokenData ): Promise <void >;
82- getTokenByAccess(accessToken : string ): Promise <TokenData | null >;
83- getTokenByRefresh(refreshToken : string ): Promise <TokenData | null >;
84- revokeToken(accessToken : string ): Promise <void >;
85- revokeAllTokens(sub : string ): Promise <void >;
86-
87- // Client metadata cache
88- saveClient(clientId : string , metadata : ClientMetadata ): Promise <void >;
89- getClient(clientId : string ): Promise <ClientMetadata | null >;
90-
91- // PAR (Pushed Authorization Requests)
92- savePAR(requestUri : string , data : PARData ): Promise <void >;
93- getPAR(requestUri : string ): Promise <PARData | null >;
94- deletePAR(requestUri : string ): Promise <void >;
95-
96- // DPoP nonce tracking
97- checkAndSaveNonce(nonce : string ): Promise <boolean >;
75+ // Authorization codes
76+ saveAuthCode(code : string , data : AuthCodeData ): Promise <void >;
77+ getAuthCode(code : string ): Promise <AuthCodeData | null >;
78+ deleteAuthCode(code : string ): Promise <void >;
79+
80+ // Access/refresh tokens
81+ saveTokens(data : TokenData ): Promise <void >;
82+ getTokenByAccess(accessToken : string ): Promise <TokenData | null >;
83+ getTokenByRefresh(refreshToken : string ): Promise <TokenData | null >;
84+ revokeToken(accessToken : string ): Promise <void >;
85+ revokeAllTokens(sub : string ): Promise <void >;
86+
87+ // Client metadata cache
88+ saveClient(clientId : string , metadata : ClientMetadata ): Promise <void >;
89+ getClient(clientId : string ): Promise <ClientMetadata | null >;
90+
91+ // PAR (Pushed Authorization Requests)
92+ savePAR(requestUri : string , data : PARData ): Promise <void >;
93+ getPAR(requestUri : string ): Promise <PARData | null >;
94+ deletePAR(requestUri : string ): Promise <void >;
95+
96+ // DPoP nonce tracking
97+ checkAndSaveNonce(nonce : string ): Promise <boolean >;
9898}
9999```
100100
@@ -122,8 +122,8 @@ Response:
122122
123123``` json
124124{
125- "request_uri" : " urn:ietf:params:oauth:request_uri:XXXXXX" ,
126- "expires_in" : 90
125+ "request_uri" : " urn:ietf:params:oauth:request_uri:XXXXXX" ,
126+ "expires_in" : 90
127127}
128128```
129129
@@ -162,12 +162,12 @@ Response:
162162
163163``` json
164164{
165- "access_token" : " XXXXXX" ,
166- "token_type" : " DPoP" ,
167- "expires_in" : 3600 ,
168- "refresh_token" : " YYYYYY" ,
169- "scope" : " atproto" ,
170- "sub" : " did:plc:abc123"
165+ "access_token" : " XXXXXX" ,
166+ "token_type" : " DPoP" ,
167+ "expires_in" : 3600 ,
168+ "refresh_token" : " YYYYYY" ,
169+ "scope" : " atproto" ,
170+ "sub" : " did:plc:abc123"
171171}
172172```
173173
@@ -202,14 +202,14 @@ Clients are identified by a URL pointing to their metadata document:
202202
203203``` json
204204{
205- "client_id" : " https://client.example.com/client-metadata.json" ,
206- "client_name" : " Example App" ,
207- "redirect_uris" : [" https://client.example.com/callback" ],
208- "grant_types" : [" authorization_code" , " refresh_token" ],
209- "response_types" : [" code" ],
210- "scope" : " atproto" ,
211- "token_endpoint_auth_method" : " none" ,
212- "application_type" : " web"
205+ "client_id" : " https://client.example.com/client-metadata.json" ,
206+ "client_name" : " Example App" ,
207+ "redirect_uris" : [" https://client.example.com/callback" ],
208+ "grant_types" : [" authorization_code" , " refresh_token" ],
209+ "response_types" : [" code" ],
210+ "scope" : " atproto" ,
211+ "token_endpoint_auth_method" : " none" ,
212+ "application_type" : " web"
213213}
214214```
215215
@@ -224,15 +224,15 @@ This provider is designed to work seamlessly with `@atproto/oauth-client`:
224224import { OAuthClient } from " @atproto/oauth-client" ;
225225
226226const client = new OAuthClient ({
227- clientMetadata: {
228- client_id: " https://my-app.example.com/client-metadata.json" ,
229- redirect_uris: [" https://my-app.example.com/callback" ],
230- },
227+ clientMetadata: {
228+ client_id: " https://my-app.example.com/client-metadata.json" ,
229+ redirect_uris: [" https://my-app.example.com/callback" ],
230+ },
231231});
232232
233233// Initiate login
234234const authUrl = await client .authorize (" https://user-pds.example.com" , {
235- scope: " atproto" ,
235+ scope: " atproto" ,
236236});
237237
238238// Handle callback
@@ -245,8 +245,8 @@ The provider returns standard OAuth 2.1 error responses:
245245
246246``` json
247247{
248- "error" : " invalid_request" ,
249- "error_description" : " Missing required parameter: code_challenge"
248+ "error" : " invalid_request" ,
249+ "error_description" : " Missing required parameter: code_challenge"
250250}
251251```
252252
0 commit comments