@whook/oauth2 25.2.1 → 26.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 +147 -98
- package/dist/index.d.ts +30 -11
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1258 -399
- package/dist/index.test.js.map +1 -1
- 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 +113 -0
- package/dist/libs/errors.js +178 -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 +7 -0
- package/dist/libs/redirectURI.js +78 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +23 -0
- package/dist/libs/schemas.js +25 -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 +7 -0
- package/dist/libs/verifier.js +37 -0
- package/dist/libs/verifier.js.map +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 +13 -50
- package/dist/routes/getOAuth2Authorize.js +60 -86
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +147 -68
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js +15 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +37 -37
- 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/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 +35 -108
- package/dist/routes/postOAuth2Token.js +53 -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 +1 -1
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +129 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +221 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +474 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.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 +81 -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 +72 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +727 -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 +11 -11
- package/src/index.test.ts +1314 -404
- package/src/index.ts +46 -53
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +325 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +120 -0
- package/src/libs/schemas.ts +27 -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 +57 -0
- package/src/routes/getOAuth2Authorize.test.ts +179 -96
- package/src/routes/getOAuth2Authorize.ts +97 -124
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +57 -60
- package/src/routes/getOAuth2WellKnownMetadata.ts +21 -10
- 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/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 +92 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +16 -18
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +564 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +388 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +101 -195
- package/src/services/oAuth2ImplicitGranter.test.ts +811 -0
- package/src/services/oAuth2ImplicitGranter.ts +163 -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/verifier.test.d.ts} +0 -0
|
@@ -1,21 +1,42 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { describe, test, jest, expect } from '@jest/globals';
|
|
2
|
+
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
3
3
|
import initPostAuthRefresh from './postAuthRefresh.js';
|
|
4
4
|
describe('postAuthRefresh', () => {
|
|
5
|
+
const OAUTH2 = {
|
|
6
|
+
authenticateURL: 'https://auth.example.com/sign_in',
|
|
7
|
+
allowedScopes: ['user', 'admin'],
|
|
8
|
+
rootClientId: 'root_app_id',
|
|
9
|
+
};
|
|
10
|
+
const readClientGrants = jest.fn();
|
|
11
|
+
const authCookies = {
|
|
12
|
+
parse: jest.fn(),
|
|
13
|
+
build: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
const postOAuth2Token = jest.fn();
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
readClientGrants.mockReset();
|
|
18
|
+
authCookies.parse.mockReset();
|
|
19
|
+
authCookies.build.mockReset();
|
|
20
|
+
postOAuth2Token.mockReset();
|
|
21
|
+
});
|
|
5
22
|
test('should work', async () => {
|
|
6
|
-
const authCookies = {
|
|
7
|
-
parse: jest.fn(),
|
|
8
|
-
build: jest.fn(),
|
|
9
|
-
};
|
|
10
|
-
const postOAuth2Token = jest.fn();
|
|
11
23
|
const postAuthRefresh = await initPostAuthRefresh({
|
|
12
|
-
|
|
13
|
-
scope: 'user',
|
|
14
|
-
applicationId: 'root_app_id',
|
|
15
|
-
},
|
|
24
|
+
OAUTH2,
|
|
16
25
|
authCookies,
|
|
26
|
+
readClientGrants,
|
|
17
27
|
postOAuth2Token,
|
|
18
28
|
});
|
|
29
|
+
readClientGrants.mockResolvedValue({
|
|
30
|
+
allowedScopes: ['user', 'admin'],
|
|
31
|
+
allowedRedirectURIS: ['https://www.example.com'],
|
|
32
|
+
allowedGrantTypes: ['code'],
|
|
33
|
+
authenticationData: {
|
|
34
|
+
clientId: 'root_app_id',
|
|
35
|
+
scopes: ['user', 'admin'],
|
|
36
|
+
userId: 'user_id',
|
|
37
|
+
},
|
|
38
|
+
isPublicClient: true,
|
|
39
|
+
});
|
|
19
40
|
authCookies.parse.mockReturnValueOnce({
|
|
20
41
|
access_token: 'an_access_token',
|
|
21
42
|
refresh_token: 'a_refresh_token',
|
|
@@ -39,59 +60,69 @@ describe('postAuthRefresh', () => {
|
|
|
39
60
|
});
|
|
40
61
|
expect({
|
|
41
62
|
response,
|
|
63
|
+
readClientGrantsCalls: readClientGrants.mock.calls,
|
|
42
64
|
authCookiesParseCalls: authCookies.parse.mock.calls,
|
|
43
65
|
authCookiesBuildCalls: authCookies.build.mock.calls,
|
|
44
66
|
postOAuth2TokenCalls: postOAuth2Token.mock.calls,
|
|
45
67
|
}).toMatchInlineSnapshot(`
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
68
|
+
{
|
|
69
|
+
"authCookiesBuildCalls": [
|
|
70
|
+
[
|
|
71
|
+
{
|
|
72
|
+
"access_token": "an_access_token",
|
|
73
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
74
|
+
"expires_in": 3600,
|
|
75
|
+
"token_type": "bearer",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"session": true,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
],
|
|
82
|
+
"authCookiesParseCalls": [
|
|
83
|
+
[
|
|
84
|
+
"a_given_cookie",
|
|
85
|
+
],
|
|
86
|
+
],
|
|
87
|
+
"postOAuth2TokenCalls": [
|
|
88
|
+
[
|
|
89
|
+
{
|
|
90
|
+
"authenticationData": {
|
|
91
|
+
"clientId": "root_app_id",
|
|
92
|
+
"scopes": [
|
|
93
|
+
"user",
|
|
94
|
+
"admin",
|
|
95
|
+
],
|
|
96
|
+
"userId": "user_id",
|
|
97
|
+
},
|
|
98
|
+
"body": {
|
|
99
|
+
"grant_type": "refresh_token",
|
|
100
|
+
"refresh_token": "a_refresh_token",
|
|
101
|
+
"scope": "user",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
],
|
|
106
|
+
"readClientGrantsCalls": [
|
|
107
|
+
[
|
|
108
|
+
"root_app_id",
|
|
109
|
+
],
|
|
110
|
+
],
|
|
111
|
+
"response": {
|
|
112
|
+
"body": {
|
|
113
|
+
"access_token": "an_access_token",
|
|
114
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
115
|
+
"expires_in": 3600,
|
|
116
|
+
"token_type": "bearer",
|
|
117
|
+
},
|
|
118
|
+
"headers": {
|
|
119
|
+
"Set-Cookie": [
|
|
120
|
+
"the_build_cookies",
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
"status": 200,
|
|
124
|
+
},
|
|
125
|
+
}
|
|
95
126
|
`);
|
|
96
127
|
});
|
|
97
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postAuthRefresh.test.js","sourceRoot":"","sources":["../../src/routes/postAuthRefresh.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"postAuthRefresh.test.js","sourceRoot":"","sources":["../../src/routes/postAuthRefresh.test.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,mBAAmB,MAAM,sBAAsB,CAAC;A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AiB;SACjC,CAAC,CAAC;QACH,WAAW,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC7D,eAAe,CAAC,qBAAqB,CAAC;YACpC,MAAM,EAAE,GAAG;YACX,IAAI,EAAE;gBACJ,YAAY,EAAE,iBAAiB;gBAC/B,eAAe,EAAE,sBAAsB;gBACvC,UAAU,EAAE,IAAI;gBAChB,UAAU,EAAE,QAAQ;aACrB;SACF,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC;YACrC,OAAO,EAAE,EAAE,MAAM,EAAE,gBAAgB,EAAE;YACrC,IAAI,EAAE;gBACJ,QAAQ,EAAE,KAAK;gBACf,KAAK,EAAE,MAAM;aACd;SACF,CAAC,CAAC;QAEH,MAAM,CAAC;YACL,QAAQ;YACR,qBAAqB,EAAE,gBAAgB,CAAC,IAAI,CAAC,KAAK;YAClD,qBAAqB,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;YACnD,qBAAqB,EAAE,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;YACnD,oBAAoB,EAAE,eAAe,CAAC,IAAI,CAAC,KAAK;SACjD,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2DxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type WhookErrorsDescriptors } from '@whook/whook';
|
|
2
|
-
import { type
|
|
2
|
+
import { type WhookOAuth2Options, type WhookOAuth2ReadClientGrantsService, type WhookOAuth2GranterService, type WhookOAuth2GranterDefinitions, type WhookOAuth2ClientId } from '../services/oAuth2Granters.js';
|
|
3
3
|
import { type LogService } from 'common-services';
|
|
4
4
|
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
5
|
+
import { scopeSchema } from '../libs/schemas.js';
|
|
6
|
+
import { codeChallengeMethodSchema, codeChallengeSchema } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
7
|
+
export { scopeSchema, codeChallengeMethodSchema, codeChallengeSchema };
|
|
5
8
|
export declare const definition: {
|
|
6
9
|
readonly method: "post";
|
|
7
10
|
readonly path: "/oauth2/acknowledge";
|
|
@@ -31,16 +34,13 @@ export declare const definition: {
|
|
|
31
34
|
readonly pattern: "^https?://";
|
|
32
35
|
readonly format: "uri";
|
|
33
36
|
};
|
|
34
|
-
readonly scope:
|
|
35
|
-
readonly type: "string";
|
|
36
|
-
readonly description: "See https://tools.ietf.org/html/rfc6749#section-3.3";
|
|
37
|
-
};
|
|
37
|
+
readonly scope: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
38
38
|
readonly state: {
|
|
39
39
|
readonly type: "string";
|
|
40
40
|
};
|
|
41
41
|
readonly acknowledged: {
|
|
42
42
|
readonly type: "boolean";
|
|
43
|
-
readonly description: "
|
|
43
|
+
readonly description: "Whether the user acknowledged the delegation or not.";
|
|
44
44
|
};
|
|
45
45
|
readonly codeChallenge: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
46
46
|
readonly codeChallengeMethod: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
@@ -80,15 +80,16 @@ export declare const definition: {
|
|
|
80
80
|
};
|
|
81
81
|
export interface HandlerDependencies {
|
|
82
82
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
OAUTH2: WhookOAuth2Options;
|
|
84
|
+
oAuth2Granters: WhookOAuth2GranterService<WhookOAuth2GranterDefinitions>[];
|
|
85
|
+
readClientGrants: WhookOAuth2ReadClientGrantsService;
|
|
85
86
|
log: LogService;
|
|
86
87
|
}
|
|
87
88
|
interface HandlerParameters {
|
|
88
89
|
authenticationData: WhookAuthenticationData;
|
|
89
90
|
body: {
|
|
90
91
|
responseType: string;
|
|
91
|
-
clientId:
|
|
92
|
+
clientId: WhookOAuth2ClientId;
|
|
92
93
|
redirectURI: string;
|
|
93
94
|
scope: string;
|
|
94
95
|
state: string;
|
|
@@ -98,7 +99,7 @@ interface HandlerParameters {
|
|
|
98
99
|
}
|
|
99
100
|
declare const _default: (dependencies: HandlerDependencies) => (parameters: HandlerParameters) => ReturnType<typeof initPostOAuth2Acknowledge>;
|
|
100
101
|
export default _default;
|
|
101
|
-
declare function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, oAuth2Granters,
|
|
102
|
+
declare function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, OAUTH2, oAuth2Granters, readClientGrants, log, }: HandlerDependencies): Promise<({ authenticationData: userAuthenticationData, body: { responseType, clientId, redirectURI: demandedRedirectURI, scope: demandedScope, state, acknowledged, ...additionalProperties }, }: HandlerParameters) => Promise<{
|
|
102
103
|
status: number;
|
|
103
104
|
headers: {
|
|
104
105
|
location: string;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { autoService, location } from 'knifecycle';
|
|
2
2
|
import { printStackTrace, YError } from 'yerror';
|
|
3
|
-
import { codeChallengeMethodSchema, codeChallengeSchema, setURLError, } from './getOAuth2Authorize.js';
|
|
4
3
|
import { refersTo, } from '@whook/whook';
|
|
4
|
+
import { filterScopes, parseOAuth2Scope, stringifyScopes, } from '../libs/scopes.js';
|
|
5
|
+
import { scopeSchema } from '../libs/schemas.js';
|
|
6
|
+
import { codeChallengeMethodSchema, codeChallengeSchema, } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
7
|
+
import { addParamsToURL, buildParamsFromError } from '../libs/redirectURI.js';
|
|
8
|
+
import { snakeCase } from '../libs/utils.js';
|
|
9
|
+
export { scopeSchema, codeChallengeMethodSchema, codeChallengeSchema };
|
|
5
10
|
/* Architecture Note #2: OAuth2 acknowledge
|
|
11
|
+
|
|
6
12
|
This endpoint is to be used by the authentication SSR frontend
|
|
7
13
|
to acknowledge that the user accepted the client request in it.
|
|
8
14
|
*/
|
|
@@ -43,16 +49,13 @@ export const definition = {
|
|
|
43
49
|
pattern: '^https?://',
|
|
44
50
|
format: 'uri',
|
|
45
51
|
},
|
|
46
|
-
scope:
|
|
47
|
-
type: 'string',
|
|
48
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
|
|
49
|
-
},
|
|
52
|
+
scope: refersTo(scopeSchema),
|
|
50
53
|
state: {
|
|
51
54
|
type: 'string',
|
|
52
55
|
},
|
|
53
56
|
acknowledged: {
|
|
54
57
|
type: 'boolean',
|
|
55
|
-
description: '
|
|
58
|
+
description: 'Whether the user acknowledged the delegation or not.',
|
|
56
59
|
},
|
|
57
60
|
codeChallenge: refersTo(codeChallengeSchema),
|
|
58
61
|
codeChallengeMethod: refersTo(codeChallengeMethodSchema),
|
|
@@ -91,44 +94,53 @@ export const definition = {
|
|
|
91
94
|
},
|
|
92
95
|
};
|
|
93
96
|
export default location(autoService(initPostOAuth2Acknowledge), import.meta.url);
|
|
94
|
-
async function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, oAuth2Granters,
|
|
95
|
-
return async ({ authenticationData:
|
|
96
|
-
if (!
|
|
97
|
+
async function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, OAUTH2, oAuth2Granters, readClientGrants, log, }) {
|
|
98
|
+
return async ({ authenticationData: userAuthenticationData, body: { responseType, clientId, redirectURI: demandedRedirectURI, scope: demandedScope, state, acknowledged = false, ...additionalProperties }, }) => {
|
|
99
|
+
if (!userAuthenticationData) {
|
|
100
|
+
throw new YError('E_UNAUTHORIZED');
|
|
101
|
+
}
|
|
102
|
+
const acknowledgeClientGrants = await readClientGrants(userAuthenticationData.clientId);
|
|
103
|
+
if (!acknowledgeClientGrants.canAcknowledge) {
|
|
97
104
|
throw new YError('E_UNAUTHORIZED');
|
|
98
105
|
}
|
|
99
|
-
// Here we check the applicationId has the right to authenticate a user
|
|
100
|
-
// with the special type 'root'
|
|
101
|
-
await checkApplication({
|
|
102
|
-
applicationId: baseAuthenticationData.applicationId,
|
|
103
|
-
type: 'root',
|
|
104
|
-
scope: '',
|
|
105
|
-
});
|
|
106
106
|
let url;
|
|
107
107
|
try {
|
|
108
108
|
if (!acknowledged) {
|
|
109
|
-
throw new YError('
|
|
109
|
+
throw new YError('E_OAUTH2_ACCESS_DENIED', [clientId]);
|
|
110
110
|
}
|
|
111
|
-
const granter = oAuth2Granters.find((granter) => granter.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
throw new YError('E_UNKNOWN_ACKNOWLEDGER_TYPE', [responseType]);
|
|
111
|
+
const granter = oAuth2Granters.find((granter) => granter.responseType === responseType);
|
|
112
|
+
if (!granter?.acknowledge) {
|
|
113
|
+
throw new YError('E_OAUTH2_UNKNOWN_ACKNOWLEDGER_TYPE', [responseType]);
|
|
115
114
|
}
|
|
116
|
-
const
|
|
115
|
+
const demandedScopes = filterScopes(parseOAuth2Scope(demandedScope), OAUTH2.allowedScopes, !!OAUTH2.strictScopesChecks);
|
|
116
|
+
const { acknowledgedAuthenticationData, acknowledgedData, acknowledgedRedirectURI, } = await granter.acknowledge(userAuthenticationData, {
|
|
117
117
|
clientId,
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
demandedRedirectURI,
|
|
119
|
+
demandedScopes,
|
|
120
120
|
}, additionalProperties);
|
|
121
|
-
url = new URL(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
url = new URL(acknowledgedRedirectURI);
|
|
122
|
+
const paramsHash = {
|
|
123
|
+
client_id: acknowledgedAuthenticationData.clientId,
|
|
124
|
+
scope: stringifyScopes(acknowledgedAuthenticationData.scopes),
|
|
125
|
+
state: state,
|
|
126
|
+
};
|
|
127
|
+
Object.keys(acknowledgedData).forEach((key) => {
|
|
128
|
+
if (typeof acknowledgedData[key] === 'number') {
|
|
129
|
+
paramsHash[snakeCase(key)] = acknowledgedData[key].toString(10);
|
|
130
|
+
}
|
|
131
|
+
else if (typeof acknowledgedData[key] === 'string') {
|
|
132
|
+
paramsHash[snakeCase(key)] = acknowledgedData[key];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
addParamsToURL(url, paramsHash, responseType === 'token' ? 'fragment' : 'query');
|
|
126
136
|
}
|
|
127
137
|
catch (err) {
|
|
128
138
|
log('debug', '👫 - OAuth2 acknowledge error', err.code);
|
|
129
139
|
log('debug-stack', printStackTrace(err));
|
|
130
|
-
url = new URL(
|
|
131
|
-
|
|
140
|
+
url = new URL(demandedRedirectURI);
|
|
141
|
+
const paramsHash = buildParamsFromError(err, ERRORS_DESCRIPTORS[err.code] ||
|
|
142
|
+
ERRORS_DESCRIPTORS.E_OAUTH2_UNEXPECTED_ERROR);
|
|
143
|
+
addParamsToURL(url, paramsHash, responseType === 'token' ? 'fragment' : 'query');
|
|
132
144
|
}
|
|
133
145
|
return {
|
|
134
146
|
status: 201,
|
|
@@ -138,10 +150,4 @@ async function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, oAuth2Granters, c
|
|
|
138
150
|
};
|
|
139
151
|
};
|
|
140
152
|
}
|
|
141
|
-
function snakeCase(s) {
|
|
142
|
-
return s
|
|
143
|
-
.split(/(?=(?<![A-Z])[A-Z])|[^a-zA-Z]+/)
|
|
144
|
-
.map((s) => s.toLowerCase())
|
|
145
|
-
.join('_');
|
|
146
|
-
}
|
|
147
153
|
//# sourceMappingURL=postOAuth2Acknowledge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postOAuth2Acknowledge.js","sourceRoot":"","sources":["../../src/routes/postOAuth2Acknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.js","sourceRoot":"","sources":["../../src/routes/postOAuth2Acknowledge.ts"],"names":[],"mappings":"AAA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