@whook/oauth2 8.5.1 → 10.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 +106 -70
- package/dist/handlers/getOAuth2Authorize.d.ts +8 -6
- package/dist/handlers/getOAuth2Authorize.js +122 -165
- package/dist/handlers/getOAuth2Authorize.js.map +1 -1
- package/dist/handlers/getOAuth2Authorize.test.js +117 -103
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
- package/dist/handlers/postAuthLogin.d.ts +3 -3
- package/dist/handlers/postAuthLogin.js +83 -120
- package/dist/handlers/postAuthLogin.js.map +1 -1
- package/dist/handlers/postAuthLogin.test.js +42 -44
- package/dist/handlers/postAuthLogin.test.js.map +1 -1
- package/dist/handlers/postAuthLogout.d.ts +1 -1
- package/dist/handlers/postAuthLogout.js +26 -42
- package/dist/handlers/postAuthLogout.js.map +1 -1
- package/dist/handlers/postAuthLogout.test.js +19 -21
- package/dist/handlers/postAuthLogout.test.js.map +1 -1
- package/dist/handlers/postAuthRefresh.d.ts +4 -4
- package/dist/handlers/postAuthRefresh.js +93 -131
- package/dist/handlers/postAuthRefresh.js.map +1 -1
- package/dist/handlers/postAuthRefresh.test.js +47 -49
- package/dist/handlers/postAuthRefresh.test.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.d.ts +11 -8
- package/dist/handlers/postOAuth2Acknowledge.js +119 -151
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.test.js +139 -125
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/handlers/postOAuth2Token.d.ts +4 -4
- package/dist/handlers/postOAuth2Token.js +200 -232
- package/dist/handlers/postOAuth2Token.js.map +1 -1
- package/dist/handlers/postOAuth2Token.test.js +156 -153
- package/dist/handlers/postOAuth2Token.test.js.map +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +14 -229
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +697 -620
- package/dist/index.test.js.map +1 -1
- package/dist/services/authCookies.d.ts +8 -4
- package/dist/services/authCookies.js +40 -71
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js +57 -62
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +2 -2
- package/dist/services/oAuth2ClientCredentialsGranter.js +34 -52
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.d.ts +1 -1
- package/dist/services/oAuth2CodeGranter.js +66 -109
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +65 -64
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +22 -19
- package/dist/services/oAuth2Granters.js +131 -138
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +1 -1
- package/dist/services/oAuth2PasswordGranter.js +27 -52
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.js +34 -58
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.d.ts +1 -1
- package/dist/services/oAuth2TokenGranter.js +50 -86
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/package.json +54 -96
- package/src/__snapshots__/index.test.ts.snap +23 -22
- package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +1 -1
- package/src/handlers/getOAuth2Authorize.test.ts +49 -13
- package/src/handlers/getOAuth2Authorize.ts +17 -16
- package/src/handlers/postAuthLogin.test.ts +9 -5
- package/src/handlers/postAuthLogin.ts +8 -7
- package/src/handlers/postAuthLogout.test.ts +8 -4
- package/src/handlers/postAuthLogout.ts +2 -2
- package/src/handlers/postAuthRefresh.test.ts +10 -6
- package/src/handlers/postAuthRefresh.ts +8 -7
- package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
- package/src/handlers/postOAuth2Acknowledge.ts +48 -30
- package/src/handlers/postOAuth2Token.test.ts +79 -19
- package/src/handlers/postOAuth2Token.ts +7 -7
- package/src/index.test.ts +116 -72
- package/src/index.ts +21 -19
- package/src/services/authCookies.test.ts +2 -2
- package/src/services/authCookies.ts +10 -5
- package/src/services/oAuth2ClientCredentialsGranter.ts +28 -24
- package/src/services/oAuth2CodeGranter.test.ts +42 -18
- package/src/services/oAuth2CodeGranter.ts +68 -62
- package/src/services/oAuth2Granters.ts +59 -29
- package/src/services/oAuth2PasswordGranter.ts +25 -24
- package/src/services/oAuth2RefreshTokenGranter.ts +30 -26
- package/src/services/oAuth2TokenGranter.ts +45 -43
- package/dist/handlers/getOAuth2Authorize.mjs +0 -160
- package/dist/handlers/getOAuth2Authorize.mjs.map +0 -1
- package/dist/handlers/getOAuth2Authorize.test.mjs +0 -114
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +0 -1
- package/dist/handlers/postAuthLogin.mjs +0 -108
- package/dist/handlers/postAuthLogin.mjs.map +0 -1
- package/dist/handlers/postAuthLogin.test.mjs +0 -85
- package/dist/handlers/postAuthLogin.test.mjs.map +0 -1
- package/dist/handlers/postAuthLogout.mjs +0 -33
- package/dist/handlers/postAuthLogout.mjs.map +0 -1
- package/dist/handlers/postAuthLogout.test.mjs +0 -30
- package/dist/handlers/postAuthLogout.test.mjs.map +0 -1
- package/dist/handlers/postAuthRefresh.mjs +0 -121
- package/dist/handlers/postAuthRefresh.mjs.map +0 -1
- package/dist/handlers/postAuthRefresh.test.mjs +0 -94
- package/dist/handlers/postAuthRefresh.test.mjs.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.mjs +0 -150
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.test.mjs +0 -140
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +0 -1
- package/dist/handlers/postOAuth2Token.mjs +0 -231
- package/dist/handlers/postOAuth2Token.mjs.map +0 -1
- package/dist/handlers/postOAuth2Token.test.mjs +0 -160
- package/dist/handlers/postOAuth2Token.test.mjs.map +0 -1
- package/dist/index.mjs +0 -15
- package/dist/index.mjs.map +0 -1
- package/dist/index.test.mjs +0 -748
- package/dist/index.test.mjs.map +0 -1
- package/dist/services/authCookies.mjs +0 -58
- package/dist/services/authCookies.mjs.map +0 -1
- package/dist/services/authCookies.test.mjs +0 -77
- package/dist/services/authCookies.test.mjs.map +0 -1
- package/dist/services/oAuth2ClientCredentialsGranter.mjs +0 -41
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +0 -1
- package/dist/services/oAuth2CodeGranter.mjs +0 -98
- package/dist/services/oAuth2CodeGranter.mjs.map +0 -1
- package/dist/services/oAuth2CodeGranter.test.mjs +0 -81
- package/dist/services/oAuth2CodeGranter.test.mjs.map +0 -1
- package/dist/services/oAuth2Granters.mjs +0 -127
- package/dist/services/oAuth2Granters.mjs.map +0 -1
- package/dist/services/oAuth2PasswordGranter.mjs +0 -40
- package/dist/services/oAuth2PasswordGranter.mjs.map +0 -1
- package/dist/services/oAuth2RefreshTokenGranter.mjs +0 -47
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +0 -1
- package/dist/services/oAuth2TokenGranter.mjs +0 -78
- package/dist/services/oAuth2TokenGranter.mjs.map +0 -1
|
@@ -1,75 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _oAuth2Granters = require("../services/oAuth2Granters");
|
|
8
|
-
|
|
9
|
-
var _yerror = _interopRequireDefault(require("yerror"));
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
import initGetOAuth2Authorize from './getOAuth2Authorize.js';
|
|
3
|
+
import { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';
|
|
4
|
+
import { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters.js';
|
|
5
|
+
import { YError } from 'yerror';
|
|
13
6
|
describe('getOAuth2Authorize', () => {
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
ERRORS_DESCRIPTORS,
|
|
62
|
-
oAuth2Granters,
|
|
63
|
-
log
|
|
64
|
-
});
|
|
65
|
-
const response = await getOAuth2Authorize({
|
|
66
|
-
response_type: 'code',
|
|
67
|
-
client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
68
|
-
redirect_uri: 'https://www.example.com',
|
|
69
|
-
scope: 'user',
|
|
70
|
-
state: 'bancal'
|
|
7
|
+
const OAUTH2 = {
|
|
8
|
+
authenticateURL: 'https://auth.example.com/sign_in',
|
|
9
|
+
};
|
|
10
|
+
const ERRORS_DESCRIPTORS = {
|
|
11
|
+
...DEFAULT_ERRORS_DESCRIPTORS,
|
|
12
|
+
...OAUTH2_ERRORS_DESCRIPTORS,
|
|
13
|
+
};
|
|
14
|
+
const log = jest.fn();
|
|
15
|
+
const codeGranter = {
|
|
16
|
+
type: 'code',
|
|
17
|
+
authorizer: {
|
|
18
|
+
responseType: 'code',
|
|
19
|
+
authorize: jest.fn(),
|
|
20
|
+
},
|
|
21
|
+
acknowledger: {
|
|
22
|
+
acknowledgmentType: 'code',
|
|
23
|
+
acknowledge: jest.fn(),
|
|
24
|
+
},
|
|
25
|
+
authenticator: {
|
|
26
|
+
grantType: 'authorization_code',
|
|
27
|
+
authenticate: jest.fn(),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const tokenGranter = {
|
|
31
|
+
type: 'token',
|
|
32
|
+
authorizer: {
|
|
33
|
+
responseType: 'token',
|
|
34
|
+
authorize: jest.fn(),
|
|
35
|
+
},
|
|
36
|
+
acknowledger: {
|
|
37
|
+
acknowledgmentType: 'token',
|
|
38
|
+
acknowledge: jest.fn(),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const oAuth2Granters = [
|
|
42
|
+
codeGranter,
|
|
43
|
+
tokenGranter,
|
|
44
|
+
];
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
log.mockReset();
|
|
47
|
+
[
|
|
48
|
+
codeGranter.authorizer.authorize,
|
|
49
|
+
codeGranter.acknowledger.acknowledge,
|
|
50
|
+
codeGranter.authenticator.authenticate,
|
|
51
|
+
tokenGranter.authorizer.authorize,
|
|
52
|
+
tokenGranter.acknowledger.acknowledge,
|
|
53
|
+
].forEach((mock) => mock.mockReset());
|
|
71
54
|
});
|
|
72
|
-
|
|
55
|
+
test('should redirect', async () => {
|
|
56
|
+
[
|
|
57
|
+
codeGranter.acknowledger.acknowledge,
|
|
58
|
+
codeGranter.authenticator.authenticate,
|
|
59
|
+
tokenGranter.authorizer.authorize,
|
|
60
|
+
tokenGranter.acknowledger.acknowledge,
|
|
61
|
+
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
62
|
+
codeGranter.authorizer.authorize.mockResolvedValueOnce({
|
|
63
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
64
|
+
redirectURI: 'http://lol',
|
|
65
|
+
scope: 'user',
|
|
66
|
+
});
|
|
67
|
+
const getOAuth2Authorize = await initGetOAuth2Authorize({
|
|
68
|
+
OAUTH2,
|
|
69
|
+
ERRORS_DESCRIPTORS,
|
|
70
|
+
oAuth2Granters,
|
|
71
|
+
log,
|
|
72
|
+
});
|
|
73
|
+
const response = await getOAuth2Authorize({
|
|
74
|
+
response_type: 'code',
|
|
75
|
+
client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
76
|
+
redirect_uri: 'https://www.example.com',
|
|
77
|
+
scope: 'user',
|
|
78
|
+
state: 'bancal',
|
|
79
|
+
});
|
|
80
|
+
expect(response).toMatchInlineSnapshot(`
|
|
73
81
|
Object {
|
|
74
82
|
"headers": Object {
|
|
75
83
|
"location": "https://auth.example.com/sign_in?type=code&redirect_uri=http%3A%2F%2Flol&scope=user&client_id=abbacaca-abba-caca-abba-cacaabbacaca&state=bancal",
|
|
@@ -77,31 +85,37 @@ describe('getOAuth2Authorize', () => {
|
|
|
77
85
|
"status": 302,
|
|
78
86
|
}
|
|
79
87
|
`);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
});
|
|
89
|
-
test('should redirect with an error when some', async () => {
|
|
90
|
-
[codeGranter.authorizer.authorize, codeGranter.acknowledger.acknowledge, codeGranter.authenticator.authenticate, tokenGranter.authorizer.authorize, tokenGranter.acknowledger.acknowledge].forEach(mock => mock.mockRejectedValueOnce(new _yerror.default('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
91
|
-
const getOAuth2Authorize = await (0, _getOAuth2Authorize.default)({
|
|
92
|
-
OAUTH2,
|
|
93
|
-
ERRORS_DESCRIPTORS,
|
|
94
|
-
oAuth2Granters,
|
|
95
|
-
log
|
|
88
|
+
expect({
|
|
89
|
+
logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),
|
|
90
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorizer.authorize.mock.calls,
|
|
91
|
+
codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledger.acknowledge.mock.calls,
|
|
92
|
+
codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticator.authenticate.mock.calls,
|
|
93
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorizer.authorize.mock.calls,
|
|
94
|
+
tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledger.acknowledge.mock.calls,
|
|
95
|
+
}).toMatchSnapshot();
|
|
96
96
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
test('should redirect with an error when some', async () => {
|
|
98
|
+
[
|
|
99
|
+
codeGranter.authorizer.authorize,
|
|
100
|
+
codeGranter.acknowledger.acknowledge,
|
|
101
|
+
codeGranter.authenticator.authenticate,
|
|
102
|
+
tokenGranter.authorizer.authorize,
|
|
103
|
+
tokenGranter.acknowledger.acknowledge,
|
|
104
|
+
].forEach((mock) => mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')));
|
|
105
|
+
const getOAuth2Authorize = await initGetOAuth2Authorize({
|
|
106
|
+
OAUTH2,
|
|
107
|
+
ERRORS_DESCRIPTORS,
|
|
108
|
+
oAuth2Granters,
|
|
109
|
+
log,
|
|
110
|
+
});
|
|
111
|
+
const response = await getOAuth2Authorize({
|
|
112
|
+
response_type: 'yolo',
|
|
113
|
+
client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
114
|
+
redirect_uri: 'https://www.example.com',
|
|
115
|
+
scope: 'user',
|
|
116
|
+
state: 'bancal',
|
|
117
|
+
});
|
|
118
|
+
expect(response).toMatchInlineSnapshot(`
|
|
105
119
|
Object {
|
|
106
120
|
"headers": Object {
|
|
107
121
|
"location": "https://auth.example.com/sign_in?redirect_uri=https%3A%2F%2Fwww.example.com&error=unsupported_response_type&error_decription=The+type+%22yolo%22+is+not+supported.&state=bancal",
|
|
@@ -109,14 +123,14 @@ describe('getOAuth2Authorize', () => {
|
|
|
109
123
|
"status": 302,
|
|
110
124
|
}
|
|
111
125
|
`);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
expect({
|
|
127
|
+
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),
|
|
128
|
+
codeGranterAuthorizerAuthorizeCalls: codeGranter.authorizer.authorize.mock.calls,
|
|
129
|
+
codeGranterAcknowledgerAcknowledgeCalls: codeGranter.acknowledger.acknowledge.mock.calls,
|
|
130
|
+
codeGranterAuthenticatorAuthenticateCalls: codeGranter.authenticator.authenticate.mock.calls,
|
|
131
|
+
tokenGranterAuthorizerAuthorizeCalls: tokenGranter.authorizer.authorize.mock.calls,
|
|
132
|
+
tokenGranterAcknowledgerAcknowledgeCalls: tokenGranter.acknowledger.acknowledge.mock.calls,
|
|
133
|
+
}).toMatchSnapshot();
|
|
134
|
+
});
|
|
121
135
|
});
|
|
122
136
|
//# sourceMappingURL=getOAuth2Authorize.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/handlers/getOAuth2Authorize.test.ts"],"names":["describe","OAUTH2","authenticateURL","ERRORS_DESCRIPTORS","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","log","jest","fn","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","YError","mockResolvedValueOnce","applicationId","redirectURI","scope","getOAuth2Authorize","response","response_type","client_id","redirect_uri","state","expect","toMatchInlineSnapshot","logCalls","calls","filter","args","endsWith","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;;;AAGAA,QAAQ,CAAC,oBAAD,EAAuB,MAAM;AACnC,QAAMC,MAAqB,GAAG;AAC5BC,IAAAA,eAAe,EAAE;AADW,GAA9B;AAGA,QAAMC,kBAAkB,GAAG,EACzB,GAAGC,iCADsB;AAEzB,OAAGC;AAFsB,GAA3B;AAIA,QAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;AACA,QAAMC,WAAW,GAAG;AAClBC,IAAAA,IAAI,EAAE,MADY;AAElBC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,YAAY,EAAE,MAAhB;AAAwBC,MAAAA,SAAS,EAAEN,IAAI,CAACC,EAAL;AAAnC,KAFM;AAGlBM,IAAAA,YAAY,EAAE;AAAEC,MAAAA,kBAAkB,EAAE,MAAtB;AAA8BC,MAAAA,WAAW,EAAET,IAAI,CAACC,EAAL;AAA3C,KAHI;AAIlBS,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,oBADE;AAEbC,MAAAA,YAAY,EAAEZ,IAAI,CAACC,EAAL;AAFD;AAJG,GAApB;AASA,QAAMY,YAAY,GAAG;AACnBV,IAAAA,IAAI,EAAE,OADa;AAEnBC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,YAAY,EAAE,OAAhB;AAAyBC,MAAAA,SAAS,EAAEN,IAAI,CAACC,EAAL;AAApC,KAFO;AAGnBM,IAAAA,YAAY,EAAE;AAAEC,MAAAA,kBAAkB,EAAE,OAAtB;AAA+BC,MAAAA,WAAW,EAAET,IAAI,CAACC,EAAL;AAA5C;AAHK,GAArB;AAKA,QAAMa,cAAsC,GAAG,CAACZ,WAA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":["import initGetOAuth2Authorize from './getOAuth2Authorize';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport YError from 'yerror';\nimport type { OAuth2Options, OAuth2GranterService } from '..';\n\ndescribe('getOAuth2Authorize', () => {\n const OAUTH2: OAuth2Options = {\n authenticateURL: 'https://auth.example.com/sign_in',\n };\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const log = jest.fn();\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n });\n\n const getOAuth2Authorize = await initGetOAuth2Authorize({\n OAUTH2,\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n log,\n });\n const response = await getOAuth2Authorize({\n response_type: 'code',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n });\n\n expect(response).toMatchInlineSnapshot(`\n Object {\n \"headers\": Object {\n \"location\": \"https://auth.example.com/sign_in?type=code&redirect_uri=http%3A%2F%2Flol&scope=user&client_id=abbacaca-abba-caca-abba-cacaabbacaca&state=bancal\",\n },\n \"status\": 302,\n }\n `);\n expect({\n logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect with an error when some', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const getOAuth2Authorize = await initGetOAuth2Authorize({\n OAUTH2,\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n log,\n });\n const response = await getOAuth2Authorize({\n response_type: 'yolo',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n });\n\n expect(response).toMatchInlineSnapshot(`\n Object {\n \"headers\": Object {\n \"location\": \"https://auth.example.com/sign_in?redirect_uri=https%3A%2F%2Fwww.example.com&error=unsupported_response_type&error_decription=The+type+%22yolo%22+is+not+supported.&state=bancal\",\n },\n \"status\": 302,\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"file":"getOAuth2Authorize.test.js"}
|
|
1
|
+
{"version":3,"file":"getOAuth2Authorize.test.js","sourceRoot":"","sources":["../../src/handlers/getOAuth2Authorize.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,sBAAsB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMhC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,MAAM,MAAM,GAAkB;QAC5B,eAAe,EAAE,kCAAkC;KACpD,CAAC;IACF,MAAM,kBAAkB,GAAG;QACzB,GAAG,0BAA0B;QAC7B,GAAG,yBAAyB;KAC7B,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,EAAc,CAAC;IAClC,MAAM,WAAW,GAAG;QAClB,IAAI,EAAE,MAAM;QACZ,UAAU,EAAE;YACV,YAAY,EAAE,MAAM;YACpB,SAAS,EACP,IAAI,CAAC,EAAE,EAEJ;SACN;QACD,YAAY,EAAE;YACZ,kBAAkB,EAAE,MAAM;YAC1B,WAAW,EACT,IAAI,CAAC,EAAE,EAE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|
-
import type { AuthCookiesService, AuthHandlersConfig } from '../services/authCookies';
|
|
2
|
+
import type { AuthCookiesService, AuthHandlersConfig } from '../services/authCookies.js';
|
|
3
3
|
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
4
|
export declare const definition: WhookAPIHandlerDefinition;
|
|
5
|
-
declare const _default: <
|
|
5
|
+
declare const _default: import("knifecycle").ServiceInitializer<AuthHandlersConfig<BaseAuthenticationData<string, string>> & {
|
|
6
6
|
authCookies: Pick<AuthCookiesService, "build">;
|
|
7
7
|
postOAuth2Token: (parameters: {
|
|
8
8
|
body: {
|
|
@@ -23,7 +23,7 @@ declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<stri
|
|
|
23
23
|
refresh_token_expiration_date: string;
|
|
24
24
|
};
|
|
25
25
|
}>;
|
|
26
|
-
}
|
|
26
|
+
}, (parameters: {
|
|
27
27
|
body: {
|
|
28
28
|
username: string;
|
|
29
29
|
password: string;
|
|
@@ -1,125 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
content: {
|
|
30
|
-
'application/json': {
|
|
31
|
-
schema: {
|
|
32
|
-
type: 'object',
|
|
33
|
-
required: ['username', 'password'],
|
|
34
|
-
properties: {
|
|
35
|
-
username: {
|
|
36
|
-
type: 'string'
|
|
37
|
-
},
|
|
38
|
-
password: {
|
|
39
|
-
type: 'string'
|
|
40
|
-
},
|
|
41
|
-
scope: {
|
|
42
|
-
type: 'string'
|
|
43
|
-
},
|
|
44
|
-
remember: {
|
|
45
|
-
type: 'boolean'
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
responses: {
|
|
53
|
-
200: {
|
|
54
|
-
description: 'Successfuly logged in.',
|
|
55
|
-
content: {
|
|
56
|
-
'application/json': {
|
|
57
|
-
schema: {
|
|
58
|
-
type: 'object',
|
|
59
|
-
properties: {
|
|
60
|
-
access_token: {
|
|
61
|
-
type: 'string'
|
|
1
|
+
import { autoHandler } from 'knifecycle';
|
|
2
|
+
import { YHTTPError } from 'yhttperror';
|
|
3
|
+
import { AUTH_API_PREFIX } from '../services/authCookies.js';
|
|
4
|
+
export const definition = {
|
|
5
|
+
method: 'post',
|
|
6
|
+
path: `${AUTH_API_PREFIX}/login`,
|
|
7
|
+
operation: {
|
|
8
|
+
operationId: 'postAuthLogin',
|
|
9
|
+
summary: 'Logs a user in',
|
|
10
|
+
tags: ['auth'],
|
|
11
|
+
'x-whook': {
|
|
12
|
+
disabled: true,
|
|
13
|
+
},
|
|
14
|
+
parameters: [],
|
|
15
|
+
requestBody: {
|
|
16
|
+
required: true,
|
|
17
|
+
content: {
|
|
18
|
+
'application/json': {
|
|
19
|
+
schema: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
required: ['username', 'password'],
|
|
22
|
+
properties: {
|
|
23
|
+
username: { type: 'string' },
|
|
24
|
+
password: { type: 'string' },
|
|
25
|
+
scope: { type: 'string' },
|
|
26
|
+
remember: { type: 'boolean' },
|
|
27
|
+
},
|
|
28
|
+
},
|
|
62
29
|
},
|
|
63
|
-
|
|
64
|
-
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
responses: {
|
|
33
|
+
200: {
|
|
34
|
+
description: 'Successfuly logged in.',
|
|
35
|
+
content: {
|
|
36
|
+
'application/json': {
|
|
37
|
+
schema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
access_token: { type: 'string' },
|
|
41
|
+
expiration_date: { type: 'string' },
|
|
42
|
+
expires_in: { type: 'string' },
|
|
43
|
+
token_type: { type: 'string' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
65
47
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
token_type: {
|
|
70
|
-
type: 'string'
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
79
51
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
} catch (err) {
|
|
117
|
-
const newErr = _yhttperror.default.wrap(err);
|
|
118
|
-
|
|
119
|
-
newErr.headers = { ...(err.headers || {}),
|
|
120
|
-
'Set-Cookie': authCookies.build()
|
|
121
|
-
};
|
|
122
|
-
throw newErr;
|
|
123
|
-
}
|
|
52
|
+
export default autoHandler(postAuthLogin);
|
|
53
|
+
async function postAuthLogin({ ROOT_AUTHENTICATION_DATA, authCookies, postOAuth2Token, }, { body, }) {
|
|
54
|
+
try {
|
|
55
|
+
const response = await postOAuth2Token({
|
|
56
|
+
body: {
|
|
57
|
+
grant_type: 'password',
|
|
58
|
+
scope: body.scope,
|
|
59
|
+
username: body.username,
|
|
60
|
+
password: body.password,
|
|
61
|
+
},
|
|
62
|
+
authenticationData: ROOT_AUTHENTICATION_DATA,
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
...response,
|
|
66
|
+
headers: {
|
|
67
|
+
...(response.headers || {}),
|
|
68
|
+
'Set-Cookie': authCookies.build(response.status === 200 ? response.body : undefined, { session: !body.remember }),
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
access_token: response.body.access_token,
|
|
72
|
+
expiration_date: response.body.expiration_date,
|
|
73
|
+
expires_in: response.body.expires_in,
|
|
74
|
+
token_type: response.body.token_type,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const newErr = YHTTPError.wrap(err);
|
|
80
|
+
newErr.headers = {
|
|
81
|
+
...(err.headers || {}),
|
|
82
|
+
// TODO: Allow string[] in YHTTPError
|
|
83
|
+
'Set-Cookie': authCookies.build(),
|
|
84
|
+
};
|
|
85
|
+
throw newErr;
|
|
86
|
+
}
|
|
124
87
|
}
|
|
125
88
|
//# sourceMappingURL=postAuthLogin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/handlers/postAuthLogin.ts"],"names":[
|
|
1
|
+
{"version":3,"file":"postAuthLogin.js","sourceRoot":"","sources":["../../src/handlers/postAuthLogin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAS7D,MAAM,CAAC,MAAM,UAAU,GAA8B;IACnD,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,GAAG,eAAe,QAAQ;IAChC,SAAS,EAAE;QACT,WAAW,EAAE,eAAe;QAC5B,OAAO,EAAE,gBAAgB;QACzB,IAAI,EAAE,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AC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB;YACD,kBAAkB,EAAE,wBAAwB;SAC7C,CAAC,CAAC;QAEH,OAAO;YACL,GAAG,QAAQ;YACX,OAAO,EAAE;gBACP,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;gBAC3B,YAAY,EAAE,WAAW,CAAC,KAAK,CAC7B,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EACnD,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAC5B;aACF;YACD,IAAI,EAAE;gBACJ,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;gBACxC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,eAAe;gBAC9C,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;gBACpC,UAAU,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU;aACrC;SACF,CAAC;KACH;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,GAAY,CAAC,CAAC;QAE7C,MAAM,CAAC,OAAO,GAAG;YACf,GAAG,CAAE,GAAkB,CAAC,OAAO,IAAI,EAAE,CAAC;YACtC,qCAAqC;YACrC,YAAY,EAAE,WAAW,CAAC,KAAK,EAAuB;SACvD,CAAC;QAEF,MAAM,MAAM,CAAC;KACd;AACH,CAAC"}
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _postAuthLogin = _interopRequireDefault(require("./postAuthLogin"));
|
|
4
|
-
|
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
-
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
import initPostAuthLogin from './postAuthLogin.js';
|
|
7
3
|
describe('postAuthLogin', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
4
|
+
test('should work', async () => {
|
|
5
|
+
const authCookies = {
|
|
6
|
+
build: jest.fn(),
|
|
7
|
+
};
|
|
8
|
+
const postOAuth2Token = jest.fn();
|
|
9
|
+
const postAuthLogin = await initPostAuthLogin({
|
|
10
|
+
ROOT_AUTHENTICATION_DATA: {
|
|
11
|
+
scope: 'user',
|
|
12
|
+
applicationId: 'root_app_id',
|
|
13
|
+
},
|
|
14
|
+
authCookies,
|
|
15
|
+
postOAuth2Token,
|
|
16
|
+
});
|
|
17
|
+
authCookies.build.mockReturnValueOnce(['the_build_cookies']);
|
|
18
|
+
postOAuth2Token.mockResolvedValueOnce({
|
|
19
|
+
status: 200,
|
|
20
|
+
body: {
|
|
21
|
+
access_token: 'an_access_token',
|
|
22
|
+
expiration_date: '2020-02-02T20:22:02Z',
|
|
23
|
+
expires_in: 3600,
|
|
24
|
+
token_type: 'bearer',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const response = await postAuthLogin({
|
|
28
|
+
body: {
|
|
29
|
+
username: 'a_username',
|
|
30
|
+
password: 'a_password',
|
|
31
|
+
remember: false,
|
|
32
|
+
scope: 'user',
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
expect({
|
|
36
|
+
response,
|
|
37
|
+
authCookiesBuildCalls: authCookies.build.mock.calls,
|
|
38
|
+
postOAuth2TokenCalls: postOAuth2Token.mock.calls,
|
|
39
|
+
}).toMatchInlineSnapshot(`
|
|
44
40
|
Object {
|
|
45
41
|
"authCookiesBuildCalls": Array [
|
|
46
42
|
Array [
|
|
@@ -79,12 +75,14 @@ describe('postAuthLogin', () => {
|
|
|
79
75
|
"token_type": "bearer",
|
|
80
76
|
},
|
|
81
77
|
"headers": Object {
|
|
82
|
-
"Set-Cookie":
|
|
78
|
+
"Set-Cookie": Array [
|
|
79
|
+
"the_build_cookies",
|
|
80
|
+
],
|
|
83
81
|
},
|
|
84
82
|
"status": 200,
|
|
85
83
|
},
|
|
86
84
|
}
|
|
87
85
|
`);
|
|
88
|
-
|
|
86
|
+
});
|
|
89
87
|
});
|
|
90
88
|
//# sourceMappingURL=postAuthLogin.test.js.map
|