@whook/oauth2 9.0.0 → 10.0.1
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 +90 -68
- package/dist/handlers/getOAuth2Authorize.d.ts +4 -4
- 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 +1 -1
- package/dist/handlers/postAuthLogin.js +83 -121
- 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 +1 -1
- package/dist/handlers/postAuthRefresh.js +93 -132
- 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 +5 -5
- 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 +1 -1
- 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 -619
- 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 -66
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- 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 +48 -89
- 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 +2 -2
- package/src/handlers/postAuthLogin.test.ts +9 -5
- package/src/handlers/postAuthLogin.ts +4 -4
- 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 +4 -4
- package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
- package/src/handlers/postOAuth2Acknowledge.ts +18 -8
- package/src/handlers/postOAuth2Token.test.ts +77 -17
- package/src/handlers/postOAuth2Token.ts +3 -3
- package/src/index.test.ts +110 -65
- 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 +3 -3
- package/src/services/oAuth2CodeGranter.test.ts +27 -4
- package/src/services/oAuth2CodeGranter.ts +2 -2
- package/src/services/oAuth2PasswordGranter.ts +2 -2
- package/src/services/oAuth2RefreshTokenGranter.ts +2 -2
- package/src/services/oAuth2TokenGranter.ts +1 -1
- 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 -109
- 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 -122
- 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 -747
- 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 -83
- 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,"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,oBAA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,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK;YACjD,yCAAyC,EACvC,WAAW,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK;YACnD,oCAAoC,EAClC,YAAY,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK;YAC9C,wCAAwC,EACtC,YAAY,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK;SACnD,CAAC,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { WhookAPIHandlerDefinition } from '@whook/whook';
|
|
2
|
-
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
5
|
declare const _default: import("knifecycle").ServiceInitializer<AuthHandlersConfig<BaseAuthenticationData<string, string>> & {
|
|
@@ -1,126 +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
|
-
// TODO: Allow string[] in YHTTPError
|
|
121
|
-
'Set-Cookie': authCookies.build()
|
|
122
|
-
};
|
|
123
|
-
throw newErr;
|
|
124
|
-
}
|
|
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
|
+
}
|
|
125
87
|
}
|
|
126
88
|
//# sourceMappingURL=postAuthLogin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postAuthLogin.js","
|
|
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,MAA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