@@ -3,13 +3,11 @@ import { z } from 'zod';
33/**
44 * Reusable URL validation that disallows javascript: scheme
55 */
6- export const SafeUrlSchema = z
7- . string ( )
8- . url ( )
6+ export const SafeUrlSchema = z . url ( )
97 . superRefine ( ( val , ctx ) => {
108 if ( ! URL . canParse ( val ) ) {
119 ctx . addIssue ( {
12- code : z . ZodIssueCode . custom ,
10+ code : " custom" ,
1311 message : 'URL must be parseable' ,
1412 fatal : true
1513 } ) ;
@@ -22,36 +20,35 @@ export const SafeUrlSchema = z
2220 const u = new URL ( url ) ;
2321 return u . protocol !== 'javascript:' && u . protocol !== 'data:' && u . protocol !== 'vbscript:' ;
2422 } ,
25- { message : 'URL cannot use javascript:, data:, or vbscript: scheme' }
23+ {
24+ error : 'URL cannot use javascript:, data:, or vbscript: scheme'
25+ }
2626 ) ;
2727
2828/**
2929 * RFC 9728 OAuth Protected Resource Metadata
3030 */
31- export const OAuthProtectedResourceMetadataSchema = z
32- . object ( {
33- resource : z . string ( ) . url ( ) ,
31+ export const OAuthProtectedResourceMetadataSchema = z . looseObject ( {
32+ resource : z . url ( ) ,
3433 authorization_servers : z . array ( SafeUrlSchema ) . optional ( ) ,
35- jwks_uri : z . string ( ) . url ( ) . optional ( ) ,
34+ jwks_uri : z . url ( ) . optional ( ) ,
3635 scopes_supported : z . array ( z . string ( ) ) . optional ( ) ,
3736 bearer_methods_supported : z . array ( z . string ( ) ) . optional ( ) ,
3837 resource_signing_alg_values_supported : z . array ( z . string ( ) ) . optional ( ) ,
3938 resource_name : z . string ( ) . optional ( ) ,
4039 resource_documentation : z . string ( ) . optional ( ) ,
41- resource_policy_uri : z . string ( ) . url ( ) . optional ( ) ,
42- resource_tos_uri : z . string ( ) . url ( ) . optional ( ) ,
40+ resource_policy_uri : z . url ( ) . optional ( ) ,
41+ resource_tos_uri : z . url ( ) . optional ( ) ,
4342 tls_client_certificate_bound_access_tokens : z . boolean ( ) . optional ( ) ,
4443 authorization_details_types_supported : z . array ( z . string ( ) ) . optional ( ) ,
4544 dpop_signing_alg_values_supported : z . array ( z . string ( ) ) . optional ( ) ,
4645 dpop_bound_access_tokens_required : z . boolean ( ) . optional ( )
47- } )
48- . passthrough ( ) ;
46+ } ) ;
4947
5048/**
5149 * RFC 8414 OAuth 2.0 Authorization Server Metadata
5250 */
53- export const OAuthMetadataSchema = z
54- . object ( {
51+ export const OAuthMetadataSchema = z . looseObject ( {
5552 issuer : z . string ( ) ,
5653 authorization_endpoint : SafeUrlSchema ,
5754 token_endpoint : SafeUrlSchema ,
@@ -70,15 +67,13 @@ export const OAuthMetadataSchema = z
7067 introspection_endpoint_auth_methods_supported : z . array ( z . string ( ) ) . optional ( ) ,
7168 introspection_endpoint_auth_signing_alg_values_supported : z . array ( z . string ( ) ) . optional ( ) ,
7269 code_challenge_methods_supported : z . array ( z . string ( ) ) . optional ( )
73- } )
74- . passthrough ( ) ;
70+ } ) ;
7571
7672/**
7773 * OpenID Connect Discovery 1.0 Provider Metadata
7874 * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
7975 */
80- export const OpenIdProviderMetadataSchema = z
81- . object ( {
76+ export const OpenIdProviderMetadataSchema = z . looseObject ( {
8277 issuer : z . string ( ) ,
8378 authorization_endpoint : SafeUrlSchema ,
8479 token_endpoint : SafeUrlSchema ,
@@ -114,8 +109,7 @@ export const OpenIdProviderMetadataSchema = z
114109 require_request_uri_registration : z . boolean ( ) . optional ( ) ,
115110 op_policy_uri : SafeUrlSchema . optional ( ) ,
116111 op_tos_uri : SafeUrlSchema . optional ( )
117- } )
118- . passthrough ( ) ;
112+ } ) ;
119113
120114/**
121115 * OpenID Connect Discovery metadata that may include OAuth 2.0 fields
@@ -131,16 +125,14 @@ export const OpenIdProviderDiscoveryMetadataSchema = OpenIdProviderMetadataSchem
131125/**
132126 * OAuth 2.1 token response
133127 */
134- export const OAuthTokensSchema = z
135- . object ( {
128+ export const OAuthTokensSchema = z . object ( {
136129 access_token : z . string ( ) ,
137130 id_token : z . string ( ) . optional ( ) , // Optional for OAuth 2.1, but necessary in OpenID Connect
138131 token_type : z . string ( ) ,
139132 expires_in : z . number ( ) . optional ( ) ,
140133 scope : z . string ( ) . optional ( ) ,
141134 refresh_token : z . string ( ) . optional ( )
142- } )
143- . strip ( ) ;
135+ } ) ;
144136
145137/**
146138 * OAuth 2.1 error response
@@ -159,8 +151,7 @@ export const OptionalSafeUrlSchema = SafeUrlSchema.optional().or(z.literal('').t
159151/**
160152 * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
161153 */
162- export const OAuthClientMetadataSchema = z
163- . object ( {
154+ export const OAuthClientMetadataSchema = z . object ( {
164155 redirect_uris : z . array ( SafeUrlSchema ) ,
165156 token_endpoint_auth_method : z . string ( ) . optional ( ) ,
166157 grant_types : z . array ( z . string ( ) ) . optional ( ) ,
@@ -177,20 +168,17 @@ export const OAuthClientMetadataSchema = z
177168 software_id : z . string ( ) . optional ( ) ,
178169 software_version : z . string ( ) . optional ( ) ,
179170 software_statement : z . string ( ) . optional ( )
180- } )
181- . strip ( ) ;
171+ } ) ;
182172
183173/**
184174 * RFC 7591 OAuth 2.0 Dynamic Client Registration client information
185175 */
186- export const OAuthClientInformationSchema = z
187- . object ( {
176+ export const OAuthClientInformationSchema = z . object ( {
188177 client_id : z . string ( ) ,
189178 client_secret : z . string ( ) . optional ( ) ,
190179 client_id_issued_at : z . number ( ) . optional ( ) ,
191180 client_secret_expires_at : z . number ( ) . optional ( )
192- } )
193- . strip ( ) ;
181+ } ) ;
194182
195183/**
196184 * RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
@@ -200,22 +188,18 @@ export const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(
200188/**
201189 * RFC 7591 OAuth 2.0 Dynamic Client Registration error response
202190 */
203- export const OAuthClientRegistrationErrorSchema = z
204- . object ( {
191+ export const OAuthClientRegistrationErrorSchema = z . object ( {
205192 error : z . string ( ) ,
206193 error_description : z . string ( ) . optional ( )
207- } )
208- . strip ( ) ;
194+ } ) ;
209195
210196/**
211197 * RFC 7009 OAuth 2.0 Token Revocation request
212198 */
213- export const OAuthTokenRevocationRequestSchema = z
214- . object ( {
199+ export const OAuthTokenRevocationRequestSchema = z . object ( {
215200 token : z . string ( ) ,
216201 token_type_hint : z . string ( ) . optional ( )
217- } )
218- . strip ( ) ;
202+ } ) ;
219203
220204export type OAuthMetadata = z . infer < typeof OAuthMetadataSchema > ;
221205export type OpenIdProviderMetadata = z . infer < typeof OpenIdProviderMetadataSchema > ;
0 commit comments