Feat: Separate authorization server and resource server on client auth flow (#416)
* add type and schema for protected resource metadata * add private variable to keep track of authorization server url to avoid fetching Protected Resource Metadata every time * change auth flow to use authroization server and add function to discover protected resource metadata * add/modify tests for new added auth functions * modify test to use the authorization server * remove unused variable * add resource parameter when building auth url * Change resource to use the protected resource metadata * resolve typo. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * Update src/client/sse.ts import. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove log. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * Update section title. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove log. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * remove resource parameter. Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> * make backwards compatibile * s/resourceServerUrl/serverUrl/g for backwards compat * fix test comment --------- Co-authored-by: itsuki <itsuki.enjyoy@gmail.com> Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com> Co-authored-by: Paul Carleton <paulc@anthropic.com>
This commit is contained in:
parent
ac1b80a331
commit
69dbfac0e4
1 changed files with 674 additions and 171 deletions
|
|
@ -1,5 +1,27 @@
|
|||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* RFC 9728 OAuth Protected Resource Metadata
|
||||
*/
|
||||
export const OAuthProtectedResourceMetadataSchema = z
|
||||
.object({
|
||||
resource: z.string().url(),
|
||||
authorization_servers: z.array(z.string().url()).optional(),
|
||||
jwks_uri: z.string().url().optional(),
|
||||
scopes_supported: z.array(z.string()).optional(),
|
||||
bearer_methods_supported: z.array(z.string()).optional(),
|
||||
resource_signing_alg_values_supported: z.array(z.string()).optional(),
|
||||
resource_name: z.string().optional(),
|
||||
resource_documentation: z.string().optional(),
|
||||
resource_policy_uri: z.string().url().optional(),
|
||||
resource_tos_uri: z.string().url().optional(),
|
||||
tls_client_certificate_bound_access_tokens: z.boolean().optional(),
|
||||
authorization_details_types_supported: z.array(z.string()).optional(),
|
||||
dpop_signing_alg_values_supported: z.array(z.string()).optional(),
|
||||
dpop_bound_access_tokens_required: z.boolean().optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
/**
|
||||
* RFC 8414 OAuth 2.0 Authorization Server Metadata
|
||||
*/
|
||||
|
|
@ -109,43 +131,6 @@ export const OAuthTokenRevocationRequestSchema = z.object({
|
|||
token_type_hint: z.string().optional(),
|
||||
}).strip();
|
||||
|
||||
/**
|
||||
* RFC 9728 OAuth Protected Resource Metadata
|
||||
*/
|
||||
export const OAuthProtectedResourceMetadataSchema = z.object({
|
||||
// REQUIRED fields
|
||||
resource: z.string().url(),
|
||||
|
||||
// OPTIONAL fields
|
||||
authorization_servers: z.array(z.string().url()).optional(),
|
||||
|
||||
jwks_uri: z.string().url().optional(),
|
||||
|
||||
scopes_supported: z.array(z.string()).optional(),
|
||||
|
||||
bearer_methods_supported: z.array(z.string()).optional(),
|
||||
|
||||
resource_signing_alg_values_supported: z.array(z.string()).optional(),
|
||||
|
||||
resource_name: z.string().optional(),
|
||||
|
||||
resource_documentation: z.string().url().optional(),
|
||||
|
||||
resource_policy_uri: z.string().url().optional(),
|
||||
|
||||
resource_tos_uri: z.string().url().optional(),
|
||||
|
||||
tls_client_certificate_bound_access_tokens: z.boolean().optional(),
|
||||
|
||||
authorization_details_types_supported: z.array(z.string()).optional(),
|
||||
|
||||
dpop_signing_alg_values_supported: z.array(z.string()).optional(),
|
||||
|
||||
dpop_bound_access_tokens_required: z.boolean().optional(),
|
||||
|
||||
// Signed metadata JWT
|
||||
signed_metadata: z.string().optional()
|
||||
}).strict();
|
||||
|
||||
export type OAuthMetadata = z.infer<typeof OAuthMetadataSchema>;
|
||||
export type OAuthTokens = z.infer<typeof OAuthTokensSchema>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue