@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.
- package/README.md +6 -5
- package/dist/build-client-metadata.d.ts +5 -320
- package/dist/build-client-metadata.d.ts.map +1 -1
- package/dist/build-client-metadata.js +3 -2
- package/dist/build-client-metadata.js.map +1 -1
- package/dist/index.d.ts +31 -31
- package/dist/schemas/atcute-client-shared.d.ts +8 -0
- package/dist/schemas/atcute-client-shared.d.ts.map +1 -0
- package/dist/schemas/atcute-client-shared.js +15 -0
- package/dist/schemas/atcute-client-shared.js.map +1 -0
- package/dist/schemas/atcute-confidential-client-metadata.d.ts +228 -4
- package/dist/schemas/atcute-confidential-client-metadata.d.ts.map +1 -1
- package/dist/schemas/atcute-confidential-client-metadata.js +48 -88
- package/dist/schemas/atcute-confidential-client-metadata.js.map +1 -1
- package/dist/schemas/atcute-public-client-metadata.d.ts +75 -35
- package/dist/schemas/atcute-public-client-metadata.d.ts.map +1 -1
- package/dist/schemas/atcute-public-client-metadata.js +25 -110
- package/dist/schemas/atcute-public-client-metadata.js.map +1 -1
- package/dist/schemas/atproto-authorization-server-metadata.d.ts +786 -4
- package/dist/schemas/atproto-authorization-server-metadata.d.ts.map +1 -1
- package/dist/schemas/atproto-authorization-server-metadata.js +2 -18
- package/dist/schemas/atproto-authorization-server-metadata.js.map +1 -1
- package/dist/schemas/atproto-oauth-scope.d.ts +3 -3
- package/dist/schemas/atproto-oauth-scope.d.ts.map +1 -1
- package/dist/schemas/atproto-oauth-scope.js +2 -2
- package/dist/schemas/atproto-oauth-scope.js.map +1 -1
- package/dist/schemas/atproto-oauth-token-response.d.ts +17 -17
- package/dist/schemas/atproto-oauth-token-response.d.ts.map +1 -1
- package/dist/schemas/atproto-oauth-token-response.js +6 -6
- package/dist/schemas/atproto-oauth-token-response.js.map +1 -1
- package/dist/schemas/atproto-protected-resource-metadata.d.ts +100 -4
- package/dist/schemas/atproto-protected-resource-metadata.d.ts.map +1 -1
- package/dist/schemas/atproto-protected-resource-metadata.js +2 -11
- package/dist/schemas/atproto-protected-resource-metadata.js.map +1 -1
- package/dist/schemas/jwk.d.ts +4289 -42
- package/dist/schemas/jwk.d.ts.map +1 -1
- package/dist/schemas/jwk.js +58 -91
- package/dist/schemas/jwk.js.map +1 -1
- package/dist/schemas/jwks.d.ts +87 -42
- package/dist/schemas/jwks.d.ts.map +1 -1
- package/dist/schemas/jwks.js +13 -29
- package/dist/schemas/jwks.js.map +1 -1
- package/dist/schemas/oauth-authorization-details.d.ts +18 -18
- package/dist/schemas/oauth-authorization-details.d.ts.map +1 -1
- package/dist/schemas/oauth-authorization-details.js +7 -7
- package/dist/schemas/oauth-authorization-details.js.map +1 -1
- package/dist/schemas/oauth-authorization-server-metadata.d.ts +462 -48
- package/dist/schemas/oauth-authorization-server-metadata.d.ts.map +1 -1
- package/dist/schemas/oauth-authorization-server-metadata.js +46 -65
- package/dist/schemas/oauth-authorization-server-metadata.js.map +1 -1
- package/dist/schemas/oauth-client-id-discoverable.d.ts +2 -2
- package/dist/schemas/oauth-client-id-discoverable.d.ts.map +1 -1
- package/dist/schemas/oauth-client-id-discoverable.js +20 -22
- package/dist/schemas/oauth-client-id-discoverable.js.map +1 -1
- package/dist/schemas/oauth-client-id.d.ts +3 -3
- package/dist/schemas/oauth-client-id.d.ts.map +1 -1
- package/dist/schemas/oauth-client-id.js +2 -2
- package/dist/schemas/oauth-client-id.js.map +1 -1
- package/dist/schemas/oauth-client-metadata.d.ts +73 -51
- package/dist/schemas/oauth-client-metadata.d.ts.map +1 -1
- package/dist/schemas/oauth-client-metadata.js +33 -40
- package/dist/schemas/oauth-client-metadata.js.map +1 -1
- package/dist/schemas/oauth-code-challenge-method.d.ts +3 -3
- package/dist/schemas/oauth-code-challenge-method.d.ts.map +1 -1
- package/dist/schemas/oauth-code-challenge-method.js +2 -2
- package/dist/schemas/oauth-code-challenge-method.js.map +1 -1
- package/dist/schemas/oauth-endpoint-auth-method.d.ts +3 -3
- package/dist/schemas/oauth-endpoint-auth-method.d.ts.map +1 -1
- package/dist/schemas/oauth-endpoint-auth-method.js +10 -2
- package/dist/schemas/oauth-endpoint-auth-method.js.map +1 -1
- package/dist/schemas/oauth-grant-type.d.ts +3 -3
- package/dist/schemas/oauth-grant-type.d.ts.map +1 -1
- package/dist/schemas/oauth-grant-type.js +10 -3
- package/dist/schemas/oauth-grant-type.js.map +1 -1
- package/dist/schemas/oauth-issuer-identifier.d.ts +3 -3
- package/dist/schemas/oauth-issuer-identifier.d.ts.map +1 -1
- package/dist/schemas/oauth-issuer-identifier.js +16 -9
- package/dist/schemas/oauth-issuer-identifier.js.map +1 -1
- package/dist/schemas/oauth-par-response.d.ts +5 -5
- package/dist/schemas/oauth-par-response.d.ts.map +1 -1
- package/dist/schemas/oauth-par-response.js +3 -3
- package/dist/schemas/oauth-par-response.js.map +1 -1
- package/dist/schemas/oauth-prompt.d.ts +3 -3
- package/dist/schemas/oauth-prompt.d.ts.map +1 -1
- package/dist/schemas/oauth-prompt.js +2 -2
- package/dist/schemas/oauth-prompt.js.map +1 -1
- package/dist/schemas/oauth-protected-resource-metadata.d.ts +88 -16
- package/dist/schemas/oauth-protected-resource-metadata.d.ts.map +1 -1
- package/dist/schemas/oauth-protected-resource-metadata.js +14 -26
- package/dist/schemas/oauth-protected-resource-metadata.js.map +1 -1
- package/dist/schemas/oauth-redirect-uri.d.ts +5 -5
- package/dist/schemas/oauth-redirect-uri.d.ts.map +1 -1
- package/dist/schemas/oauth-redirect-uri.js +3 -16
- package/dist/schemas/oauth-redirect-uri.js.map +1 -1
- package/dist/schemas/oauth-response-mode.d.ts +3 -3
- package/dist/schemas/oauth-response-mode.d.ts.map +1 -1
- package/dist/schemas/oauth-response-mode.js +2 -2
- package/dist/schemas/oauth-response-mode.js.map +1 -1
- package/dist/schemas/oauth-response-type.d.ts +3 -3
- package/dist/schemas/oauth-response-type.d.ts.map +1 -1
- package/dist/schemas/oauth-response-type.js +13 -7
- package/dist/schemas/oauth-response-type.js.map +1 -1
- package/dist/schemas/oauth-scope.d.ts +3 -3
- package/dist/schemas/oauth-scope.d.ts.map +1 -1
- package/dist/schemas/oauth-scope.js +2 -2
- package/dist/schemas/oauth-scope.js.map +1 -1
- package/dist/schemas/oauth-token-response.d.ts +17 -17
- package/dist/schemas/oauth-token-response.d.ts.map +1 -1
- package/dist/schemas/oauth-token-response.js +7 -7
- package/dist/schemas/oauth-token-response.js.map +1 -1
- package/dist/schemas/oauth-token-type.d.ts +3 -3
- package/dist/schemas/oauth-token-type.d.ts.map +1 -1
- package/dist/schemas/oauth-token-type.js +8 -7
- package/dist/schemas/oauth-token-type.js.map +1 -1
- package/dist/schemas/uri.d.ts +7 -7
- package/dist/schemas/uri.d.ts.map +1 -1
- package/dist/schemas/uri.js +44 -44
- package/dist/schemas/uri.js.map +1 -1
- package/dist/schemas/utils.d.ts.map +1 -1
- package/dist/schemas/utils.js.map +1 -1
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js.map +1 -1
- package/lib/build-client-metadata.ts +9 -7
- package/lib/index.ts +31 -31
- package/lib/schemas/atcute-client-shared.ts +25 -0
- package/lib/schemas/atcute-confidential-client-metadata.ts +81 -111
- package/lib/schemas/atcute-public-client-metadata.ts +70 -166
- package/lib/schemas/atproto-authorization-server-metadata.ts +22 -23
- package/lib/schemas/atproto-oauth-scope.ts +8 -5
- package/lib/schemas/atproto-oauth-token-response.ts +10 -9
- package/lib/schemas/atproto-protected-resource-metadata.ts +15 -15
- package/lib/schemas/jwk.ts +104 -120
- package/lib/schemas/jwks.ts +28 -40
- package/lib/schemas/oauth-authorization-details.ts +10 -10
- package/lib/schemas/oauth-authorization-server-metadata.ts +72 -74
- package/lib/schemas/oauth-client-id-discoverable.ts +43 -48
- package/lib/schemas/oauth-client-id.ts +3 -3
- package/lib/schemas/oauth-client-metadata.ts +45 -49
- package/lib/schemas/oauth-code-challenge-method.ts +3 -3
- package/lib/schemas/oauth-endpoint-auth-method.ts +11 -11
- package/lib/schemas/oauth-grant-type.ts +11 -11
- package/lib/schemas/oauth-issuer-identifier.ts +35 -27
- package/lib/schemas/oauth-par-response.ts +4 -4
- package/lib/schemas/oauth-prompt.ts +3 -9
- package/lib/schemas/oauth-protected-resource-metadata.ts +26 -35
- package/lib/schemas/oauth-redirect-uri.ts +15 -23
- package/lib/schemas/oauth-response-mode.ts +3 -7
- package/lib/schemas/oauth-response-type.ts +12 -12
- package/lib/schemas/oauth-scope.ts +3 -3
- package/lib/schemas/oauth-token-response.ts +10 -10
- package/lib/schemas/oauth-token-type.ts +16 -12
- package/lib/schemas/uri.ts +89 -76
- package/package.json +9 -8
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import { oauthClientIdSchema } from './oauth-client-id.
|
|
4
|
-
import { httpsUriSchema } from './uri.
|
|
5
|
-
import { extractUrlPath, isHostnameIP } from './utils.
|
|
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.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
3
|
/** base OAuth client ID (any non-empty string) */
|
|
4
|
-
export const oauthClientIdSchema = v.
|
|
4
|
+
export const oauthClientIdSchema = v.pipe(v.string(), v.nonEmpty(`must not be empty`));
|
|
5
5
|
|
|
6
|
-
export type OAuthClientId = v.
|
|
6
|
+
export type OAuthClientId = v.InferOutput<typeof oauthClientIdSchema>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import { jwksPubSchema } from './jwks.
|
|
4
|
-
import { oauthClientIdSchema } from './oauth-client-id.
|
|
5
|
-
import { oauthEndpointAuthMethodSchema } from './oauth-endpoint-auth-method.
|
|
6
|
-
import { oauthGrantTypeSchema } from './oauth-grant-type.
|
|
7
|
-
import { oauthRedirectUriSchema } from './oauth-redirect-uri.
|
|
8
|
-
import { oauthResponseTypeSchema } from './oauth-response-type.
|
|
9
|
-
import { oauthScopeSchema } from './oauth-scope.
|
|
10
|
-
import { webUriSchema } from './uri.
|
|
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.
|
|
12
|
+
const oauthApplicationTypeSchema = v.picklist(['web', 'native']);
|
|
13
13
|
|
|
14
|
-
const oauthSubjectTypeSchema = v.
|
|
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.
|
|
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
|
-
.
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
39
|
+
token_endpoint_auth_method: v.optional(oauthEndpointAuthMethodSchema),
|
|
41
40
|
// > If unspecified or omitted, the default is "client_secret_basic" [...].
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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.
|
|
72
|
-
require_auth_time: v.
|
|
73
|
-
contacts: v.array(v.
|
|
74
|
-
tls_client_certificate_bound_access_tokens: v.
|
|
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.
|
|
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())
|
|
76
|
+
authorization_details_types: v.optional(v.array(v.string())),
|
|
81
77
|
});
|
|
82
78
|
|
|
83
|
-
export type OAuthClientMetadata = v.
|
|
79
|
+
export type OAuthClientMetadata = v.InferOutput<typeof oauthClientMetadataSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
export const oauthCodeChallengeMethodSchema = v.
|
|
3
|
+
export const oauthCodeChallengeMethodSchema = v.picklist(['S256', 'plain']);
|
|
4
4
|
|
|
5
|
-
export type OAuthCodeChallengeMethod = v.
|
|
5
|
+
export type OAuthCodeChallengeMethod = v.InferOutput<typeof oauthCodeChallengeMethodSchema>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
export const oauthEndpointAuthMethodSchema = v.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
13
|
+
export type OAuthEndpointAuthMethod = v.InferOutput<typeof oauthEndpointAuthMethodSchema>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
export const oauthGrantTypeSchema = v.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
13
|
+
export type OAuthGrantType = v.InferOutput<typeof oauthGrantTypeSchema>;
|
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import { webUriSchema } from './uri.
|
|
3
|
+
import { webUriSchema } from './uri.ts';
|
|
4
4
|
|
|
5
|
-
export const oauthIssuerIdentifierSchema =
|
|
5
|
+
export const oauthIssuerIdentifierSchema = v.pipe(
|
|
6
|
+
webUriSchema,
|
|
6
7
|
// validate the issuer (MIX-UP attacks)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
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 '
|
|
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.
|
|
5
|
+
export const oauthParResponseSchema = v.looseObject({
|
|
6
6
|
request_uri: v.string(),
|
|
7
|
-
expires_in: v.number().
|
|
7
|
+
expires_in: v.pipe(v.number(), v.check(isPositiveInteger, `must be a positive integer`)),
|
|
8
8
|
});
|
|
9
9
|
|
|
10
|
-
export type OAuthParResponse = v.
|
|
10
|
+
export type OAuthParResponse = v.InferOutput<typeof oauthParResponseSchema>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as v from '
|
|
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.
|
|
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.
|
|
14
|
+
export type OAuthPrompt = v.InferOutput<typeof oauthPromptSchema>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import { oauthIssuerIdentifierSchema } from './oauth-issuer-identifier.
|
|
4
|
-
import { webUriSchema } from './uri.
|
|
3
|
+
import { oauthIssuerIdentifierSchema } from './oauth-issuer-identifier.ts';
|
|
4
|
+
import { webUriSchema } from './uri.ts';
|
|
5
5
|
|
|
6
|
-
export const oauthBearerMethodSchema = v.
|
|
6
|
+
export const oauthBearerMethodSchema = v.picklist(['header', 'body', 'query']);
|
|
7
7
|
|
|
8
|
-
export type OAuthBearerMethod = v.
|
|
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.
|
|
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)
|
|
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:
|
|
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())
|
|
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)
|
|
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())
|
|
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:
|
|
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:
|
|
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:
|
|
66
|
+
resource_tos_uri: v.optional(webUriSchema),
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
export const oauthProtectedResourceMetadataValidator =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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 '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
import { httpsUriSchema, loopbackUriSchema, privateUseUriSchema } from './uri.
|
|
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 =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
|
|
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.
|
|
27
|
+
export type LoopbackRedirectUri = v.InferOutput<typeof loopbackRedirectUriSchema>;
|
|
29
28
|
|
|
30
|
-
export const oauthRedirectUriSchema = v.
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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 '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
export const oauthResponseModeSchema = v.
|
|
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.
|
|
5
|
+
export type OAuthResponseMode = v.InferOutput<typeof oauthResponseModeSchema>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import * as v from '
|
|
1
|
+
import * as v from 'valibot';
|
|
2
2
|
|
|
3
|
-
export const oauthResponseTypeSchema = v.
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.
|
|
17
|
+
export type OAuthResponseType = v.InferOutput<typeof oauthResponseTypeSchema>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as v from '
|
|
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().
|
|
16
|
+
export const oauthScopeSchema = v.pipe(v.string(), v.check(isOAuthScope, `invalid OAuth scope`));
|
|
17
17
|
|
|
18
|
-
export type OAuthScope = v.
|
|
18
|
+
export type OAuthScope = v.InferOutput<typeof oauthScopeSchema>;
|