@whook/oauth2 25.2.1 → 26.0.2
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 +147 -98
- package/dist/index.d.ts +34 -11
- package/dist/index.js +18 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1671 -393
- package/dist/index.test.js.map +1 -1
- package/dist/libs/authorizationRequests.d.ts +6 -0
- package/dist/libs/authorizationRequests.js +22 -0
- package/dist/libs/authorizationRequests.js.map +1 -0
- package/dist/libs/authorizationRequests.test.js +24 -0
- package/dist/libs/authorizationRequests.test.js.map +1 -0
- package/dist/libs/clients.d.ts +2 -0
- package/dist/libs/clients.js +13 -0
- package/dist/libs/clients.js.map +1 -0
- package/dist/libs/errors.d.ts +143 -0
- package/dist/libs/errors.js +227 -0
- package/dist/libs/errors.js.map +1 -0
- package/dist/libs/grants.d.ts +2 -0
- package/dist/libs/grants.js +10 -0
- package/dist/libs/grants.js.map +1 -0
- package/dist/libs/redirectURI.d.ts +8 -0
- package/dist/libs/redirectURI.js +94 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +31 -0
- package/dist/libs/schemas.js +33 -0
- package/dist/libs/schemas.js.map +1 -0
- package/dist/libs/scopes.d.ts +16 -0
- package/dist/libs/scopes.js +37 -0
- package/dist/libs/scopes.js.map +1 -1
- package/dist/libs/utils.d.ts +2 -0
- package/dist/libs/utils.js +17 -0
- package/dist/libs/utils.js.map +1 -0
- package/dist/libs/verifier.d.ts +10 -0
- package/dist/libs/verifier.js +51 -0
- package/dist/libs/verifier.js.map +1 -0
- package/dist/libs/verifier.test.d.ts +1 -0
- package/dist/libs/verifier.test.js +21 -0
- package/dist/libs/verifier.test.js.map +1 -0
- package/dist/routes/getOAuth2Authorize.d.ts +38 -59
- package/dist/routes/getOAuth2Authorize.js +129 -93
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +959 -73
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +18 -11
- package/dist/routes/getOAuth2WellKnownMetadata.js +43 -11
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +51 -49
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
- package/dist/routes/postAuthLogin.d.ts +14 -9
- package/dist/routes/postAuthLogin.js +10 -5
- package/dist/routes/postAuthLogin.js.map +1 -1
- package/dist/routes/postAuthLogin.test.js +79 -55
- package/dist/routes/postAuthLogin.test.js.map +1 -1
- package/dist/routes/postAuthLogout.d.ts +5 -2
- package/dist/routes/postAuthLogout.js +12 -7
- package/dist/routes/postAuthLogout.js.map +1 -1
- package/dist/routes/postAuthLogout.test.js +35 -17
- package/dist/routes/postAuthLogout.test.js.map +1 -1
- package/dist/routes/postAuthRefresh.d.ts +14 -9
- package/dist/routes/postAuthRefresh.js +10 -6
- package/dist/routes/postAuthRefresh.js.map +1 -1
- package/dist/routes/postAuthRefresh.test.js +90 -59
- package/dist/routes/postAuthRefresh.test.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.d.ts +11 -10
- package/dist/routes/postOAuth2Acknowledge.js +43 -37
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +135 -70
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +137 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js +187 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.d.ts +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +554 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -0
- package/dist/routes/postOAuth2Revoke.d.ts +99 -0
- package/dist/routes/postOAuth2Revoke.js +102 -0
- package/dist/routes/postOAuth2Revoke.js.map +1 -0
- package/dist/routes/postOAuth2Revoke.test.d.ts +1 -0
- package/dist/routes/postOAuth2Revoke.test.js +161 -0
- package/dist/routes/postOAuth2Revoke.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +47 -108
- package/dist/routes/postOAuth2Token.js +65 -114
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/routes/postOAuth2Token.test.js +493 -61
- package/dist/routes/postOAuth2Token.test.js.map +1 -1
- package/dist/services/authCookies.d.ts +9 -13
- package/dist/services/authCookies.js +9 -5
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +124 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +204 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +345 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2AuthorizationRequests.d.ts +41 -0
- package/dist/services/oAuth2AuthorizationRequests.js +61 -0
- package/dist/services/oAuth2AuthorizationRequests.js.map +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.js +249 -0
- package/dist/services/oAuth2AuthorizationRequests.test.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +28 -12
- package/dist/services/oAuth2ClientCredentialsGranter.js +39 -21
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js +265 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +79 -86
- package/dist/services/oAuth2Granters.js +2 -67
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2ImplicitGranter.d.ts +38 -0
- package/dist/services/oAuth2ImplicitGranter.js +61 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +589 -0
- package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +43 -10
- package/dist/services/oAuth2PasswordGranter.js +53 -18
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.test.d.ts +1 -0
- package/dist/services/oAuth2PasswordGranter.test.js +455 -0
- package/dist/services/oAuth2PasswordGranter.test.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +42 -9
- package/dist/services/oAuth2RefreshTokenGranter.js +60 -21
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.test.d.ts +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js +403 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js.map +1 -0
- package/package.json +14 -13
- package/src/index.test.ts +1773 -407
- package/src/index.ts +63 -53
- package/src/libs/authorizationRequests.test.ts +40 -0
- package/src/libs/authorizationRequests.ts +42 -0
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +411 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +142 -0
- package/src/libs/schemas.ts +37 -0
- package/src/libs/scopes.ts +49 -0
- package/src/libs/utils.ts +24 -0
- package/src/libs/verifier.test.ts +37 -0
- package/src/libs/verifier.ts +75 -0
- package/src/routes/getOAuth2Authorize.test.ts +1102 -102
- package/src/routes/getOAuth2Authorize.ts +243 -151
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +73 -74
- package/src/routes/getOAuth2WellKnownMetadata.ts +63 -16
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +4 -6
- package/src/routes/postAuthLogin.test.ts +86 -57
- package/src/routes/postAuthLogin.ts +24 -14
- package/src/routes/postAuthLogout.test.ts +42 -18
- package/src/routes/postAuthLogout.ts +22 -8
- package/src/routes/postAuthRefresh.test.ts +98 -61
- package/src/routes/postAuthRefresh.ts +25 -13
- package/src/routes/postOAuth2Acknowledge.test.ts +167 -108
- package/src/routes/postOAuth2Acknowledge.ts +90 -64
- package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +681 -0
- package/src/routes/postOAuth2PushedAuthorizationRequest.ts +292 -0
- package/src/routes/postOAuth2Revoke.test.ts +179 -0
- package/src/routes/postOAuth2Revoke.ts +156 -0
- package/src/routes/postOAuth2Token.test.ts +570 -108
- package/src/routes/postOAuth2Token.ts +104 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +24 -22
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +407 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +365 -0
- package/src/services/oAuth2AuthorizationRequests.test.ts +282 -0
- package/src/services/oAuth2AuthorizationRequests.ts +141 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +100 -196
- package/src/services/oAuth2ImplicitGranter.test.ts +650 -0
- package/src/services/oAuth2ImplicitGranter.ts +147 -0
- package/src/services/oAuth2PasswordGranter.test.ts +493 -0
- package/src/services/oAuth2PasswordGranter.ts +116 -40
- package/src/services/oAuth2RefreshTokenGranter.test.ts +441 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +118 -51
- package/src/types.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +0 -41
- package/dist/services/oAuth2CodeGranter.js +0 -105
- package/dist/services/oAuth2CodeGranter.js.map +0 -1
- package/dist/services/oAuth2CodeGranter.test.js +0 -123
- package/dist/services/oAuth2CodeGranter.test.js.map +0 -1
- package/dist/services/oAuth2TokenGranter.d.ts +0 -22
- package/dist/services/oAuth2TokenGranter.js +0 -64
- package/dist/services/oAuth2TokenGranter.js.map +0 -1
- package/src/__snapshots__/index.test.ts.snap +0 -401
- package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -37
- package/src/routes/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -61
- package/src/routes/__snapshots__/postOAuth2Token.test.ts.snap +0 -52
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +0 -52
- package/src/services/oAuth2CodeGranter.test.ts +0 -176
- package/src/services/oAuth2CodeGranter.ts +0 -210
- package/src/services/oAuth2TokenGranter.ts +0 -119
- /package/dist/{services/oAuth2CodeGranter.test.d.ts → libs/authorizationRequests.test.d.ts} +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { type LogService } from 'common-services';
|
|
2
|
+
import { type WhookOAuth2ReadClientGrantsService, type WhookOAuth2GranterDefinitions, type WhookOAuth2GranterService, type WhookOAuth2Options } from '../services/oAuth2Granters.js';
|
|
3
|
+
import { codeChallengeMethodSchema, codeChallengeSchema } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
4
|
+
import { scopeSchema, requestURISchema } from '../libs/schemas.js';
|
|
5
|
+
import { type WhookOAuth2AuthorizationRequestsConfig, type WhookOAuth2AuthorizationRequestsService } from '../services/oAuth2AuthorizationRequests.js';
|
|
6
|
+
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
7
|
+
import { type WhookOAuth2AuthorizeRequestParameters } from './getOAuth2Authorize.js';
|
|
8
|
+
export { scopeSchema, requestURISchema, codeChallengeSchema, codeChallengeMethodSchema, };
|
|
9
|
+
export declare const pushedAuthorizationRequestBodySchema: {
|
|
10
|
+
readonly name: "PushedAuthorizationRequestBody";
|
|
11
|
+
readonly schema: {
|
|
12
|
+
readonly description: "OAuth2 Pushed Authorization Request, see https://datatracker.ietf.org/doc/html/rfc9126#section-2.1.";
|
|
13
|
+
readonly type: "object";
|
|
14
|
+
readonly required: ["response_type", "client_id"];
|
|
15
|
+
readonly properties: {
|
|
16
|
+
readonly response_type: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly enum: ["code", "token"];
|
|
19
|
+
};
|
|
20
|
+
readonly client_id: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
};
|
|
23
|
+
readonly redirect_uri: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly pattern: "^https?://";
|
|
26
|
+
readonly format: "uri";
|
|
27
|
+
};
|
|
28
|
+
readonly scope: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
29
|
+
readonly state: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
};
|
|
32
|
+
readonly code_challenge: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
33
|
+
readonly code_challenge_method: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare const definition: {
|
|
38
|
+
readonly method: "post";
|
|
39
|
+
readonly path: "/oauth2/par";
|
|
40
|
+
readonly config: {
|
|
41
|
+
readonly environments: [];
|
|
42
|
+
};
|
|
43
|
+
readonly operation: {
|
|
44
|
+
readonly operationId: "postOAuth2PushedAuthorizationRequest";
|
|
45
|
+
readonly summary: "Implements the [Pushed Authorization Request Endpoint](https://datatracker.ietf.org/doc/html/rfc9126#section-2).";
|
|
46
|
+
readonly tags: ["oauth2"];
|
|
47
|
+
readonly parameters: [];
|
|
48
|
+
readonly requestBody: {
|
|
49
|
+
readonly required: true;
|
|
50
|
+
readonly content: {
|
|
51
|
+
readonly 'application/x-www-form-urlencoded': {
|
|
52
|
+
readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
53
|
+
};
|
|
54
|
+
readonly 'application/json': {
|
|
55
|
+
readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
readonly responses: {
|
|
60
|
+
readonly '201': {
|
|
61
|
+
readonly description: "Request URI created.";
|
|
62
|
+
readonly headers: {
|
|
63
|
+
readonly 'cache-control': {
|
|
64
|
+
readonly schema: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
readonly pragma: {
|
|
69
|
+
readonly schema: {
|
|
70
|
+
readonly type: "string";
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
readonly content: {
|
|
75
|
+
readonly 'application/json': {
|
|
76
|
+
readonly schema: {
|
|
77
|
+
readonly type: "object";
|
|
78
|
+
readonly required: ["request_uri", "expires_in"];
|
|
79
|
+
readonly properties: {
|
|
80
|
+
readonly request_uri: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
81
|
+
readonly expires_in: {
|
|
82
|
+
readonly type: "number";
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
readonly '400': {
|
|
90
|
+
readonly description: "Request URI error response, see https://datatracker.ietf.org/doc/html/rfc9126#section-2.3.";
|
|
91
|
+
readonly content: {
|
|
92
|
+
readonly 'application/json': {
|
|
93
|
+
readonly schema: {
|
|
94
|
+
readonly type: "object";
|
|
95
|
+
readonly required: ["error"];
|
|
96
|
+
readonly properties: {
|
|
97
|
+
readonly error: {
|
|
98
|
+
readonly type: "string";
|
|
99
|
+
readonly enum: ["invalid_request", "invalid_scope", "invalid_client", "unauthorized_client", "unsupported_response_type"];
|
|
100
|
+
};
|
|
101
|
+
readonly error_description: {
|
|
102
|
+
readonly type: "string";
|
|
103
|
+
};
|
|
104
|
+
readonly error_uri: {
|
|
105
|
+
readonly type: "string";
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
declare const _default: import("knifecycle").ServiceInitializer<WhookOAuth2AuthorizationRequestsConfig & {
|
|
116
|
+
OAUTH2: WhookOAuth2Options;
|
|
117
|
+
oAuth2Granters: WhookOAuth2GranterService<WhookOAuth2GranterDefinitions>[];
|
|
118
|
+
oAuth2AuthorizationRequests: Pick<WhookOAuth2AuthorizationRequestsService, "create">;
|
|
119
|
+
readClientGrants: WhookOAuth2ReadClientGrantsService;
|
|
120
|
+
log?: LogService;
|
|
121
|
+
}, ({ body: { response_type: responseType, client_id: givenClientId, redirect_uri: demandedRedirectURI, scope: demandedScope, state, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod, request_uri: requestURI, }, authenticationData: optionalAuthenticationData, }: {
|
|
122
|
+
body: WhookOAuth2AuthorizeRequestParameters & {
|
|
123
|
+
request_uri?: string;
|
|
124
|
+
} & Record<string, string>;
|
|
125
|
+
authenticationData?: WhookAuthenticationData;
|
|
126
|
+
}) => Promise<{
|
|
127
|
+
status: number;
|
|
128
|
+
headers: {
|
|
129
|
+
'cache-control': string;
|
|
130
|
+
pragma: string;
|
|
131
|
+
};
|
|
132
|
+
body: {
|
|
133
|
+
request_uri: `urn:ietf:params:oauth:request_uri:${string}`;
|
|
134
|
+
expires_in: number;
|
|
135
|
+
};
|
|
136
|
+
}>>;
|
|
137
|
+
export default _default;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { autoService, location } from 'knifecycle';
|
|
2
|
+
import { YError } from 'yerror';
|
|
3
|
+
import { noop, refersTo, } from '@whook/whook';
|
|
4
|
+
import { filterScopes, parseOAuth2Scope, stringifyScopes, } from '../libs/scopes.js';
|
|
5
|
+
import { AUTHORIZATION_CODE_RESPONSE_TYPE, codeChallengeMethodSchema, codeChallengeSchema, } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
6
|
+
import { IMPLICIT_RESPONSE_TYPE } from '../services/oAuth2ImplicitGranter.js';
|
|
7
|
+
import { scopeSchema, requestURISchema } from '../libs/schemas.js';
|
|
8
|
+
import { checkCodeChallengeParameters, PLAIN_CODE_CHALLENGE_METHOD, } from '../libs/verifier.js';
|
|
9
|
+
import { DEFAULT_OAUTH2_PAR, } from '../services/oAuth2AuthorizationRequests.js';
|
|
10
|
+
import { toUsableClientId } from '../libs/clients.js';
|
|
11
|
+
import { getUsableRedirectURI } from '../libs/redirectURI.js';
|
|
12
|
+
export { scopeSchema, requestURISchema, codeChallengeSchema, codeChallengeMethodSchema, };
|
|
13
|
+
export const pushedAuthorizationRequestBodySchema = {
|
|
14
|
+
name: 'PushedAuthorizationRequestBody',
|
|
15
|
+
schema: {
|
|
16
|
+
description: 'OAuth2 Pushed Authorization Request, see https://datatracker.ietf.org/doc/html/rfc9126#section-2.1.',
|
|
17
|
+
type: 'object',
|
|
18
|
+
required: ['response_type', 'client_id'],
|
|
19
|
+
properties: {
|
|
20
|
+
response_type: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
enum: [AUTHORIZATION_CODE_RESPONSE_TYPE, IMPLICIT_RESPONSE_TYPE],
|
|
23
|
+
},
|
|
24
|
+
client_id: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
},
|
|
27
|
+
redirect_uri: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
pattern: '^https?://',
|
|
30
|
+
format: 'uri',
|
|
31
|
+
},
|
|
32
|
+
scope: refersTo(scopeSchema),
|
|
33
|
+
state: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
},
|
|
36
|
+
code_challenge: refersTo(codeChallengeSchema),
|
|
37
|
+
code_challenge_method: refersTo(codeChallengeMethodSchema),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
export const definition = {
|
|
42
|
+
method: 'post',
|
|
43
|
+
path: '/oauth2/par',
|
|
44
|
+
config: {
|
|
45
|
+
environments: [],
|
|
46
|
+
},
|
|
47
|
+
operation: {
|
|
48
|
+
operationId: 'postOAuth2PushedAuthorizationRequest',
|
|
49
|
+
summary: `Implements the [Pushed Authorization Request Endpoint](https://datatracker.ietf.org/doc/html/rfc9126#section-2).`,
|
|
50
|
+
tags: ['oauth2'],
|
|
51
|
+
parameters: [],
|
|
52
|
+
requestBody: {
|
|
53
|
+
required: true,
|
|
54
|
+
content: {
|
|
55
|
+
'application/x-www-form-urlencoded': {
|
|
56
|
+
schema: refersTo(pushedAuthorizationRequestBodySchema),
|
|
57
|
+
},
|
|
58
|
+
'application/json': {
|
|
59
|
+
schema: refersTo(pushedAuthorizationRequestBodySchema),
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
responses: {
|
|
64
|
+
'201': {
|
|
65
|
+
description: 'Request URI created.',
|
|
66
|
+
headers: {
|
|
67
|
+
'cache-control': {
|
|
68
|
+
schema: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
pragma: {
|
|
73
|
+
schema: {
|
|
74
|
+
type: 'string',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
content: {
|
|
79
|
+
'application/json': {
|
|
80
|
+
schema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
required: ['request_uri', 'expires_in'],
|
|
83
|
+
properties: {
|
|
84
|
+
request_uri: refersTo(requestURISchema),
|
|
85
|
+
expires_in: {
|
|
86
|
+
type: 'number',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
'400': {
|
|
94
|
+
description: 'Request URI error response, see https://datatracker.ietf.org/doc/html/rfc9126#section-2.3.',
|
|
95
|
+
content: {
|
|
96
|
+
'application/json': {
|
|
97
|
+
schema: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
required: ['error'],
|
|
100
|
+
properties: {
|
|
101
|
+
error: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
enum: [
|
|
104
|
+
'invalid_request',
|
|
105
|
+
'invalid_scope',
|
|
106
|
+
'invalid_client',
|
|
107
|
+
'unauthorized_client',
|
|
108
|
+
'unsupported_response_type',
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
error_description: { type: 'string' },
|
|
112
|
+
error_uri: { type: 'string' },
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
async function initPostOAuth2PushedAuthorizationRequest({ OAUTH2, OAUTH2_PAR = DEFAULT_OAUTH2_PAR, oAuth2Granters, oAuth2AuthorizationRequests, readClientGrants, log = noop, }) {
|
|
122
|
+
if (OAUTH2_PAR.mode === 'disabled') {
|
|
123
|
+
log('error', `💥 - OAuth2 PAR endpoint should be disabled when PAR is.`);
|
|
124
|
+
throw new YError('E_OAUTH2_MISCONFIGURED');
|
|
125
|
+
}
|
|
126
|
+
return async ({ body: { response_type: responseType, client_id: givenClientId, redirect_uri: demandedRedirectURI = '', scope: demandedScope = '', state, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod, request_uri: requestURI, }, authenticationData: optionalAuthenticationData, }) => {
|
|
127
|
+
const usableClientId = toUsableClientId([
|
|
128
|
+
optionalAuthenticationData?.clientId,
|
|
129
|
+
givenClientId,
|
|
130
|
+
]);
|
|
131
|
+
const clientGrants = await readClientGrants(usableClientId);
|
|
132
|
+
if (usableClientId !== clientGrants.authenticationData.clientId) {
|
|
133
|
+
throw new YError('E_OAUTH2_CLIENT_GRANTS_MISMATCH', [
|
|
134
|
+
usableClientId,
|
|
135
|
+
clientGrants.authenticationData.clientId,
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
if (!clientGrants.isPublicClient) {
|
|
139
|
+
if (!optionalAuthenticationData) {
|
|
140
|
+
throw new YError('E_OAUTH2_AUTHENTICATION_REQUIRED', [usableClientId]);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const usableRedirectURI = getUsableRedirectURI(clientGrants.allowedRedirectURIS, demandedRedirectURI);
|
|
144
|
+
const demandedScopes = filterScopes(filterScopes(parseOAuth2Scope(demandedScope), OAUTH2.allowedScopes, !!OAUTH2.strictScopesChecks), clientGrants.allowedScopes, !!OAUTH2.strictScopesChecks);
|
|
145
|
+
if (requestURI) {
|
|
146
|
+
throw new YError('E_OAUTH2_REQUEST_URI_NOT_ALLOWED');
|
|
147
|
+
}
|
|
148
|
+
checkCodeChallengeParameters(responseType, codeChallenge, OAUTH2.forcePKCE);
|
|
149
|
+
const granter = oAuth2Granters.find((granter) => granter.responseType === responseType);
|
|
150
|
+
if (!granter?.authorize) {
|
|
151
|
+
throw new YError('E_OAUTH2_UNKNOWN_RESPONSE_TYPE', [responseType]);
|
|
152
|
+
}
|
|
153
|
+
const { scopes } = await granter.authorize({
|
|
154
|
+
clientId: usableClientId,
|
|
155
|
+
clientGrants,
|
|
156
|
+
demandedScopes,
|
|
157
|
+
});
|
|
158
|
+
const paramsHash = {
|
|
159
|
+
response_type: responseType,
|
|
160
|
+
redirect_uri: usableRedirectURI,
|
|
161
|
+
scope: stringifyScopes(scopes),
|
|
162
|
+
client_id: usableClientId,
|
|
163
|
+
};
|
|
164
|
+
if (responseType === AUTHORIZATION_CODE_RESPONSE_TYPE && codeChallenge) {
|
|
165
|
+
paramsHash.code_challenge = codeChallenge;
|
|
166
|
+
paramsHash.code_challenge_method =
|
|
167
|
+
codeChallengeMethod || PLAIN_CODE_CHALLENGE_METHOD;
|
|
168
|
+
}
|
|
169
|
+
if (state) {
|
|
170
|
+
paramsHash.state = state;
|
|
171
|
+
}
|
|
172
|
+
const { requestURI: pushedRequestURI, expiresIn } = await oAuth2AuthorizationRequests.create(usableClientId, paramsHash);
|
|
173
|
+
return {
|
|
174
|
+
status: 201,
|
|
175
|
+
headers: {
|
|
176
|
+
'cache-control': 'no-store',
|
|
177
|
+
pragma: 'no-cache',
|
|
178
|
+
},
|
|
179
|
+
body: {
|
|
180
|
+
request_uri: pushedRequestURI,
|
|
181
|
+
expires_in: Math.floor(expiresIn / 1000),
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export default location(autoService(initPostOAuth2PushedAuthorizationRequest), import.meta.url);
|
|
187
|
+
//# sourceMappingURL=postOAuth2PushedAuthorizationRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postOAuth2PushedAuthorizationRequest.js","sourceRoot":"","sources":["../../src/routes/postOAuth2PushedAuthorizationRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,IAAI,EACJ,QAAQ,GAGT,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,GAGnB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,GAC1B,CAAC;AAEF,MAAM,CAAC,MAAM,oCA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