@atproto/oauth-types 0.7.3 → 0.7.5
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/CHANGELOG.md +24 -0
- package/dist/atproto-loopback-client-id.d.ts +3 -3
- package/dist/atproto-loopback-client-id.d.ts.map +1 -1
- package/dist/atproto-loopback-client-id.js.map +1 -1
- package/dist/atproto-loopback-client-metadata.d.ts +5 -5
- package/dist/atproto-loopback-client-metadata.d.ts.map +1 -1
- package/dist/atproto-loopback-client-metadata.js.map +1 -1
- package/dist/atproto-oauth-scope.d.ts +2 -2
- package/dist/atproto-oauth-scope.d.ts.map +1 -1
- package/dist/atproto-oauth-scope.js.map +1 -1
- package/dist/atproto-oauth-token-response.d.ts +1 -1
- package/dist/atproto-oauth-token-response.d.ts.map +1 -1
- package/dist/atproto-oauth-token-response.js.map +1 -1
- package/dist/oauth-client-id-discoverable.d.ts +1 -1
- package/dist/oauth-client-id-discoverable.d.ts.map +1 -1
- package/dist/oauth-client-id-discoverable.js.map +1 -1
- package/dist/oauth-client-id-loopback.d.ts +2 -2
- package/dist/oauth-client-id-loopback.d.ts.map +1 -1
- package/dist/oauth-client-id-loopback.js.map +1 -1
- package/dist/oauth-introspection-response.d.ts +2 -2
- package/dist/oauth-introspection-response.d.ts.map +1 -1
- package/dist/oauth-introspection-response.js.map +1 -1
- package/dist/oauth-redirect-uri.d.ts +1 -1
- package/dist/oauth-redirect-uri.d.ts.map +1 -1
- package/dist/oauth-redirect-uri.js.map +1 -1
- package/dist/uri.d.ts +1 -1
- package/dist/uri.d.ts.map +1 -1
- package/dist/uri.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js.map +1 -1
- package/package.json +11 -7
- package/src/atproto-loopback-client-id.ts +0 -78
- package/src/atproto-loopback-client-metadata.ts +0 -47
- package/src/atproto-loopback-client-redirect-uris.ts +0 -4
- package/src/atproto-oauth-scope.ts +0 -34
- package/src/atproto-oauth-token-response.ts +0 -16
- package/src/constants.ts +0 -2
- package/src/index.ts +0 -50
- package/src/oauth-access-token.ts +0 -4
- package/src/oauth-authorization-code-grant-token-request.ts +0 -19
- package/src/oauth-authorization-details.ts +0 -48
- package/src/oauth-authorization-request-jar.ts +0 -16
- package/src/oauth-authorization-request-par.ts +0 -12
- package/src/oauth-authorization-request-parameters.ts +0 -100
- package/src/oauth-authorization-request-query.ts +0 -21
- package/src/oauth-authorization-request-uri.ts +0 -10
- package/src/oauth-authorization-response-error.ts +0 -25
- package/src/oauth-authorization-server-metadata.ts +0 -120
- package/src/oauth-client-credentials-grant-token-request.ts +0 -9
- package/src/oauth-client-credentials.ts +0 -53
- package/src/oauth-client-id-discoverable.ts +0 -130
- package/src/oauth-client-id-loopback.ts +0 -164
- package/src/oauth-client-id.ts +0 -4
- package/src/oauth-client-metadata.ts +0 -80
- package/src/oauth-code-challenge-method.ts +0 -3
- package/src/oauth-endpoint-auth-method.ts +0 -13
- package/src/oauth-endpoint-name.ts +0 -8
- package/src/oauth-grant-type.ts +0 -13
- package/src/oauth-introspection-response.ts +0 -23
- package/src/oauth-issuer-identifier.ts +0 -47
- package/src/oauth-par-response.ts +0 -8
- package/src/oauth-password-grant-token-request.ts +0 -11
- package/src/oauth-prompt-mode.ts +0 -18
- package/src/oauth-protected-resource-metadata.ts +0 -94
- package/src/oauth-redirect-uri.ts +0 -73
- package/src/oauth-refresh-token-grant-token-request.ts +0 -11
- package/src/oauth-refresh-token.ts +0 -4
- package/src/oauth-request-uri.ts +0 -5
- package/src/oauth-response-mode.ts +0 -9
- package/src/oauth-response-type.ts +0 -17
- package/src/oauth-scope.ts +0 -21
- package/src/oauth-token-identification.ts +0 -12
- package/src/oauth-token-request.ts +0 -14
- package/src/oauth-token-response.ts +0 -29
- package/src/oauth-token-type.ts +0 -15
- package/src/oidc-authorization-error-response.ts +0 -29
- package/src/oidc-claims-parameter.ts +0 -40
- package/src/oidc-claims-properties.ts +0 -11
- package/src/oidc-entity-type.ts +0 -5
- package/src/oidc-userinfo.ts +0 -15
- package/src/uri.ts +0 -221
- package/src/util.ts +0 -170
- package/tsconfig.build.json +0 -8
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -4
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS } from './atproto-loopback-client-redirect-uris.js'
|
|
2
|
-
import {
|
|
3
|
-
AtprotoOAuthScope,
|
|
4
|
-
DEFAULT_ATPROTO_OAUTH_SCOPE,
|
|
5
|
-
asAtprotoOAuthScope,
|
|
6
|
-
isAtprotoOAuthScope,
|
|
7
|
-
} from './atproto-oauth-scope.js'
|
|
8
|
-
import {
|
|
9
|
-
LOOPBACK_CLIENT_ID_ORIGIN,
|
|
10
|
-
OAuthClientIdLoopback,
|
|
11
|
-
parseOAuthLoopbackClientId,
|
|
12
|
-
} from './oauth-client-id-loopback.js'
|
|
13
|
-
import {
|
|
14
|
-
OAuthLoopbackRedirectURI,
|
|
15
|
-
oauthLoopbackClientRedirectUriSchema,
|
|
16
|
-
} from './oauth-redirect-uri.js'
|
|
17
|
-
import { arrayEquivalent, asArray } from './util.js'
|
|
18
|
-
|
|
19
|
-
export type OAuthLoopbackClientIdConfig = {
|
|
20
|
-
scope?: string
|
|
21
|
-
redirect_uris?: Iterable<string>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function buildAtprotoLoopbackClientId(
|
|
25
|
-
config?: OAuthLoopbackClientIdConfig,
|
|
26
|
-
): OAuthClientIdLoopback {
|
|
27
|
-
if (config) {
|
|
28
|
-
const params = new URLSearchParams()
|
|
29
|
-
|
|
30
|
-
const { scope } = config
|
|
31
|
-
if (scope != null && scope !== DEFAULT_ATPROTO_OAUTH_SCOPE) {
|
|
32
|
-
params.set('scope', asAtprotoOAuthScope(scope))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const redirectUris = asArray(config.redirect_uris)
|
|
36
|
-
if (
|
|
37
|
-
redirectUris &&
|
|
38
|
-
!arrayEquivalent(redirectUris, DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS)
|
|
39
|
-
) {
|
|
40
|
-
if (!redirectUris.length) {
|
|
41
|
-
throw new TypeError(`Unexpected empty "redirect_uris" config`)
|
|
42
|
-
}
|
|
43
|
-
for (const uri of redirectUris) {
|
|
44
|
-
params.append(
|
|
45
|
-
'redirect_uri',
|
|
46
|
-
oauthLoopbackClientRedirectUriSchema.parse(uri),
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (params.size) {
|
|
52
|
-
return `${LOOPBACK_CLIENT_ID_ORIGIN}?${params.toString()}`
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return LOOPBACK_CLIENT_ID_ORIGIN
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export type AtprotoLoopbackClientIdParams = {
|
|
60
|
-
scope: AtprotoOAuthScope
|
|
61
|
-
redirect_uris: [OAuthLoopbackRedirectURI, ...OAuthLoopbackRedirectURI[]]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function parseAtprotoLoopbackClientId(
|
|
65
|
-
clientId: string,
|
|
66
|
-
): AtprotoLoopbackClientIdParams {
|
|
67
|
-
const { scope = DEFAULT_ATPROTO_OAUTH_SCOPE, redirect_uris } =
|
|
68
|
-
parseOAuthLoopbackClientId(clientId)
|
|
69
|
-
if (!isAtprotoOAuthScope(scope)) {
|
|
70
|
-
throw new TypeError(
|
|
71
|
-
'ATProto Loopback ClientID must include "atproto" scope',
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
scope,
|
|
76
|
-
redirect_uris: redirect_uris ?? [...DEFAULT_LOOPBACK_CLIENT_REDIRECT_URIS],
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AtprotoLoopbackClientIdParams,
|
|
3
|
-
OAuthLoopbackClientIdConfig,
|
|
4
|
-
buildAtprotoLoopbackClientId,
|
|
5
|
-
parseAtprotoLoopbackClientId,
|
|
6
|
-
} from './atproto-loopback-client-id.js'
|
|
7
|
-
import { AtprotoOAuthScope } from './atproto-oauth-scope.js'
|
|
8
|
-
import { OAuthClientIdLoopback } from './oauth-client-id-loopback.js'
|
|
9
|
-
import { OAuthClientMetadataInput } from './oauth-client-metadata.js'
|
|
10
|
-
import { OAuthLoopbackRedirectURI } from './oauth-redirect-uri.js'
|
|
11
|
-
|
|
12
|
-
export type AtprotoLoopbackClientMetadata = OAuthClientMetadataInput & {
|
|
13
|
-
client_id: OAuthClientIdLoopback
|
|
14
|
-
scope: AtprotoOAuthScope
|
|
15
|
-
redirect_uris: [OAuthLoopbackRedirectURI, ...OAuthLoopbackRedirectURI[]]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function atprotoLoopbackClientMetadata(
|
|
19
|
-
clientId: string,
|
|
20
|
-
): AtprotoLoopbackClientMetadata {
|
|
21
|
-
const params = parseAtprotoLoopbackClientId(clientId)
|
|
22
|
-
// Safe to cast because parseAtprotoLoopbackClientId ensures it's a loopback ID
|
|
23
|
-
return buildMetadataInternal(clientId as OAuthClientIdLoopback, params)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function buildAtprotoLoopbackClientMetadata(
|
|
27
|
-
config: OAuthLoopbackClientIdConfig,
|
|
28
|
-
): AtprotoLoopbackClientMetadata {
|
|
29
|
-
const clientId = buildAtprotoLoopbackClientId(config)
|
|
30
|
-
return buildMetadataInternal(clientId, parseAtprotoLoopbackClientId(clientId))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function buildMetadataInternal(
|
|
34
|
-
clientId: OAuthClientIdLoopback,
|
|
35
|
-
clientParams: AtprotoLoopbackClientIdParams,
|
|
36
|
-
): AtprotoLoopbackClientMetadata {
|
|
37
|
-
return {
|
|
38
|
-
client_id: clientId,
|
|
39
|
-
scope: clientParams.scope,
|
|
40
|
-
redirect_uris: clientParams.redirect_uris,
|
|
41
|
-
response_types: ['code'],
|
|
42
|
-
grant_types: ['authorization_code', 'refresh_token'],
|
|
43
|
-
token_endpoint_auth_method: 'none',
|
|
44
|
-
application_type: 'native',
|
|
45
|
-
dpop_bound_access_tokens: true,
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { OAuthScope, isOAuthScope } from './oauth-scope.js'
|
|
3
|
-
import { SpaceSeparatedValue, isSpaceSeparatedValue } from './util.js'
|
|
4
|
-
|
|
5
|
-
export const ATPROTO_SCOPE_VALUE = 'atproto'
|
|
6
|
-
export type AtprotoScopeValue = typeof ATPROTO_SCOPE_VALUE
|
|
7
|
-
|
|
8
|
-
export type AtprotoOAuthScope = OAuthScope &
|
|
9
|
-
SpaceSeparatedValue<AtprotoScopeValue>
|
|
10
|
-
|
|
11
|
-
export function isAtprotoOAuthScope(input: string): input is AtprotoOAuthScope {
|
|
12
|
-
return (
|
|
13
|
-
isOAuthScope(input) && isSpaceSeparatedValue(ATPROTO_SCOPE_VALUE, input)
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function asAtprotoOAuthScope<I extends string>(input: I) {
|
|
18
|
-
if (isAtprotoOAuthScope(input)) return input
|
|
19
|
-
throw new TypeError(`Value must contain "${ATPROTO_SCOPE_VALUE}" scope value`)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function assertAtprotoOAuthScope(
|
|
23
|
-
input: string,
|
|
24
|
-
): asserts input is AtprotoOAuthScope {
|
|
25
|
-
void asAtprotoOAuthScope(input)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const atprotoOAuthScopeSchema = z.string().refine(isAtprotoOAuthScope, {
|
|
29
|
-
message: 'Invalid ATProto OAuth scope',
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// Default scope is for reading identity (did) only
|
|
33
|
-
export const DEFAULT_ATPROTO_OAUTH_SCOPE =
|
|
34
|
-
ATPROTO_SCOPE_VALUE satisfies AtprotoOAuthScope
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { TypeOf, z } from 'zod'
|
|
2
|
-
import { atprotoDidSchema } from '@atproto/did'
|
|
3
|
-
import { atprotoOAuthScopeSchema } from './atproto-oauth-scope.js'
|
|
4
|
-
import { oauthTokenResponseSchema } from './oauth-token-response.js'
|
|
5
|
-
|
|
6
|
-
export const atprotoOAuthTokenResponseSchema = oauthTokenResponseSchema.extend({
|
|
7
|
-
token_type: z.literal('DPoP'),
|
|
8
|
-
sub: atprotoDidSchema,
|
|
9
|
-
scope: atprotoOAuthScopeSchema,
|
|
10
|
-
// OpenID is not compatible with atproto identities
|
|
11
|
-
id_token: z.never().optional(),
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export type AtprotoOAuthTokenResponse = TypeOf<
|
|
15
|
-
typeof atprotoOAuthTokenResponseSchema
|
|
16
|
-
>
|
package/src/constants.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export * from './constants.js'
|
|
2
|
-
export * from './uri.js'
|
|
3
|
-
export * from './util.js'
|
|
4
|
-
|
|
5
|
-
export * from './atproto-loopback-client-id.js'
|
|
6
|
-
export * from './atproto-loopback-client-metadata.js'
|
|
7
|
-
export * from './atproto-loopback-client-redirect-uris.js'
|
|
8
|
-
export * from './atproto-oauth-scope.js'
|
|
9
|
-
export * from './atproto-oauth-token-response.js'
|
|
10
|
-
export * from './oauth-access-token.js'
|
|
11
|
-
export * from './oauth-authorization-code-grant-token-request.js'
|
|
12
|
-
export * from './oauth-authorization-details.js'
|
|
13
|
-
export * from './oauth-authorization-request-jar.js'
|
|
14
|
-
export * from './oauth-authorization-request-par.js'
|
|
15
|
-
export * from './oauth-authorization-request-parameters.js'
|
|
16
|
-
export * from './oauth-authorization-request-query.js'
|
|
17
|
-
export * from './oauth-authorization-request-uri.js'
|
|
18
|
-
export * from './oauth-authorization-response-error.js'
|
|
19
|
-
export * from './oauth-authorization-server-metadata.js'
|
|
20
|
-
export * from './oauth-client-credentials-grant-token-request.js'
|
|
21
|
-
export * from './oauth-client-credentials.js'
|
|
22
|
-
export * from './oauth-client-id-discoverable.js'
|
|
23
|
-
export * from './oauth-client-id-loopback.js'
|
|
24
|
-
export * from './oauth-client-id.js'
|
|
25
|
-
export * from './oauth-client-metadata.js'
|
|
26
|
-
export * from './oauth-endpoint-auth-method.js'
|
|
27
|
-
export * from './oauth-endpoint-name.js'
|
|
28
|
-
export * from './oauth-grant-type.js'
|
|
29
|
-
export * from './oauth-introspection-response.js'
|
|
30
|
-
export * from './oauth-issuer-identifier.js'
|
|
31
|
-
export * from './oauth-par-response.js'
|
|
32
|
-
export * from './oauth-password-grant-token-request.js'
|
|
33
|
-
export * from './oauth-prompt-mode.js'
|
|
34
|
-
export * from './oauth-protected-resource-metadata.js'
|
|
35
|
-
export * from './oauth-redirect-uri.js'
|
|
36
|
-
export * from './oauth-refresh-token-grant-token-request.js'
|
|
37
|
-
export * from './oauth-refresh-token.js'
|
|
38
|
-
export * from './oauth-request-uri.js'
|
|
39
|
-
export * from './oauth-response-mode.js'
|
|
40
|
-
export * from './oauth-response-type.js'
|
|
41
|
-
export * from './oauth-scope.js'
|
|
42
|
-
export * from './oauth-token-identification.js'
|
|
43
|
-
export * from './oauth-token-request.js'
|
|
44
|
-
export * from './oauth-token-response.js'
|
|
45
|
-
export * from './oauth-token-type.js'
|
|
46
|
-
export * from './oidc-authorization-error-response.js'
|
|
47
|
-
export * from './oidc-claims-parameter.js'
|
|
48
|
-
export * from './oidc-claims-properties.js'
|
|
49
|
-
export * from './oidc-entity-type.js'
|
|
50
|
-
export * from './oidc-userinfo.js'
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { oauthRedirectUriSchema } from './oauth-redirect-uri.js'
|
|
3
|
-
|
|
4
|
-
export const oauthAuthorizationCodeGrantTokenRequestSchema = z.object({
|
|
5
|
-
grant_type: z.literal('authorization_code'),
|
|
6
|
-
code: z.string().min(1),
|
|
7
|
-
redirect_uri: oauthRedirectUriSchema,
|
|
8
|
-
/** @see {@link https://datatracker.ietf.org/doc/html/rfc7636#section-4.1} */
|
|
9
|
-
code_verifier: z
|
|
10
|
-
.string()
|
|
11
|
-
.min(43)
|
|
12
|
-
.max(128)
|
|
13
|
-
.regex(/^[a-zA-Z0-9-._~]+$/)
|
|
14
|
-
.optional(),
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
export type OAuthAuthorizationCodeGrantTokenRequest = z.infer<
|
|
18
|
-
typeof oauthAuthorizationCodeGrantTokenRequestSchema
|
|
19
|
-
>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { dangerousUriSchema } from './uri.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc9396#section-2 | RFC 9396, Section 2}
|
|
6
|
-
*/
|
|
7
|
-
export const oauthAuthorizationDetailSchema = z.object({
|
|
8
|
-
type: z.string(),
|
|
9
|
-
/**
|
|
10
|
-
* An array of strings representing the location of the resource or RS. These
|
|
11
|
-
* strings are typically URIs identifying the location of the RS.
|
|
12
|
-
*/
|
|
13
|
-
locations: z.array(dangerousUriSchema).optional(),
|
|
14
|
-
/**
|
|
15
|
-
* An array of strings representing the kinds of actions to be taken at the
|
|
16
|
-
* resource.
|
|
17
|
-
*/
|
|
18
|
-
actions: z.array(z.string()).optional(),
|
|
19
|
-
/**
|
|
20
|
-
* An array of strings representing the kinds of data being requested from the
|
|
21
|
-
* resource.
|
|
22
|
-
*/
|
|
23
|
-
datatypes: z.array(z.string()).optional(),
|
|
24
|
-
/**
|
|
25
|
-
* A string identifier indicating a specific resource available at the API.
|
|
26
|
-
*/
|
|
27
|
-
identifier: z.string().optional(),
|
|
28
|
-
/**
|
|
29
|
-
* An array of strings representing the types or levels of privilege being
|
|
30
|
-
* requested at the resource.
|
|
31
|
-
*/
|
|
32
|
-
privileges: z.array(z.string()).optional(),
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
export type OAuthAuthorizationDetail = z.infer<
|
|
36
|
-
typeof oauthAuthorizationDetailSchema
|
|
37
|
-
>
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc9396#section-2 | RFC 9396, Section 2}
|
|
41
|
-
*/
|
|
42
|
-
export const oauthAuthorizationDetailsSchema = z.array(
|
|
43
|
-
oauthAuthorizationDetailSchema,
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
export type OAuthAuthorizationDetails = z.infer<
|
|
47
|
-
typeof oauthAuthorizationDetailsSchema
|
|
48
|
-
>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { signedJwtSchema, unsignedJwtSchema } from '@atproto/jwk'
|
|
3
|
-
|
|
4
|
-
export const oauthAuthorizationRequestJarSchema = z.object({
|
|
5
|
-
/**
|
|
6
|
-
* AuthorizationRequest inside a JWT:
|
|
7
|
-
* - "iat" is required and **MUST** be less than one minute
|
|
8
|
-
*
|
|
9
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc9101}
|
|
10
|
-
*/
|
|
11
|
-
request: z.union([signedJwtSchema, unsignedJwtSchema]),
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export type OAuthAuthorizationRequestJar = z.infer<
|
|
15
|
-
typeof oauthAuthorizationRequestJarSchema
|
|
16
|
-
>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { oauthAuthorizationRequestJarSchema } from './oauth-authorization-request-jar.js'
|
|
3
|
-
import { oauthAuthorizationRequestParametersSchema } from './oauth-authorization-request-parameters.js'
|
|
4
|
-
|
|
5
|
-
export const oauthAuthorizationRequestParSchema = z.union([
|
|
6
|
-
oauthAuthorizationRequestParametersSchema,
|
|
7
|
-
oauthAuthorizationRequestJarSchema,
|
|
8
|
-
])
|
|
9
|
-
|
|
10
|
-
export type OAuthAuthorizationRequestPar = z.infer<
|
|
11
|
-
typeof oauthAuthorizationRequestParSchema
|
|
12
|
-
>
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { signedJwtSchema } from '@atproto/jwk'
|
|
3
|
-
import { oauthAuthorizationDetailsSchema } from './oauth-authorization-details.js'
|
|
4
|
-
import { oauthClientIdSchema } from './oauth-client-id.js'
|
|
5
|
-
import { oauthCodeChallengeMethodSchema } from './oauth-code-challenge-method.js'
|
|
6
|
-
import { oauthPromptModeSchema } from './oauth-prompt-mode.js'
|
|
7
|
-
import { oauthRedirectUriSchema } from './oauth-redirect-uri.js'
|
|
8
|
-
import { oauthResponseModeSchema } from './oauth-response-mode.js'
|
|
9
|
-
import { oauthResponseTypeSchema } from './oauth-response-type.js'
|
|
10
|
-
import { oauthScopeSchema } from './oauth-scope.js'
|
|
11
|
-
import { oidcClaimsParameterSchema } from './oidc-claims-parameter.js'
|
|
12
|
-
import { oidcClaimsPropertiesSchema } from './oidc-claims-properties.js'
|
|
13
|
-
import { oidcEntityTypeSchema } from './oidc-entity-type.js'
|
|
14
|
-
import { jsonObjectPreprocess, numberPreprocess } from './util.js'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @note non string parameters will be converted from their string
|
|
18
|
-
* representation since oauth request parameters are typically sent as URL
|
|
19
|
-
* encoded form data or URL encoded query string.
|
|
20
|
-
* @see {@link https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest | OIDC}
|
|
21
|
-
*/
|
|
22
|
-
export const oauthAuthorizationRequestParametersSchema = z.object({
|
|
23
|
-
client_id: oauthClientIdSchema,
|
|
24
|
-
state: z.string().optional(),
|
|
25
|
-
redirect_uri: oauthRedirectUriSchema.optional(),
|
|
26
|
-
scope: oauthScopeSchema.optional(),
|
|
27
|
-
response_type: oauthResponseTypeSchema,
|
|
28
|
-
|
|
29
|
-
// PKCE
|
|
30
|
-
|
|
31
|
-
// https://datatracker.ietf.org/doc/html/rfc7636#section-4.3
|
|
32
|
-
code_challenge: z.string().optional(),
|
|
33
|
-
code_challenge_method: oauthCodeChallengeMethodSchema.optional(),
|
|
34
|
-
|
|
35
|
-
// DPOP
|
|
36
|
-
|
|
37
|
-
// https://datatracker.ietf.org/doc/html/rfc9449#section-12.3
|
|
38
|
-
dpop_jkt: z.string().optional(),
|
|
39
|
-
|
|
40
|
-
// OIDC
|
|
41
|
-
|
|
42
|
-
// Default depend on response_type
|
|
43
|
-
response_mode: oauthResponseModeSchema.optional(),
|
|
44
|
-
|
|
45
|
-
nonce: z.string().optional(),
|
|
46
|
-
|
|
47
|
-
// Specifies the allowable elapsed time in seconds since the last time the
|
|
48
|
-
// End-User was actively authenticated by the OP. If the elapsed time is
|
|
49
|
-
// greater than this value, the OP MUST attempt to actively re-authenticate
|
|
50
|
-
// the End-User. (The max_age request parameter corresponds to the OpenID 2.0
|
|
51
|
-
// PAPE [OpenID.PAPE] max_auth_age request parameter.) When max_age is used,
|
|
52
|
-
// the ID Token returned MUST include an auth_time Claim Value. Note that
|
|
53
|
-
// max_age=0 is equivalent to prompt=login.
|
|
54
|
-
max_age: z.preprocess(numberPreprocess, z.number().int().min(0)).optional(),
|
|
55
|
-
|
|
56
|
-
claims: z
|
|
57
|
-
.preprocess(
|
|
58
|
-
jsonObjectPreprocess,
|
|
59
|
-
z.record(
|
|
60
|
-
oidcEntityTypeSchema,
|
|
61
|
-
z.record(
|
|
62
|
-
oidcClaimsParameterSchema,
|
|
63
|
-
z.union([z.literal(null), oidcClaimsPropertiesSchema]),
|
|
64
|
-
),
|
|
65
|
-
),
|
|
66
|
-
)
|
|
67
|
-
.optional(),
|
|
68
|
-
|
|
69
|
-
// https://openid.net/specs/openid-connect-core-1_0.html#RegistrationParameter
|
|
70
|
-
// Not supported by this library (yet?)
|
|
71
|
-
// registration: clientMetadataSchema.optional(),
|
|
72
|
-
|
|
73
|
-
login_hint: z.string().min(1).optional(),
|
|
74
|
-
|
|
75
|
-
ui_locales: z
|
|
76
|
-
.string()
|
|
77
|
-
.regex(/^[a-z]{2,3}(-[A-Z]{2})?( [a-z]{2,3}(-[A-Z]{2})?)*$/) // fr-CA fr en
|
|
78
|
-
.optional(),
|
|
79
|
-
|
|
80
|
-
// Previous ID Token, should be provided when prompt=none is used
|
|
81
|
-
id_token_hint: signedJwtSchema.optional(),
|
|
82
|
-
|
|
83
|
-
// Type of UI the AS is displayed on
|
|
84
|
-
display: z.enum(['page', 'popup', 'touch', 'wap']).optional(),
|
|
85
|
-
|
|
86
|
-
// How the AS should prompt the user for authorization:
|
|
87
|
-
prompt: oauthPromptModeSchema.optional(),
|
|
88
|
-
|
|
89
|
-
// https://datatracker.ietf.org/doc/html/rfc9396
|
|
90
|
-
authorization_details: z
|
|
91
|
-
.preprocess(jsonObjectPreprocess, oauthAuthorizationDetailsSchema)
|
|
92
|
-
.optional(),
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @see {oauthAuthorizationRequestParametersSchema}
|
|
97
|
-
*/
|
|
98
|
-
export type OAuthAuthorizationRequestParameters = z.infer<
|
|
99
|
-
typeof oauthAuthorizationRequestParametersSchema
|
|
100
|
-
>
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { oauthAuthorizationRequestJarSchema } from './oauth-authorization-request-jar.js'
|
|
3
|
-
import { oauthAuthorizationRequestParametersSchema } from './oauth-authorization-request-parameters.js'
|
|
4
|
-
import { oauthAuthorizationRequestUriSchema } from './oauth-authorization-request-uri.js'
|
|
5
|
-
import { oauthClientIdSchema } from './oauth-client-id.js'
|
|
6
|
-
|
|
7
|
-
export const oauthAuthorizationRequestQuerySchema = z.intersection(
|
|
8
|
-
z.object({
|
|
9
|
-
// REQUIRED. OAuth 2.0 [RFC6749] client_id.
|
|
10
|
-
client_id: oauthClientIdSchema,
|
|
11
|
-
}),
|
|
12
|
-
z.union([
|
|
13
|
-
oauthAuthorizationRequestParametersSchema,
|
|
14
|
-
oauthAuthorizationRequestJarSchema,
|
|
15
|
-
oauthAuthorizationRequestUriSchema,
|
|
16
|
-
]),
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
export type OAuthAuthorizationRequestQuery = z.infer<
|
|
20
|
-
typeof oauthAuthorizationRequestQuerySchema
|
|
21
|
-
>
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { oauthRequestUriSchema } from './oauth-request-uri.js'
|
|
3
|
-
|
|
4
|
-
export const oauthAuthorizationRequestUriSchema = z.object({
|
|
5
|
-
request_uri: oauthRequestUriSchema,
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export type OAuthAuthorizationRequestUri = z.infer<
|
|
9
|
-
typeof oauthAuthorizationRequestUriSchema
|
|
10
|
-
>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @see {@link https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-1-12#name-error-response-2}
|
|
5
|
-
*/
|
|
6
|
-
export const oauthAuthorizationResponseErrorSchema = z.enum([
|
|
7
|
-
// The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
|
|
8
|
-
'invalid_request',
|
|
9
|
-
// The client is not authorized to request an authorization code using this method.
|
|
10
|
-
'unauthorized_client',
|
|
11
|
-
// The resource owner or authorization server denied the request.
|
|
12
|
-
'access_denied',
|
|
13
|
-
// The authorization server does not support obtaining an authorization code using this method.
|
|
14
|
-
'unsupported_response_type',
|
|
15
|
-
// The requested scope is invalid, unknown, or malformed.
|
|
16
|
-
'invalid_scope',
|
|
17
|
-
// The authorization server encountered an unexpected condition that prevented it from fulfilling the request. (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to the client via an HTTP redirect.)
|
|
18
|
-
'server_error',
|
|
19
|
-
// The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code cannot be returned to the client via an HTTP redirect.)
|
|
20
|
-
'temporarily_unavailable',
|
|
21
|
-
])
|
|
22
|
-
|
|
23
|
-
export type OAuthAuthorizationResponseError = z.infer<
|
|
24
|
-
typeof oauthAuthorizationResponseErrorSchema
|
|
25
|
-
>
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
import { oauthCodeChallengeMethodSchema } from './oauth-code-challenge-method.js'
|
|
3
|
-
import { oauthIssuerIdentifierSchema } from './oauth-issuer-identifier.js'
|
|
4
|
-
import { oauthPromptModeSchema } from './oauth-prompt-mode.js'
|
|
5
|
-
import { webUriSchema } from './uri.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @see {@link https://datatracker.ietf.org/doc/html/rfc8414}
|
|
9
|
-
* @note we do not enforce https: scheme in URIs to support development
|
|
10
|
-
* environments. Make sure to validate the URIs before using it in a production
|
|
11
|
-
* environment.
|
|
12
|
-
*/
|
|
13
|
-
export const oauthAuthorizationServerMetadataSchema = z.object({
|
|
14
|
-
issuer: oauthIssuerIdentifierSchema,
|
|
15
|
-
|
|
16
|
-
claims_supported: z.array(z.string()).optional(),
|
|
17
|
-
claims_locales_supported: z.array(z.string()).optional(),
|
|
18
|
-
claims_parameter_supported: z.boolean().optional(),
|
|
19
|
-
request_parameter_supported: z.boolean().optional(),
|
|
20
|
-
request_uri_parameter_supported: z.boolean().optional(),
|
|
21
|
-
require_request_uri_registration: z.boolean().optional(),
|
|
22
|
-
scopes_supported: z.array(z.string()).optional(),
|
|
23
|
-
subject_types_supported: z.array(z.string()).optional(),
|
|
24
|
-
response_types_supported: z.array(z.string()).optional(),
|
|
25
|
-
response_modes_supported: z.array(z.string()).optional(),
|
|
26
|
-
grant_types_supported: z.array(z.string()).optional(),
|
|
27
|
-
code_challenge_methods_supported: z
|
|
28
|
-
.array(oauthCodeChallengeMethodSchema)
|
|
29
|
-
.min(1)
|
|
30
|
-
.optional(),
|
|
31
|
-
ui_locales_supported: z.array(z.string()).optional(),
|
|
32
|
-
id_token_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
33
|
-
display_values_supported: z.array(z.string()).optional(),
|
|
34
|
-
request_object_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
35
|
-
authorization_response_iss_parameter_supported: z.boolean().optional(),
|
|
36
|
-
authorization_details_types_supported: z.array(z.string()).optional(),
|
|
37
|
-
request_object_encryption_alg_values_supported: z
|
|
38
|
-
.array(z.string())
|
|
39
|
-
.optional(),
|
|
40
|
-
request_object_encryption_enc_values_supported: z
|
|
41
|
-
.array(z.string())
|
|
42
|
-
.optional(),
|
|
43
|
-
|
|
44
|
-
jwks_uri: webUriSchema.optional(),
|
|
45
|
-
|
|
46
|
-
authorization_endpoint: webUriSchema, // .optional(),
|
|
47
|
-
|
|
48
|
-
token_endpoint: webUriSchema, // .optional(),
|
|
49
|
-
// https://www.rfc-editor.org/rfc/rfc8414.html#section-2
|
|
50
|
-
token_endpoint_auth_methods_supported: z
|
|
51
|
-
.array(z.string())
|
|
52
|
-
// > If omitted, the default is "client_secret_basic" [...].
|
|
53
|
-
.default(['client_secret_basic']),
|
|
54
|
-
token_endpoint_auth_signing_alg_values_supported: z
|
|
55
|
-
.array(z.string())
|
|
56
|
-
.optional(),
|
|
57
|
-
|
|
58
|
-
revocation_endpoint: webUriSchema.optional(),
|
|
59
|
-
introspection_endpoint: webUriSchema.optional(),
|
|
60
|
-
pushed_authorization_request_endpoint: webUriSchema.optional(),
|
|
61
|
-
|
|
62
|
-
require_pushed_authorization_requests: z.boolean().optional(),
|
|
63
|
-
|
|
64
|
-
userinfo_endpoint: webUriSchema.optional(),
|
|
65
|
-
end_session_endpoint: webUriSchema.optional(),
|
|
66
|
-
registration_endpoint: webUriSchema.optional(),
|
|
67
|
-
|
|
68
|
-
// https://datatracker.ietf.org/doc/html/rfc9449#section-5.1
|
|
69
|
-
dpop_signing_alg_values_supported: z.array(z.string()).optional(),
|
|
70
|
-
|
|
71
|
-
// https://www.rfc-editor.org/rfc/rfc9728.html#section-4
|
|
72
|
-
protected_resources: z.array(webUriSchema).optional(),
|
|
73
|
-
|
|
74
|
-
// https://www.ietf.org/archive/id/draft-ietf-oauth-client-id-metadata-document-00.html
|
|
75
|
-
client_id_metadata_document_supported: z.boolean().optional(),
|
|
76
|
-
|
|
77
|
-
// https://openid.net/specs/openid-connect-prompt-create-1_0.html#section-4.2
|
|
78
|
-
prompt_values_supported: z.array(oauthPromptModeSchema).optional(),
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
export type OAuthAuthorizationServerMetadata = z.infer<
|
|
82
|
-
typeof oauthAuthorizationServerMetadataSchema
|
|
83
|
-
>
|
|
84
|
-
|
|
85
|
-
export const oauthAuthorizationServerMetadataValidator =
|
|
86
|
-
oauthAuthorizationServerMetadataSchema
|
|
87
|
-
.superRefine((data, ctx) => {
|
|
88
|
-
if (
|
|
89
|
-
data.require_pushed_authorization_requests &&
|
|
90
|
-
!data.pushed_authorization_request_endpoint
|
|
91
|
-
) {
|
|
92
|
-
ctx.addIssue({
|
|
93
|
-
code: z.ZodIssueCode.custom,
|
|
94
|
-
message:
|
|
95
|
-
'"pushed_authorization_request_endpoint" required when "require_pushed_authorization_requests" is true',
|
|
96
|
-
})
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.superRefine((data, ctx) => {
|
|
100
|
-
if (data.response_types_supported) {
|
|
101
|
-
if (!data.response_types_supported.includes('code')) {
|
|
102
|
-
ctx.addIssue({
|
|
103
|
-
code: z.ZodIssueCode.custom,
|
|
104
|
-
message: 'Response type "code" is required',
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
.superRefine((data, ctx) => {
|
|
110
|
-
if (
|
|
111
|
-
data.token_endpoint_auth_signing_alg_values_supported?.includes('none')
|
|
112
|
-
) {
|
|
113
|
-
// https://openid.net/specs/openid-connect-discovery-1_0.html#rfc.section.3
|
|
114
|
-
// > The value `none` MUST NOT be used.
|
|
115
|
-
ctx.addIssue({
|
|
116
|
-
code: z.ZodIssueCode.custom,
|
|
117
|
-
message: 'Client authentication method "none" is not allowed',
|
|
118
|
-
})
|
|
119
|
-
}
|
|
120
|
-
})
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
export const oauthClientCredentialsGrantTokenRequestSchema = z.object({
|
|
4
|
-
grant_type: z.literal('client_credentials'),
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
export type OAuthClientCredentialsGrantTokenRequest = z.infer<
|
|
8
|
-
typeof oauthClientCredentialsGrantTokenRequestSchema
|
|
9
|
-
>
|