@atcute/oauth-types 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +6 -5
  2. package/dist/build-client-metadata.d.ts +5 -320
  3. package/dist/build-client-metadata.d.ts.map +1 -1
  4. package/dist/build-client-metadata.js +3 -2
  5. package/dist/build-client-metadata.js.map +1 -1
  6. package/dist/index.d.ts +31 -31
  7. package/dist/schemas/atcute-client-shared.d.ts +8 -0
  8. package/dist/schemas/atcute-client-shared.d.ts.map +1 -0
  9. package/dist/schemas/atcute-client-shared.js +15 -0
  10. package/dist/schemas/atcute-client-shared.js.map +1 -0
  11. package/dist/schemas/atcute-confidential-client-metadata.d.ts +228 -4
  12. package/dist/schemas/atcute-confidential-client-metadata.d.ts.map +1 -1
  13. package/dist/schemas/atcute-confidential-client-metadata.js +48 -88
  14. package/dist/schemas/atcute-confidential-client-metadata.js.map +1 -1
  15. package/dist/schemas/atcute-public-client-metadata.d.ts +75 -35
  16. package/dist/schemas/atcute-public-client-metadata.d.ts.map +1 -1
  17. package/dist/schemas/atcute-public-client-metadata.js +25 -110
  18. package/dist/schemas/atcute-public-client-metadata.js.map +1 -1
  19. package/dist/schemas/atproto-authorization-server-metadata.d.ts +786 -4
  20. package/dist/schemas/atproto-authorization-server-metadata.d.ts.map +1 -1
  21. package/dist/schemas/atproto-authorization-server-metadata.js +2 -18
  22. package/dist/schemas/atproto-authorization-server-metadata.js.map +1 -1
  23. package/dist/schemas/atproto-oauth-scope.d.ts +3 -3
  24. package/dist/schemas/atproto-oauth-scope.d.ts.map +1 -1
  25. package/dist/schemas/atproto-oauth-scope.js +2 -2
  26. package/dist/schemas/atproto-oauth-scope.js.map +1 -1
  27. package/dist/schemas/atproto-oauth-token-response.d.ts +17 -17
  28. package/dist/schemas/atproto-oauth-token-response.d.ts.map +1 -1
  29. package/dist/schemas/atproto-oauth-token-response.js +6 -6
  30. package/dist/schemas/atproto-oauth-token-response.js.map +1 -1
  31. package/dist/schemas/atproto-protected-resource-metadata.d.ts +100 -4
  32. package/dist/schemas/atproto-protected-resource-metadata.d.ts.map +1 -1
  33. package/dist/schemas/atproto-protected-resource-metadata.js +2 -11
  34. package/dist/schemas/atproto-protected-resource-metadata.js.map +1 -1
  35. package/dist/schemas/jwk.d.ts +4289 -42
  36. package/dist/schemas/jwk.d.ts.map +1 -1
  37. package/dist/schemas/jwk.js +58 -91
  38. package/dist/schemas/jwk.js.map +1 -1
  39. package/dist/schemas/jwks.d.ts +87 -42
  40. package/dist/schemas/jwks.d.ts.map +1 -1
  41. package/dist/schemas/jwks.js +13 -29
  42. package/dist/schemas/jwks.js.map +1 -1
  43. package/dist/schemas/oauth-authorization-details.d.ts +18 -18
  44. package/dist/schemas/oauth-authorization-details.d.ts.map +1 -1
  45. package/dist/schemas/oauth-authorization-details.js +7 -7
  46. package/dist/schemas/oauth-authorization-details.js.map +1 -1
  47. package/dist/schemas/oauth-authorization-server-metadata.d.ts +462 -48
  48. package/dist/schemas/oauth-authorization-server-metadata.d.ts.map +1 -1
  49. package/dist/schemas/oauth-authorization-server-metadata.js +46 -65
  50. package/dist/schemas/oauth-authorization-server-metadata.js.map +1 -1
  51. package/dist/schemas/oauth-client-id-discoverable.d.ts +2 -2
  52. package/dist/schemas/oauth-client-id-discoverable.d.ts.map +1 -1
  53. package/dist/schemas/oauth-client-id-discoverable.js +20 -22
  54. package/dist/schemas/oauth-client-id-discoverable.js.map +1 -1
  55. package/dist/schemas/oauth-client-id.d.ts +3 -3
  56. package/dist/schemas/oauth-client-id.d.ts.map +1 -1
  57. package/dist/schemas/oauth-client-id.js +2 -2
  58. package/dist/schemas/oauth-client-id.js.map +1 -1
  59. package/dist/schemas/oauth-client-metadata.d.ts +73 -51
  60. package/dist/schemas/oauth-client-metadata.d.ts.map +1 -1
  61. package/dist/schemas/oauth-client-metadata.js +33 -40
  62. package/dist/schemas/oauth-client-metadata.js.map +1 -1
  63. package/dist/schemas/oauth-code-challenge-method.d.ts +3 -3
  64. package/dist/schemas/oauth-code-challenge-method.d.ts.map +1 -1
  65. package/dist/schemas/oauth-code-challenge-method.js +2 -2
  66. package/dist/schemas/oauth-code-challenge-method.js.map +1 -1
  67. package/dist/schemas/oauth-endpoint-auth-method.d.ts +3 -3
  68. package/dist/schemas/oauth-endpoint-auth-method.d.ts.map +1 -1
  69. package/dist/schemas/oauth-endpoint-auth-method.js +10 -2
  70. package/dist/schemas/oauth-endpoint-auth-method.js.map +1 -1
  71. package/dist/schemas/oauth-grant-type.d.ts +3 -3
  72. package/dist/schemas/oauth-grant-type.d.ts.map +1 -1
  73. package/dist/schemas/oauth-grant-type.js +10 -3
  74. package/dist/schemas/oauth-grant-type.js.map +1 -1
  75. package/dist/schemas/oauth-issuer-identifier.d.ts +3 -3
  76. package/dist/schemas/oauth-issuer-identifier.d.ts.map +1 -1
  77. package/dist/schemas/oauth-issuer-identifier.js +16 -9
  78. package/dist/schemas/oauth-issuer-identifier.js.map +1 -1
  79. package/dist/schemas/oauth-par-response.d.ts +5 -5
  80. package/dist/schemas/oauth-par-response.d.ts.map +1 -1
  81. package/dist/schemas/oauth-par-response.js +3 -3
  82. package/dist/schemas/oauth-par-response.js.map +1 -1
  83. package/dist/schemas/oauth-prompt.d.ts +3 -3
  84. package/dist/schemas/oauth-prompt.d.ts.map +1 -1
  85. package/dist/schemas/oauth-prompt.js +2 -2
  86. package/dist/schemas/oauth-prompt.js.map +1 -1
  87. package/dist/schemas/oauth-protected-resource-metadata.d.ts +88 -16
  88. package/dist/schemas/oauth-protected-resource-metadata.d.ts.map +1 -1
  89. package/dist/schemas/oauth-protected-resource-metadata.js +14 -26
  90. package/dist/schemas/oauth-protected-resource-metadata.js.map +1 -1
  91. package/dist/schemas/oauth-redirect-uri.d.ts +5 -5
  92. package/dist/schemas/oauth-redirect-uri.d.ts.map +1 -1
  93. package/dist/schemas/oauth-redirect-uri.js +3 -16
  94. package/dist/schemas/oauth-redirect-uri.js.map +1 -1
  95. package/dist/schemas/oauth-response-mode.d.ts +3 -3
  96. package/dist/schemas/oauth-response-mode.d.ts.map +1 -1
  97. package/dist/schemas/oauth-response-mode.js +2 -2
  98. package/dist/schemas/oauth-response-mode.js.map +1 -1
  99. package/dist/schemas/oauth-response-type.d.ts +3 -3
  100. package/dist/schemas/oauth-response-type.d.ts.map +1 -1
  101. package/dist/schemas/oauth-response-type.js +13 -7
  102. package/dist/schemas/oauth-response-type.js.map +1 -1
  103. package/dist/schemas/oauth-scope.d.ts +3 -3
  104. package/dist/schemas/oauth-scope.d.ts.map +1 -1
  105. package/dist/schemas/oauth-scope.js +2 -2
  106. package/dist/schemas/oauth-scope.js.map +1 -1
  107. package/dist/schemas/oauth-token-response.d.ts +17 -17
  108. package/dist/schemas/oauth-token-response.d.ts.map +1 -1
  109. package/dist/schemas/oauth-token-response.js +7 -7
  110. package/dist/schemas/oauth-token-response.js.map +1 -1
  111. package/dist/schemas/oauth-token-type.d.ts +3 -3
  112. package/dist/schemas/oauth-token-type.d.ts.map +1 -1
  113. package/dist/schemas/oauth-token-type.js +8 -7
  114. package/dist/schemas/oauth-token-type.js.map +1 -1
  115. package/dist/schemas/uri.d.ts +7 -7
  116. package/dist/schemas/uri.d.ts.map +1 -1
  117. package/dist/schemas/uri.js +44 -44
  118. package/dist/schemas/uri.js.map +1 -1
  119. package/dist/schemas/utils.d.ts.map +1 -1
  120. package/dist/schemas/utils.js.map +1 -1
  121. package/dist/scope.d.ts.map +1 -1
  122. package/dist/scope.js.map +1 -1
  123. package/lib/build-client-metadata.ts +9 -7
  124. package/lib/index.ts +31 -31
  125. package/lib/schemas/atcute-client-shared.ts +25 -0
  126. package/lib/schemas/atcute-confidential-client-metadata.ts +81 -111
  127. package/lib/schemas/atcute-public-client-metadata.ts +70 -166
  128. package/lib/schemas/atproto-authorization-server-metadata.ts +22 -23
  129. package/lib/schemas/atproto-oauth-scope.ts +8 -5
  130. package/lib/schemas/atproto-oauth-token-response.ts +10 -9
  131. package/lib/schemas/atproto-protected-resource-metadata.ts +15 -15
  132. package/lib/schemas/jwk.ts +104 -120
  133. package/lib/schemas/jwks.ts +28 -40
  134. package/lib/schemas/oauth-authorization-details.ts +10 -10
  135. package/lib/schemas/oauth-authorization-server-metadata.ts +72 -74
  136. package/lib/schemas/oauth-client-id-discoverable.ts +43 -48
  137. package/lib/schemas/oauth-client-id.ts +3 -3
  138. package/lib/schemas/oauth-client-metadata.ts +45 -49
  139. package/lib/schemas/oauth-code-challenge-method.ts +3 -3
  140. package/lib/schemas/oauth-endpoint-auth-method.ts +11 -11
  141. package/lib/schemas/oauth-grant-type.ts +11 -11
  142. package/lib/schemas/oauth-issuer-identifier.ts +35 -27
  143. package/lib/schemas/oauth-par-response.ts +4 -4
  144. package/lib/schemas/oauth-prompt.ts +3 -9
  145. package/lib/schemas/oauth-protected-resource-metadata.ts +26 -35
  146. package/lib/schemas/oauth-redirect-uri.ts +15 -23
  147. package/lib/schemas/oauth-response-mode.ts +3 -7
  148. package/lib/schemas/oauth-response-type.ts +12 -12
  149. package/lib/schemas/oauth-scope.ts +3 -3
  150. package/lib/schemas/oauth-token-response.ts +10 -10
  151. package/lib/schemas/oauth-token-type.ts +16 -12
  152. package/lib/schemas/uri.ts +89 -76
  153. package/package.json +9 -8
@@ -1,53 +1,48 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { oauthClientIdSchema } from './oauth-client-id.js';
4
- import { httpsUriSchema } from './uri.js';
5
- import { extractUrlPath, isHostnameIP } from './utils.js';
3
+ import { oauthClientIdSchema } from './oauth-client-id.ts';
4
+ import { httpsUriSchema } from './uri.ts';
5
+ import { extractUrlPath, isHostnameIP } from './utils.ts';
6
6
 
7
7
  /**
8
8
  * @see {@link https://www.ietf.org/archive/id/draft-ietf-oauth-client-id-metadata-document-00.html}
9
9
  */
10
- export const oauthClientIdDiscoverableSchema = v.string().chain((input, options) => {
11
- // first validate as base client ID
12
- const clientIdResult = oauthClientIdSchema.try(input, options);
13
- if (!clientIdResult.ok) {
14
- return clientIdResult;
15
- }
16
-
17
- // then validate as https URI
18
- const httpsResult = httpsUriSchema.try(input, options);
19
- if (!httpsResult.ok) {
20
- return httpsResult;
21
- }
22
-
23
- const url = new URL(input);
24
-
25
- if (url.username || url.password) {
26
- return v.err(`client ID must not contain credentials`);
27
- }
28
-
29
- if (url.hash) {
30
- return v.err(`client ID must not contain a fragment`);
31
- }
32
-
33
- if (url.pathname === '/') {
34
- return v.err(`client ID must contain a path component (e.g. "/client-metadata.json")`);
35
- }
36
-
37
- if (url.pathname.endsWith('/')) {
38
- return v.err(`client ID path must not end with a trailing slash`);
39
- }
40
-
41
- if (isHostnameIP(url.hostname)) {
42
- return v.err(`client ID hostname must not be an IP address`);
43
- }
44
-
45
- // URL constructor normalizes the URL, so we extract the path manually to
46
- // avoid normalization, then compare it to the normalized path to ensure
47
- // that the URL does not contain path traversal or other unexpected characters
48
- if (extractUrlPath(input) !== url.pathname) {
49
- return v.err(`client ID must be in canonical form ("${url.href}", got "${input}")`);
50
- }
51
-
52
- return v.ok(input);
53
- });
10
+ export const oauthClientIdDiscoverableSchema = v.pipe(
11
+ oauthClientIdSchema,
12
+ httpsUriSchema,
13
+ v.rawCheck(({ dataset, addIssue }) => {
14
+ if (!dataset.typed) {
15
+ return;
16
+ }
17
+ const input = dataset.value;
18
+ const url = new URL(input);
19
+
20
+ if (url.username || url.password) {
21
+ addIssue({ message: `client ID must not contain credentials` });
22
+ return;
23
+ }
24
+ if (url.hash) {
25
+ addIssue({ message: `client ID must not contain a fragment` });
26
+ return;
27
+ }
28
+ if (url.pathname === '/') {
29
+ addIssue({ message: `client ID must contain a path component (e.g. "/client-metadata.json")` });
30
+ return;
31
+ }
32
+ if (url.pathname.endsWith('/')) {
33
+ addIssue({ message: `client ID path must not end with a trailing slash` });
34
+ return;
35
+ }
36
+ if (isHostnameIP(url.hostname)) {
37
+ addIssue({ message: `client ID hostname must not be an IP address` });
38
+ return;
39
+ }
40
+
41
+ // URL constructor normalizes the URL, so we extract the path manually to avoid
42
+ // normalization, then compare it to the normalized path to ensure that the URL does not
43
+ // contain path traversal or other unexpected characters
44
+ if (extractUrlPath(input) !== url.pathname) {
45
+ addIssue({ message: `client ID must be in canonical form ("${url.href}", got "${input}")` });
46
+ }
47
+ }),
48
+ );
@@ -1,6 +1,6 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
3
  /** base OAuth client ID (any non-empty string) */
4
- export const oauthClientIdSchema = v.string().assert((input) => input.length > 0, `must not be empty`);
4
+ export const oauthClientIdSchema = v.pipe(v.string(), v.nonEmpty(`must not be empty`));
5
5
 
6
- export type OAuthClientId = v.Infer<typeof oauthClientIdSchema>;
6
+ export type OAuthClientId = v.InferOutput<typeof oauthClientIdSchema>;
@@ -1,17 +1,17 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { jwksPubSchema } from './jwks.js';
4
- import { oauthClientIdSchema } from './oauth-client-id.js';
5
- import { oauthEndpointAuthMethodSchema } from './oauth-endpoint-auth-method.js';
6
- import { oauthGrantTypeSchema } from './oauth-grant-type.js';
7
- import { oauthRedirectUriSchema } from './oauth-redirect-uri.js';
8
- import { oauthResponseTypeSchema } from './oauth-response-type.js';
9
- import { oauthScopeSchema } from './oauth-scope.js';
10
- import { webUriSchema } from './uri.js';
3
+ import { jwksPubSchema } from './jwks.ts';
4
+ import { oauthClientIdSchema } from './oauth-client-id.ts';
5
+ import { oauthEndpointAuthMethodSchema } from './oauth-endpoint-auth-method.ts';
6
+ import { oauthGrantTypeSchema } from './oauth-grant-type.ts';
7
+ import { oauthRedirectUriSchema } from './oauth-redirect-uri.ts';
8
+ import { oauthResponseTypeSchema } from './oauth-response-type.ts';
9
+ import { oauthScopeSchema } from './oauth-scope.ts';
10
+ import { webUriSchema } from './uri.ts';
11
11
 
12
- const oauthApplicationTypeSchema = v.union(v.literal('web'), v.literal('native'));
12
+ const oauthApplicationTypeSchema = v.picklist(['web', 'native']);
13
13
 
14
- const oauthSubjectTypeSchema = v.union(v.literal('public'), v.literal('pairwise'));
14
+ const oauthSubjectTypeSchema = v.picklist(['public', 'pairwise']);
15
15
 
16
16
  // simple email validation
17
17
  const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -22,44 +22,40 @@ const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
22
22
  * @see {@link https://openid.net/specs/openid-connect-registration-1_0.html}
23
23
  * @see {@link https://datatracker.ietf.org/doc/html/rfc7591}
24
24
  */
25
- export const oauthClientMetadataSchema = v.object({
25
+ export const oauthClientMetadataSchema = v.looseObject({
26
26
  // https://www.rfc-editor.org/rfc/rfc7591.html#section-2
27
- redirect_uris: v
28
- .array(oauthRedirectUriSchema)
29
- .assert((arr) => arr.length > 0, `must have at least one redirect URI`),
30
- response_types: v.array(oauthResponseTypeSchema).optional(),
27
+ redirect_uris: v.pipe(
28
+ v.array(oauthRedirectUriSchema),
29
+ v.minLength(1, `must have at least one redirect URI`),
30
+ ),
31
+ response_types: v.optional(v.array(oauthResponseTypeSchema)),
31
32
  // > If omitted, the default is that the client will use only the "code"
32
33
  // > response type.
33
- // .optional((): OAuthResponseType[] => ['code'])
34
- grant_types: v.array(oauthGrantTypeSchema).optional(),
34
+ grant_types: v.optional(v.array(oauthGrantTypeSchema)),
35
35
  // > If omitted, the default behavior is that the client will use only the
36
36
  // > "authorization_code" Grant Type.
37
- // .optional((): OAuthGrantType[] => ['authorization_code']),
38
- scope: oauthScopeSchema.optional(),
37
+ scope: v.optional(oauthScopeSchema),
39
38
  // https://www.rfc-editor.org/rfc/rfc7591.html#section-2
40
- token_endpoint_auth_method: oauthEndpointAuthMethodSchema.optional(),
39
+ token_endpoint_auth_method: v.optional(oauthEndpointAuthMethodSchema),
41
40
  // > If unspecified or omitted, the default is "client_secret_basic" [...].
42
- // .optional((): OAuthEndpointAuthMethod => 'client_secret_basic'),
43
- token_endpoint_auth_signing_alg: v.string().optional(),
44
- userinfo_signed_response_alg: v.string().optional(),
45
- userinfo_encrypted_response_alg: v.string().optional(),
46
- jwks_uri: webUriSchema.optional(),
47
- jwks: jwksPubSchema.optional(),
48
- application_type: oauthApplicationTypeSchema.optional(),
49
- // .optional((): OAuthApplicationType => 'web'),
50
- subject_type: oauthSubjectTypeSchema.optional(),
51
- // .optional((): OAuthSubjectType => 'public'),
52
- request_object_signing_alg: v.string().optional(),
53
- id_token_signed_response_alg: v.string().optional(),
54
- authorization_signed_response_alg: v.string().optional(),
55
- authorization_encrypted_response_enc: v.literal('A128CBC-HS256').optional(),
56
- authorization_encrypted_response_alg: v.string().optional(),
57
- client_id: oauthClientIdSchema.optional(),
58
- client_name: v.string().optional(),
59
- client_uri: webUriSchema.optional(),
60
- policy_uri: webUriSchema.optional(),
61
- tos_uri: webUriSchema.optional(),
62
- logo_uri: webUriSchema.optional(),
41
+ token_endpoint_auth_signing_alg: v.optional(v.string()),
42
+ userinfo_signed_response_alg: v.optional(v.string()),
43
+ userinfo_encrypted_response_alg: v.optional(v.string()),
44
+ jwks_uri: v.optional(webUriSchema),
45
+ jwks: v.optional(jwksPubSchema),
46
+ application_type: v.optional(oauthApplicationTypeSchema),
47
+ subject_type: v.optional(oauthSubjectTypeSchema),
48
+ request_object_signing_alg: v.optional(v.string()),
49
+ id_token_signed_response_alg: v.optional(v.string()),
50
+ authorization_signed_response_alg: v.optional(v.string()),
51
+ authorization_encrypted_response_enc: v.optional(v.literal('A128CBC-HS256')),
52
+ authorization_encrypted_response_alg: v.optional(v.string()),
53
+ client_id: v.optional(oauthClientIdSchema),
54
+ client_name: v.optional(v.string()),
55
+ client_uri: v.optional(webUriSchema),
56
+ policy_uri: v.optional(webUriSchema),
57
+ tos_uri: v.optional(webUriSchema),
58
+ logo_uri: v.optional(webUriSchema),
63
59
 
64
60
  /**
65
61
  * default Maximum Authentication Age. specifies that the End-User MUST be
@@ -68,16 +64,16 @@ export const oauthClientMetadataSchema = v.object({
68
64
  * this default value. if omitted, no default Maximum Authentication Age is
69
65
  * specified.
70
66
  */
71
- default_max_age: v.number().optional(),
72
- require_auth_time: v.boolean().optional(),
73
- contacts: v.array(v.string().assert((s) => EMAIL_RE.test(s), `must be a valid email`)).optional(),
74
- tls_client_certificate_bound_access_tokens: v.boolean().optional(),
67
+ default_max_age: v.optional(v.number()),
68
+ require_auth_time: v.optional(v.boolean()),
69
+ contacts: v.optional(v.array(v.pipe(v.string(), v.regex(EMAIL_RE, `must be a valid email`)))),
70
+ tls_client_certificate_bound_access_tokens: v.optional(v.boolean()),
75
71
 
76
72
  // https://datatracker.ietf.org/doc/html/rfc9449#section-5.2
77
- dpop_bound_access_tokens: v.boolean().optional(),
73
+ dpop_bound_access_tokens: v.optional(v.boolean()),
78
74
 
79
75
  // https://datatracker.ietf.org/doc/html/rfc9396#section-14.5
80
- authorization_details_types: v.array(v.string()).optional(),
76
+ authorization_details_types: v.optional(v.array(v.string())),
81
77
  });
82
78
 
83
- export type OAuthClientMetadata = v.Infer<typeof oauthClientMetadataSchema>;
79
+ export type OAuthClientMetadata = v.InferOutput<typeof oauthClientMetadataSchema>;
@@ -1,5 +1,5 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- export const oauthCodeChallengeMethodSchema = v.union(v.literal('S256'), v.literal('plain'));
3
+ export const oauthCodeChallengeMethodSchema = v.picklist(['S256', 'plain']);
4
4
 
5
- export type OAuthCodeChallengeMethod = v.Infer<typeof oauthCodeChallengeMethodSchema>;
5
+ export type OAuthCodeChallengeMethod = v.InferOutput<typeof oauthCodeChallengeMethodSchema>;
@@ -1,13 +1,13 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- export const oauthEndpointAuthMethodSchema = v.union(
4
- v.literal('client_secret_basic'),
5
- v.literal('client_secret_jwt'),
6
- v.literal('client_secret_post'),
7
- v.literal('none'),
8
- v.literal('private_key_jwt'),
9
- v.literal('self_signed_tls_client_auth'),
10
- v.literal('tls_client_auth'),
11
- );
3
+ export const oauthEndpointAuthMethodSchema = v.picklist([
4
+ 'client_secret_basic',
5
+ 'client_secret_jwt',
6
+ 'client_secret_post',
7
+ 'none',
8
+ 'private_key_jwt',
9
+ 'self_signed_tls_client_auth',
10
+ 'tls_client_auth',
11
+ ]);
12
12
 
13
- export type OAuthEndpointAuthMethod = v.Infer<typeof oauthEndpointAuthMethodSchema>;
13
+ export type OAuthEndpointAuthMethod = v.InferOutput<typeof oauthEndpointAuthMethodSchema>;
@@ -1,13 +1,13 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- export const oauthGrantTypeSchema = v.union(
4
- v.literal('authorization_code'),
5
- v.literal('implicit'),
6
- v.literal('refresh_token'),
7
- v.literal('password'), // not part of OAuth 2.1
8
- v.literal('client_credentials'),
9
- v.literal('urn:ietf:params:oauth:grant-type:jwt-bearer'),
10
- v.literal('urn:ietf:params:oauth:grant-type:saml2-bearer'),
11
- );
3
+ export const oauthGrantTypeSchema = v.picklist([
4
+ 'authorization_code',
5
+ 'implicit',
6
+ 'refresh_token',
7
+ 'password', // not part of OAuth 2.1
8
+ 'client_credentials',
9
+ 'urn:ietf:params:oauth:grant-type:jwt-bearer',
10
+ 'urn:ietf:params:oauth:grant-type:saml2-bearer',
11
+ ]);
12
12
 
13
- export type OAuthGrantType = v.Infer<typeof oauthGrantTypeSchema>;
13
+ export type OAuthGrantType = v.InferOutput<typeof oauthGrantTypeSchema>;
@@ -1,30 +1,38 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { webUriSchema } from './uri.js';
3
+ import { webUriSchema } from './uri.ts';
4
4
 
5
- export const oauthIssuerIdentifierSchema = webUriSchema.chain((input) => {
5
+ export const oauthIssuerIdentifierSchema = v.pipe(
6
+ webUriSchema,
6
7
  // validate the issuer (MIX-UP attacks)
7
-
8
- if (input.endsWith('/')) {
9
- return v.err(`issuer URL must not end with a slash`);
10
- }
11
-
12
- const url = new URL(input);
13
-
14
- if (url.username || url.password) {
15
- return v.err(`issuer URL must not contain a username or password`);
16
- }
17
-
18
- if (url.hash || url.search) {
19
- return v.err(`issuer URL must not contain a query or fragment`);
20
- }
21
-
22
- const canonicalValue = url.pathname === '/' ? url.origin : url.href;
23
- if (input !== canonicalValue) {
24
- return v.err(`issuer URL must be in the canonical form`);
25
- }
26
-
27
- return v.ok(input);
28
- });
29
-
30
- export type OAuthIssuerIdentifier = v.Infer<typeof oauthIssuerIdentifierSchema>;
8
+ v.rawCheck(({ dataset, addIssue }) => {
9
+ if (!dataset.typed) {
10
+ return;
11
+ }
12
+ const input = dataset.value;
13
+
14
+ if (input.endsWith('/')) {
15
+ addIssue({ message: `issuer URL must not end with a slash` });
16
+ return;
17
+ }
18
+
19
+ const url = new URL(input);
20
+
21
+ if (url.username || url.password) {
22
+ addIssue({ message: `issuer URL must not contain a username or password` });
23
+ return;
24
+ }
25
+
26
+ if (url.hash || url.search) {
27
+ addIssue({ message: `issuer URL must not contain a query or fragment` });
28
+ return;
29
+ }
30
+
31
+ const canonicalValue = url.pathname === '/' ? url.origin : url.href;
32
+ if (input !== canonicalValue) {
33
+ addIssue({ message: `issuer URL must be in the canonical form` });
34
+ }
35
+ }),
36
+ );
37
+
38
+ export type OAuthIssuerIdentifier = v.InferOutput<typeof oauthIssuerIdentifierSchema>;
@@ -1,10 +1,10 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
3
  const isPositiveInteger = (n: number): boolean => Number.isInteger(n) && n > 0;
4
4
 
5
- export const oauthParResponseSchema = v.object({
5
+ export const oauthParResponseSchema = v.looseObject({
6
6
  request_uri: v.string(),
7
- expires_in: v.number().assert(isPositiveInteger, `must be a positive integer`),
7
+ expires_in: v.pipe(v.number(), v.check(isPositiveInteger, `must be a positive integer`)),
8
8
  });
9
9
 
10
- export type OAuthParResponse = v.Infer<typeof oauthParResponseSchema>;
10
+ export type OAuthParResponse = v.InferOutput<typeof oauthParResponseSchema>;
@@ -1,4 +1,4 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
3
  /**
4
4
  * OAuth prompt mode values.
@@ -9,12 +9,6 @@ import * as v from '@badrap/valita';
9
9
  * - `select_account`: force account selection
10
10
  * - `create`: force user registration screen
11
11
  */
12
- export const oauthPromptSchema = v.union(
13
- v.literal('none'),
14
- v.literal('login'),
15
- v.literal('consent'),
16
- v.literal('select_account'),
17
- v.literal('create'),
18
- );
12
+ export const oauthPromptSchema = v.picklist(['none', 'login', 'consent', 'select_account', 'create']);
19
13
 
20
- export type OAuthPrompt = v.Infer<typeof oauthPromptSchema>;
14
+ export type OAuthPrompt = v.InferOutput<typeof oauthPromptSchema>;
@@ -1,16 +1,16 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { oauthIssuerIdentifierSchema } from './oauth-issuer-identifier.js';
4
- import { webUriSchema } from './uri.js';
3
+ import { oauthIssuerIdentifierSchema } from './oauth-issuer-identifier.ts';
4
+ import { webUriSchema } from './uri.ts';
5
5
 
6
- export const oauthBearerMethodSchema = v.union(v.literal('header'), v.literal('body'), v.literal('query'));
6
+ export const oauthBearerMethodSchema = v.picklist(['header', 'body', 'query']);
7
7
 
8
- export type OAuthBearerMethod = v.Infer<typeof oauthBearerMethodSchema>;
8
+ export type OAuthBearerMethod = v.InferOutput<typeof oauthBearerMethodSchema>;
9
9
 
10
10
  /**
11
11
  * @see {@link https://www.rfc-editor.org/rfc/rfc9728.html#section-3.2}
12
12
  */
13
- export const oauthProtectedResourceMetadataSchema = v.object({
13
+ export const oauthProtectedResourceMetadataSchema = v.looseObject({
14
14
  /**
15
15
  * REQUIRED. the protected resource's resource identifier, which is a URL that
16
16
  * uses the https scheme and has no query or fragment components.
@@ -22,68 +22,59 @@ export const oauthProtectedResourceMetadataSchema = v.object({
22
22
  * identifiers, as defined in RFC8414, for authorization servers that can be
23
23
  * used with this protected resource.
24
24
  */
25
- authorization_servers: v.array(oauthIssuerIdentifierSchema).optional(),
25
+ authorization_servers: v.optional(v.array(oauthIssuerIdentifierSchema)),
26
26
 
27
27
  /**
28
28
  * OPTIONAL. URL of the protected resource's JWK Set document.
29
29
  */
30
- jwks_uri: webUriSchema.optional(),
30
+ jwks_uri: v.optional(webUriSchema),
31
31
 
32
32
  /**
33
33
  * RECOMMENDED. JSON array containing a list of the OAuth 2.0 scope values that
34
34
  * are used in authorization requests to request access to this protected resource.
35
35
  */
36
- scopes_supported: v.array(v.string()).optional(),
36
+ scopes_supported: v.optional(v.array(v.string())),
37
37
 
38
38
  /**
39
39
  * OPTIONAL. JSON array containing a list of the supported methods of sending
40
40
  * an OAuth 2.0 Bearer Token to the protected resource.
41
41
  */
42
- bearer_methods_supported: v.array(oauthBearerMethodSchema).optional(),
42
+ bearer_methods_supported: v.optional(v.array(oauthBearerMethodSchema)),
43
43
 
44
44
  /**
45
45
  * OPTIONAL. JSON array containing a list of the JWS signing algorithms
46
46
  * supported by the protected resource for signing resource responses.
47
47
  */
48
- resource_signing_alg_values_supported: v.array(v.string()).optional(),
48
+ resource_signing_alg_values_supported: v.optional(v.array(v.string())),
49
49
 
50
50
  /**
51
51
  * OPTIONAL. URL of a page containing human-readable information that
52
52
  * developers might want or need to know when using the protected resource.
53
53
  */
54
- resource_documentation: webUriSchema.optional(),
54
+ resource_documentation: v.optional(webUriSchema),
55
55
 
56
56
  /**
57
57
  * OPTIONAL. URL that the protected resource provides to read about the
58
58
  * protected resource's requirements on how the client can use the data.
59
59
  */
60
- resource_policy_uri: webUriSchema.optional(),
60
+ resource_policy_uri: v.optional(webUriSchema),
61
61
 
62
62
  /**
63
63
  * OPTIONAL. URL that the protected resource provides to read about the
64
64
  * protected resource's terms of service.
65
65
  */
66
- resource_tos_uri: webUriSchema.optional(),
66
+ resource_tos_uri: v.optional(webUriSchema),
67
67
  });
68
68
 
69
- export const oauthProtectedResourceMetadataValidator = oauthProtectedResourceMetadataSchema.chain((data) => {
70
- const url = new URL(data.resource);
71
-
72
- if (url.search) {
73
- return v.err({
74
- message: `resource URL must not contain query parameters`,
75
- path: ['resource'],
76
- });
77
- }
78
-
79
- if (url.hash) {
80
- return v.err({
81
- message: `resource URL must not contain a fragment`,
82
- path: ['resource'],
83
- });
84
- }
85
-
86
- return v.ok(data);
87
- });
88
-
89
- export type OAuthProtectedResourceMetadata = v.Infer<typeof oauthProtectedResourceMetadataSchema>;
69
+ export const oauthProtectedResourceMetadataValidator = v.pipe(
70
+ oauthProtectedResourceMetadataSchema,
71
+ v.forward(
72
+ v.check((data) => {
73
+ const url = new URL(data.resource);
74
+ return !url.search && !url.hash;
75
+ }, `resource URL must not contain query parameters or a fragment`),
76
+ ['resource'],
77
+ ),
78
+ );
79
+
80
+ export type OAuthProtectedResourceMetadata = v.InferOutput<typeof oauthProtectedResourceMetadataSchema>;
@@ -1,6 +1,6 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- import { httpsUriSchema, loopbackUriSchema, privateUseUriSchema } from './uri.js';
3
+ import { httpsUriSchema, loopbackUriSchema, privateUseUriSchema } from './uri.ts';
4
4
 
5
5
  /**
6
6
  * this is a loopback URI with the additional restriction that the hostname
@@ -16,27 +16,19 @@ import { httpsUriSchema, loopbackUriSchema, privateUseUriSchema } from './uri.js
16
16
  * > than the loopback interface. It is also less susceptible to client-side
17
17
  * > firewalls and misconfigured host name resolution on the user's device.
18
18
  */
19
- export const loopbackRedirectUriSchema = loopbackUriSchema.chain((input) => {
20
- if (input.startsWith('http://localhost')) {
21
- return v.err(
22
- `use of "localhost" hostname is not allowed (RFC 8252), use a loopback IP such as "127.0.0.1" instead`,
23
- );
24
- }
25
- return v.ok(input);
26
- });
19
+ export const loopbackRedirectUriSchema = v.pipe(
20
+ loopbackUriSchema,
21
+ v.check(
22
+ (input) => !input.startsWith('http://localhost'),
23
+ `use of "localhost" hostname is not allowed (RFC 8252), use a loopback IP such as "127.0.0.1" instead`,
24
+ ),
25
+ );
27
26
 
28
- export type LoopbackRedirectUri = v.Infer<typeof loopbackRedirectUriSchema>;
27
+ export type LoopbackRedirectUri = v.InferOutput<typeof loopbackRedirectUriSchema>;
29
28
 
30
- export const oauthRedirectUriSchema = v.string().chain((input, options) => {
31
- if (input.startsWith('http://')) {
32
- return loopbackRedirectUriSchema.try(input, options);
33
- }
29
+ export const oauthRedirectUriSchema = v.union(
30
+ [loopbackRedirectUriSchema, httpsUriSchema, privateUseUriSchema],
31
+ `url must use http: loopback, https:, or a private-use scheme`,
32
+ );
34
33
 
35
- if (input.startsWith('https://')) {
36
- return httpsUriSchema.try(input, options);
37
- }
38
-
39
- return privateUseUriSchema.try(input, options);
40
- });
41
-
42
- export type OAuthRedirectUri = v.Infer<typeof oauthRedirectUriSchema>;
34
+ export type OAuthRedirectUri = v.InferOutput<typeof oauthRedirectUriSchema>;
@@ -1,9 +1,5 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- export const oauthResponseModeSchema = v.union(
4
- v.literal('query'),
5
- v.literal('fragment'),
6
- v.literal('form_post'),
7
- );
3
+ export const oauthResponseModeSchema = v.picklist(['query', 'fragment', 'form_post']);
8
4
 
9
- export type OAuthResponseMode = v.Infer<typeof oauthResponseModeSchema>;
5
+ export type OAuthResponseMode = v.InferOutput<typeof oauthResponseModeSchema>;
@@ -1,17 +1,17 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
- export const oauthResponseTypeSchema = v.union(
3
+ export const oauthResponseTypeSchema = v.picklist([
4
4
  // OAuth2 (https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-10#section-4.1.1)
5
- v.literal('code'), // Authorization Code Grant
6
- v.literal('token'), // Implicit Grant
5
+ 'code', // Authorization Code Grant
6
+ 'token', // Implicit Grant
7
7
 
8
8
  // OIDC (https://openid.net/specs/oauth-v2-multiple-response-types-1_0.html)
9
- v.literal('none'),
10
- v.literal('code id_token token'),
11
- v.literal('code id_token'),
12
- v.literal('code token'),
13
- v.literal('id_token token'),
14
- v.literal('id_token'),
15
- );
9
+ 'none',
10
+ 'code id_token token',
11
+ 'code id_token',
12
+ 'code token',
13
+ 'id_token token',
14
+ 'id_token',
15
+ ]);
16
16
 
17
- export type OAuthResponseType = v.Infer<typeof oauthResponseTypeSchema>;
17
+ export type OAuthResponseType = v.InferOutput<typeof oauthResponseTypeSchema>;
@@ -1,4 +1,4 @@
1
- import * as v from '@badrap/valita';
1
+ import * as v from 'valibot';
2
2
 
3
3
  // scope = scope-token *( SP scope-token )
4
4
  // scope-token = 1*( %x21 / %x23-5B / %x5D-7E )
@@ -13,6 +13,6 @@ export const isOAuthScope = (input: string): boolean => OAUTH_SCOPE_REGEXP.test(
13
13
  *
14
14
  * @see {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-11#section-1.4.1}
15
15
  */
16
- export const oauthScopeSchema = v.string().assert(isOAuthScope, `invalid OAuth scope`);
16
+ export const oauthScopeSchema = v.pipe(v.string(), v.check(isOAuthScope, `invalid OAuth scope`));
17
17
 
18
- export type OAuthScope = v.Infer<typeof oauthScopeSchema>;
18
+ export type OAuthScope = v.InferOutput<typeof oauthScopeSchema>;