@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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postOAuth2Acknowledge.test.mjs","names":["initPostOAuth2Acknowledge","YError","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","describe","ERRORS_DESCRIPTORS","checkApplication","jest","fn","log","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","mockResolvedValueOnce","applicationId","redirectURI","scope","userId","postOAuth2Acknowledge","response","authenticationData","body","clientId","state","acknowledged","expect","toMatchInlineSnapshot","logCalls","calls","filter","endsWith","checkApplicationCalls","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"sources":["../../src/handlers/postOAuth2Acknowledge.test.ts"],"sourcesContent":["import initPostOAuth2Acknowledge from './postOAuth2Acknowledge';\nimport YError from 'yerror';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport type { OAuth2GranterService } from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\ndescribe('postOAuth2Acknowledge', () => {\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const checkApplication = jest.fn();\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 checkApplication.mockReset();\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.authorizer.authorize,\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.acknowledger.acknowledge.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n userId: 1,\n });\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'code',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&redirect_uri=http%3A%2F%2Flol&user_id=1\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\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 errors too', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n codeGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'yolo',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?error=unsupported_response_type&error_decription=Type+%22yolo%22+not+supported.\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\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"],"mappings":"AAAA,OAAOA,yBAAP,MAAsC,yBAAtC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,0BAAT,QAA2C,cAA3C;AACA,SAASC,yBAAT,QAA0C,4BAA1C;AAIAC,QAAQ,CAAC,uBAAD,EAA0B,MAAM;EACtC,MAAMC,kBAAkB,GAAG,EACzB,GAAGH,0BADsB;IAEzB,GAAGC;EAFsB,CAA3B;EAIA,MAAMG,gB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AAE,MAJH;QAKJO,KAAK,EAAE,QALH;QAMJC,YAAY,EAAE;MANV;IANqC,CAAD,CAA5C;IAeAC,MAAM,CAAC;MACLN;IADK,CAAD,CAAN,CAEGO,qBAFH,CAE0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAXI;IAYAD,MAAM,CAAC;MACLE,QAAQ,EAAElC,GAAG,CAACiB,IAAJ,CAASkB,KAAT,CAAeC,MAAf,CAAsB,CAAC,CAAClC,IAAD,CAAD,KAAY,CAACA,IAAI,CAACmC,QAAL,CAAc,OAAd,CAAnC,CADL;MAELC,qBAAqB,EAAEzC,gBAAgB,CAACoB,IAAjB,CAAsBkB,KAFxC;MAGLI,mCAAmC,EACjCtC,WAAW,CAACE,UAAZ,CAAuBE,SAAvB,CAAiCY,IAAjC,CAAsCkB,KAJnC;MAKLK,uCAAuC,EACrCvC,WAAW,CAACK,YAAZ,CAAyBE,WAAzB,CAAqCS,IAArC,CAA0CkB,KANvC;MAOLM,yCAAyC,EACvCxC,WAAW,CAACQ,aAAZ,CAA0BE,YAA1B,CAAuCM,IAAvC,CAA4CkB,KARzC;MASLO,oCAAoC,EAClC9B,YAAY,CAACT,UAAb,CAAwBE,SAAxB,CAAkCY,IAAlC,CAAuCkB,KAVpC;MAWLQ,wCAAwC,EACtC/B,YAAY,CAACN,YAAb,CAA0BE,WAA1B,CAAsCS,IAAtC,CAA2CkB;IAZxC,CAAD,CAAN,CAaGS,eAbH;EAcD,CA9DG,CAAJ;AA+DD,CAvKO,CAAR"}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { handler as _handler } from 'knifecycle';
|
|
2
|
-
import { camelCaseObjectProperties } from './getOAuth2Authorize';
|
|
3
|
-
import { noop } from '@whook/whook';
|
|
4
|
-
import YError from 'yerror';
|
|
5
|
-
import { refersTo } from '@whook/whook';
|
|
6
|
-
|
|
7
|
-
/* Architecture Note #2: OAuth2 acknowledge
|
|
8
|
-
This endpoint is to be used by the authentication server page
|
|
9
|
-
to acknowlege that the user accepted the client request.
|
|
10
|
-
*/
|
|
11
|
-
export const authorizationCodeTokenRequestBodySchema = {
|
|
12
|
-
name: 'AuthorizationCodeRequestBody',
|
|
13
|
-
schema: {
|
|
14
|
-
type: 'object',
|
|
15
|
-
description: 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',
|
|
16
|
-
required: ['grant_type'],
|
|
17
|
-
properties: {
|
|
18
|
-
grant_type: {
|
|
19
|
-
type: 'string',
|
|
20
|
-
enum: ['authorization_code']
|
|
21
|
-
},
|
|
22
|
-
code: {
|
|
23
|
-
type: 'string'
|
|
24
|
-
},
|
|
25
|
-
client_id: {
|
|
26
|
-
type: 'string'
|
|
27
|
-
},
|
|
28
|
-
redirect_uri: {
|
|
29
|
-
type: 'string',
|
|
30
|
-
pattern: '^https?://',
|
|
31
|
-
format: 'uri'
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export const passwordTokenRequestBodySchema = {
|
|
37
|
-
name: 'PasswordRequestBody',
|
|
38
|
-
schema: {
|
|
39
|
-
type: 'object',
|
|
40
|
-
description: 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',
|
|
41
|
-
required: ['grant_type', 'username', 'password'],
|
|
42
|
-
properties: {
|
|
43
|
-
grant_type: {
|
|
44
|
-
type: 'string',
|
|
45
|
-
enum: ['password']
|
|
46
|
-
},
|
|
47
|
-
username: {
|
|
48
|
-
type: 'string'
|
|
49
|
-
},
|
|
50
|
-
password: {
|
|
51
|
-
type: 'string'
|
|
52
|
-
},
|
|
53
|
-
scope: {
|
|
54
|
-
type: 'string',
|
|
55
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
export const clientCredentialsTokenRequestBodySchema = {
|
|
61
|
-
name: 'ClientCredentialsRequestBody',
|
|
62
|
-
schema: {
|
|
63
|
-
type: 'object',
|
|
64
|
-
description: 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
|
|
65
|
-
required: ['grant_type'],
|
|
66
|
-
properties: {
|
|
67
|
-
grant_type: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
enum: ['client_credentials']
|
|
70
|
-
},
|
|
71
|
-
scope: {
|
|
72
|
-
type: 'string',
|
|
73
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
export const refreshTokenRequestBodySchema = {
|
|
79
|
-
name: 'RefreshTokenRequestBody',
|
|
80
|
-
schema: {
|
|
81
|
-
type: 'object',
|
|
82
|
-
description: 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',
|
|
83
|
-
required: ['grant_type', 'refresh_token'],
|
|
84
|
-
properties: {
|
|
85
|
-
grant_type: {
|
|
86
|
-
type: 'string',
|
|
87
|
-
enum: ['refresh_token']
|
|
88
|
-
},
|
|
89
|
-
refresh_token: {
|
|
90
|
-
type: 'string'
|
|
91
|
-
},
|
|
92
|
-
scope: {
|
|
93
|
-
type: 'string',
|
|
94
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
export const tokenBodySchema = {
|
|
100
|
-
name: 'TokenRequestBody',
|
|
101
|
-
schema: {
|
|
102
|
-
oneOf: [refersTo(passwordTokenRequestBodySchema), refersTo(authorizationCodeTokenRequestBodySchema), refersTo(clientCredentialsTokenRequestBodySchema), refersTo(refreshTokenRequestBodySchema)]
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
export const definition = {
|
|
106
|
-
method: 'post',
|
|
107
|
-
path: '/oauth2/token',
|
|
108
|
-
operation: {
|
|
109
|
-
operationId: 'postOAuth2Token',
|
|
110
|
-
summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)
|
|
111
|
-
as defined per the OAuth2 RFC.`,
|
|
112
|
-
tags: ['oauth2'],
|
|
113
|
-
parameters: [],
|
|
114
|
-
requestBody: {
|
|
115
|
-
required: true,
|
|
116
|
-
content: {
|
|
117
|
-
'application/x-www-form-urlencoded': {
|
|
118
|
-
schema: refersTo(tokenBodySchema)
|
|
119
|
-
},
|
|
120
|
-
'application/json': {
|
|
121
|
-
schema: refersTo(tokenBodySchema)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
responses: {
|
|
126
|
-
'200': {
|
|
127
|
-
description: 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',
|
|
128
|
-
content: {
|
|
129
|
-
'application/json': {
|
|
130
|
-
schema: {
|
|
131
|
-
type: 'object',
|
|
132
|
-
required: ['access_token', 'token_type'],
|
|
133
|
-
properties: {
|
|
134
|
-
access_token: {
|
|
135
|
-
type: 'string'
|
|
136
|
-
},
|
|
137
|
-
token_type: {
|
|
138
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-7.1',
|
|
139
|
-
type: 'string',
|
|
140
|
-
enum: ['bearer', 'mac']
|
|
141
|
-
},
|
|
142
|
-
expires_in: {
|
|
143
|
-
description: 'The lifetime in seconds of the access token',
|
|
144
|
-
type: 'number'
|
|
145
|
-
},
|
|
146
|
-
refresh_token: {
|
|
147
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-6',
|
|
148
|
-
type: 'string'
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
'400': {
|
|
156
|
-
description: 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',
|
|
157
|
-
content: {
|
|
158
|
-
'application/json': {
|
|
159
|
-
schema: {
|
|
160
|
-
type: 'object',
|
|
161
|
-
required: ['error'],
|
|
162
|
-
properties: {
|
|
163
|
-
error: {
|
|
164
|
-
type: 'string',
|
|
165
|
-
enum: ['invalid_request', 'invalid_client', 'invalid_grant', 'unauthorized_client', 'unsupported_grant_type', 'invalid_scope']
|
|
166
|
-
},
|
|
167
|
-
error_description: {
|
|
168
|
-
type: 'string'
|
|
169
|
-
},
|
|
170
|
-
error_uri: {
|
|
171
|
-
type: 'string'
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
export default _handler(postOAuth2Token, "postOAuth2Token", ["oAuth2Granters", "oAuth2AccessToken", "oAuth2RefreshToken", "?time", "?log"]);
|
|
182
|
-
|
|
183
|
-
async function postOAuth2Token({
|
|
184
|
-
oAuth2Granters,
|
|
185
|
-
oAuth2AccessToken,
|
|
186
|
-
oAuth2RefreshToken,
|
|
187
|
-
time = Date.now.bind(Date),
|
|
188
|
-
log = noop
|
|
189
|
-
}, {
|
|
190
|
-
body: {
|
|
191
|
-
grant_type: grantType,
|
|
192
|
-
...grantParameters
|
|
193
|
-
},
|
|
194
|
-
authenticationData
|
|
195
|
-
}) {
|
|
196
|
-
try {
|
|
197
|
-
const granter = oAuth2Granters.find(granter => granter.authenticator && granter.authenticator.grantType === grantType);
|
|
198
|
-
|
|
199
|
-
if (!granter || !granter.authenticator) {
|
|
200
|
-
throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const newAuthenticationData = await granter.authenticator.authenticate(camelCaseObjectProperties(grantParameters), authenticationData);
|
|
204
|
-
const [{
|
|
205
|
-
token: accessToken,
|
|
206
|
-
expiresAt: accessTokenExpiresAt
|
|
207
|
-
}, {
|
|
208
|
-
token: refreshToken,
|
|
209
|
-
expiresAt: refreshTokenExpiresAt
|
|
210
|
-
}] = await Promise.all([oAuth2AccessToken.create(authenticationData, newAuthenticationData), oAuth2RefreshToken.create(authenticationData, newAuthenticationData)]);
|
|
211
|
-
const currentTime = time();
|
|
212
|
-
return {
|
|
213
|
-
status: 200,
|
|
214
|
-
headers: {},
|
|
215
|
-
body: {
|
|
216
|
-
access_token: accessToken,
|
|
217
|
-
token_type: 'bearer',
|
|
218
|
-
expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),
|
|
219
|
-
expiration_date: new Date(accessTokenExpiresAt).toISOString(),
|
|
220
|
-
refresh_token: refreshToken,
|
|
221
|
-
refresh_token_expires_in: Math.ceil((refreshTokenExpiresAt - currentTime) / 1000),
|
|
222
|
-
refresh_token_expiration_date: new Date(refreshTokenExpiresAt).toISOString()
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
} catch (err) {
|
|
226
|
-
log('debug', '👫 - OAuth2 token issuing error', err.code);
|
|
227
|
-
log('debug-stack', err.stack || 'no_stack_trace');
|
|
228
|
-
throw YError.cast(err, 'E_OAUTH2');
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
//# sourceMappingURL=postOAuth2Token.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postOAuth2Token.mjs","names":["autoHandler","camelCaseObjectProperties","noop","YError","refersTo","authorizationCodeTokenRequestBodySchema","name","schema","type","description","required","properties","grant_type","enum","code","client_id","redirect_uri","pattern","format","passwordTokenRequestBodySchema","username","password","scope","clientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","refresh_token","tokenBodySchema","oneOf","definition","method","path","operation","operationId","summary","tags","parameters","requestBody","content","responses","access_token","token_type","expires_in","error","error_description","error_uri","postOAuth2Token","oAuth2Granters","oAuth2AccessToken","oAuth2RefreshToken","time","Date","now","bind","log","body","grantType","grantParameters","authenticationData","granter","find","authenticator","newAuthenticationData","authenticate","token","accessToken","expiresAt","accessTokenExpiresAt","refreshToken","refreshTokenExpiresAt","Promise","all","create","currentTime","status","headers","Math","ceil","expiration_date","toISOString","refresh_token_expires_in","refresh_token_expiration_date","err","stack","cast"],"sources":["../../src/handlers/postOAuth2Token.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { camelCaseObjectProperties } from './getOAuth2Authorize';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService, TimeService } from 'common-services';\nimport type {\n WhookAPISchemaDefinition,\n WhookAPIHandlerDefinition,\n} from '@whook/whook';\nimport type {\n OAuth2GranterService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n} from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication server page\n to acknowlege that the user accepted the client request.\n*/\nexport const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'AuthorizationCodeRequestBody',\n schema: {\n type: 'object',\n description:\n 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['authorization_code'],\n },\n code: {\n type: 'string',\n },\n client_id: {\n type: 'string',\n },\n redirect_uri: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n };\n\nexport const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'PasswordRequestBody',\n schema: {\n type: 'object',\n description:\n 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',\n required: ['grant_type', 'username', 'password'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['password'],\n },\n username: {\n type: 'string',\n },\n password: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'ClientCredentialsRequestBody',\n schema: {\n type: 'object',\n description:\n 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['client_credentials'],\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n };\n\nexport const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'RefreshTokenRequestBody',\n schema: {\n type: 'object',\n description:\n 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',\n required: ['grant_type', 'refresh_token'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['refresh_token'],\n },\n refresh_token: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const tokenBodySchema: WhookAPISchemaDefinition = {\n name: 'TokenRequestBody',\n schema: {\n oneOf: [\n refersTo(passwordTokenRequestBodySchema),\n refersTo(authorizationCodeTokenRequestBodySchema),\n refersTo(clientCredentialsTokenRequestBodySchema),\n refersTo(refreshTokenRequestBodySchema),\n ],\n } as OpenAPIV3.SchemaObject,\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/token',\n operation: {\n operationId: 'postOAuth2Token',\n summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/x-www-form-urlencoded': {\n schema: refersTo(tokenBodySchema),\n },\n 'application/json': {\n schema: refersTo(tokenBodySchema),\n },\n },\n },\n responses: {\n '200': {\n description:\n 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['access_token', 'token_type'],\n properties: {\n access_token: { type: 'string' },\n token_type: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-7.1',\n type: 'string',\n enum: ['bearer', 'mac'],\n },\n expires_in: {\n description: 'The lifetime in seconds of the access token',\n type: 'number',\n },\n refresh_token: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-6',\n type: 'string',\n },\n },\n },\n },\n },\n },\n '400': {\n description:\n 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n enum: [\n 'invalid_request',\n 'invalid_client',\n 'invalid_grant',\n 'unauthorized_client',\n 'unsupported_grant_type',\n 'invalid_scope',\n ],\n },\n error_description: { type: 'string' },\n error_uri: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postOAuth2Token);\n\nasync function postOAuth2Token<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time = Date.now.bind(Date),\n log = noop,\n }: {\n oAuth2Granters: OAuth2GranterService[];\n oAuth2AccessToken: OAuth2AccessTokenService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log: LogService;\n time: TimeService;\n },\n {\n body: { grant_type: grantType, ...grantParameters },\n authenticationData,\n }: {\n body: {\n grant_type: string;\n [name: string]: unknown;\n };\n authenticationData: AUTHENTICATION_DATA;\n },\n) {\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authenticator && granter.authenticator.grantType === grantType,\n );\n\n if (!granter || !granter.authenticator) {\n throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);\n }\n\n const newAuthenticationData = await granter.authenticator.authenticate(\n camelCaseObjectProperties(grantParameters),\n authenticationData,\n );\n\n const [\n { token: accessToken, expiresAt: accessTokenExpiresAt },\n { token: refreshToken, expiresAt: refreshTokenExpiresAt },\n ] = await Promise.all([\n oAuth2AccessToken.create(authenticationData, newAuthenticationData),\n oAuth2RefreshToken.create(authenticationData, newAuthenticationData),\n ]);\n const currentTime = time();\n\n return {\n status: 200,\n headers: {},\n body: {\n access_token: accessToken,\n token_type: 'bearer',\n expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),\n expiration_date: new Date(accessTokenExpiresAt).toISOString(),\n refresh_token: refreshToken,\n refresh_token_expires_in: Math.ceil(\n (refreshTokenExpiresAt - currentTime) / 1000,\n ),\n refresh_token_expiration_date: new Date(\n refreshTokenExpiresAt,\n ).toISOString(),\n },\n };\n } catch (err) {\n log('debug', '👫 - OAuth2 token issuing error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n throw YError.cast(err as Error, 'E_OAUTH2');\n }\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,yBAAT,QAA0C,sBAA1C;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,QAAT,QAAyB,cAAzB;;AAcA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uCAAiE,GAC5E;EACEC,IAAI,EAAE,8BADR;EAEEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,+EAHI;IAINC,QAAQ,EAAE,CAAC,YAAD,CAJJ;IAKNC,UAAU,EAAE;MACVC,UAAU,EAAE;QACVJ,IAAI,EAAE,QADI;QAEVK,IAAI,EAAE,CAAC,oBAAD;MAFI,CADF;MAKVC,IAAI,EAAE;QACJN,IAAI,EAAE;MADF,CALI;MAQVO,SAAS,EAAE;QACTP,IAAI,EAAE;MADG,CARD;MAWVQ,YAAY,EAAE;QACZR,IAAI,EAAE,QADM;QAEZS,OAAO,EAAE,YAFG;QAGZC,MAAM,EAAE;MAHI;IAXJ;EALN;AAFV,CADK;AA4BP,OAAO,MAAMC,8BAAwD,GAAG;EACtEb,IAAI,EAAE,qBADgE;EAEtEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,gGAHI;IAINC,QAAQ,EAAE,CAAC,YAAD,EAAe,UAAf,EAA2B,UAA3B,CAJJ;IAKNC,UAA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EG;IAAlC,CAFI,IAGF,MAAMC,OAAO,CAACC,GAAR,CAAY,CACpBvB,iBAAiB,CAACwB,MAAlB,CAAyBd,kBAAzB,EAA6CI,qBAA7C,CADoB,EAEpBb,kBAAkB,CAACuB,MAAnB,CAA0Bd,kBAA1B,EAA8CI,qBAA9C,CAFoB,CAAZ,CAHV;IAOA,MAAMW,WAAW,GAAGvB,IAAI,EAAxB;IAEA,OAAO;MACLwB,MAAM,EAAE,GADH;MAELC,OAAO,EAAE,EAFJ;MAGLpB,IAAI,EAAE;QACJf,YAAY,EAAEyB,WADV;QAEJxB,UAAU,EAAE,QAFR;QAGJC,UAAU,EAAEkC,IAAI,CAACC,IAAL,CAAU,CAACV,oBAAoB,GAAGM,WAAxB,IAAuC,IAAjD,CAHR;QAIJK,eAAe,EAAE,IAAI3B,IAAJ,CAASgB,oBAAT,EAA+BY,WAA/B,EAJb;QAKJrD,aAAa,EAAE0C,YALX;QAMJY,wBAAwB,EAAEJ,IAAI,CAACC,IAAL,CACxB,CAACR,qBAAqB,GAAGI,WAAzB,IAAwC,IADhB,CANtB;QASJQ,6BAA6B,EAAE,IAAI9B,IAAJ,CAC7BkB,qBAD6B,EAE7BU,WAF6B;MAT3B;IAHD,CAAP;EAiBD,CAzCD,CAyCE,OAAOG,GAAP,EAAY;IACZ5B,GAAG,CAAC,OAAD,EAAU,iCAAV,EAA8C4B,GAAD,CAAgBnE,IAA7D,CAAH;IACAuC,GAAG,CAAC,aAAD,EAAiB4B,GAAD,CAAeC,KAAf,IAAwB,gBAAxC,CAAH;IAEA,MAAM/E,MAAM,CAACgF,IAAP,CAAYF,GAAZ,EAA0B,UAA1B,CAAN;EACD;AACF"}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import initPostOAuth2Token from './postOAuth2Token';
|
|
2
|
-
import YError from 'yerror';
|
|
3
|
-
describe('postOAuth2Token', () => {
|
|
4
|
-
const log = jest.fn();
|
|
5
|
-
const time = jest.fn();
|
|
6
|
-
const oAuth2AccessToken = {
|
|
7
|
-
create: jest.fn(),
|
|
8
|
-
check: jest.fn()
|
|
9
|
-
};
|
|
10
|
-
const oAuth2RefreshToken = {
|
|
11
|
-
create: jest.fn(),
|
|
12
|
-
check: jest.fn()
|
|
13
|
-
};
|
|
14
|
-
const codeGranter = {
|
|
15
|
-
type: 'code',
|
|
16
|
-
authorizer: {
|
|
17
|
-
responseType: 'code',
|
|
18
|
-
authorize: jest.fn()
|
|
19
|
-
},
|
|
20
|
-
acknowledger: {
|
|
21
|
-
acknowledgmentType: 'code',
|
|
22
|
-
acknowledge: jest.fn()
|
|
23
|
-
},
|
|
24
|
-
authenticator: {
|
|
25
|
-
grantType: 'authorization_code',
|
|
26
|
-
authenticate: jest.fn()
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const passwordGranter = {
|
|
30
|
-
type: 'password',
|
|
31
|
-
authenticator: {
|
|
32
|
-
grantType: 'password',
|
|
33
|
-
authenticate: jest.fn()
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const clientCredentialsGranter = {
|
|
37
|
-
type: 'client_credentials',
|
|
38
|
-
authenticator: {
|
|
39
|
-
grantType: 'client_credentials',
|
|
40
|
-
authenticate: jest.fn()
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const tokenGranter = {
|
|
44
|
-
type: 'token',
|
|
45
|
-
authorizer: {
|
|
46
|
-
responseType: 'token',
|
|
47
|
-
authorize: jest.fn()
|
|
48
|
-
},
|
|
49
|
-
acknowledger: {
|
|
50
|
-
acknowledgmentType: 'token',
|
|
51
|
-
acknowledge: jest.fn()
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const refreshTokenGranter = {
|
|
55
|
-
type: 'refresh',
|
|
56
|
-
authenticator: {
|
|
57
|
-
grantType: 'refresh',
|
|
58
|
-
authenticate: jest.fn()
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const oAuth2Granters = [codeGranter, tokenGranter, passwordGranter, refreshTokenGranter, clientCredentialsGranter];
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
log.mockReset();
|
|
64
|
-
time.mockReset();
|
|
65
|
-
oAuth2AccessToken.create.mockReset();
|
|
66
|
-
oAuth2AccessToken.check.mockReset();
|
|
67
|
-
oAuth2RefreshToken.create.mockReset();
|
|
68
|
-
oAuth2RefreshToken.check.mockReset();
|
|
69
|
-
codeGranter.authorizer.authorize.mockReset();
|
|
70
|
-
codeGranter.acknowledger.acknowledge.mockReset();
|
|
71
|
-
codeGranter.authenticator.authenticate.mockReset();
|
|
72
|
-
tokenGranter.authorizer.authorize.mockReset();
|
|
73
|
-
tokenGranter.acknowledger.acknowledge.mockReset();
|
|
74
|
-
passwordGranter.authenticator.authenticate.mockReset();
|
|
75
|
-
refreshTokenGranter.authenticator.authenticate.mockReset();
|
|
76
|
-
clientCredentialsGranter.authenticator.authenticate.mockReset();
|
|
77
|
-
});
|
|
78
|
-
test('should create a token', async () => {
|
|
79
|
-
time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());
|
|
80
|
-
oAuth2AccessToken.create.mockResolvedValueOnce({
|
|
81
|
-
token: 'an_access_token',
|
|
82
|
-
expiresAt: Date.parse('2010-03-07T00:00:00Z')
|
|
83
|
-
});
|
|
84
|
-
oAuth2RefreshToken.create.mockResolvedValueOnce({
|
|
85
|
-
token: 'a_refresh_token',
|
|
86
|
-
expiresAt: Date.parse('2180-03-06T00:00:00Z')
|
|
87
|
-
});
|
|
88
|
-
codeGranter.authorizer.authorize.mockResolvedValueOnce({
|
|
89
|
-
applicationId: ''
|
|
90
|
-
});
|
|
91
|
-
const postOAuth2Token = await initPostOAuth2Token({
|
|
92
|
-
oAuth2Granters,
|
|
93
|
-
oAuth2AccessToken,
|
|
94
|
-
oAuth2RefreshToken,
|
|
95
|
-
time,
|
|
96
|
-
log
|
|
97
|
-
});
|
|
98
|
-
const response = await postOAuth2Token({
|
|
99
|
-
authenticationData: {
|
|
100
|
-
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
101
|
-
scope: 'user'
|
|
102
|
-
},
|
|
103
|
-
body: {
|
|
104
|
-
grant_type: 'authorization_code',
|
|
105
|
-
code: '007',
|
|
106
|
-
client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
107
|
-
redirect_uri: 'http://lol'
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
expect({
|
|
111
|
-
response,
|
|
112
|
-
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
113
|
-
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
114
|
-
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack'))
|
|
115
|
-
}).toMatchSnapshot();
|
|
116
|
-
});
|
|
117
|
-
test('should fail with a bad grant type', async () => {
|
|
118
|
-
const postOAuth2Token = await initPostOAuth2Token({
|
|
119
|
-
oAuth2Granters,
|
|
120
|
-
oAuth2AccessToken,
|
|
121
|
-
oAuth2RefreshToken,
|
|
122
|
-
time,
|
|
123
|
-
log
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
await postOAuth2Token({
|
|
128
|
-
authenticationData: {
|
|
129
|
-
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
130
|
-
scope: 'user'
|
|
131
|
-
},
|
|
132
|
-
body: {
|
|
133
|
-
grant_type: 'yolo',
|
|
134
|
-
code: '007',
|
|
135
|
-
client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
136
|
-
redirect_uri: 'http://lol'
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
throw new YError('E_UNEXPECTED_SUCCESS');
|
|
140
|
-
} catch (err) {
|
|
141
|
-
expect({
|
|
142
|
-
errorCode: err.code,
|
|
143
|
-
errorParams: err.params
|
|
144
|
-
}).toMatchInlineSnapshot(`
|
|
145
|
-
Object {
|
|
146
|
-
"errorCode": "E_UNKNOWN_AUTHENTICATOR_TYPE",
|
|
147
|
-
"errorParams": Array [
|
|
148
|
-
"yolo",
|
|
149
|
-
],
|
|
150
|
-
}
|
|
151
|
-
`);
|
|
152
|
-
expect({
|
|
153
|
-
oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,
|
|
154
|
-
oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,
|
|
155
|
-
logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack'))
|
|
156
|
-
}).toMatchSnapshot();
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
//# sourceMappingURL=postOAuth2Token.test.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postOAuth2Token.test.mjs","names":["initPostOAuth2Token","YError","describe","log","jest","fn","time","oAuth2AccessToken","create","check","oAuth2RefreshToken","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","passwordGranter","clientCredentialsGranter","tokenGranter","refreshTokenGranter","oAuth2Granters","beforeEach","mockReset","test","mockReturnValue","Date","getTime","mockResolvedValueOnce","token","expiresAt","parse","applicationId","postOAuth2Token","response","authenticationData","scope","body","grant_type","code","client_id","redirect_uri","expect","oAuth2AccessTokenCreateCalls","mock","calls","oAuth2RefreshTokenCreateCalls","logCalls","filter","endsWith","toMatchSnapshot","err","errorCode","errorParams","params","toMatchInlineSnapshot"],"sources":["../../src/handlers/postOAuth2Token.test.ts"],"sourcesContent":["import initPostOAuth2Token from './postOAuth2Token';\nimport YError from 'yerror';\nimport type { OAuth2GranterService } from '..';\n\ndescribe('postOAuth2Token', () => {\n const log = jest.fn();\n const time = jest.fn();\n const oAuth2AccessToken = { create: jest.fn(), check: jest.fn() };\n const oAuth2RefreshToken = { create: jest.fn(), check: 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 passwordGranter = {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: jest.fn(),\n },\n };\n const clientCredentialsGranter = {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\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 refreshTokenGranter = {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh',\n authenticate: jest.fn(),\n },\n };\n const oAuth2Granters: OAuth2GranterService[] = [\n codeGranter,\n tokenGranter,\n passwordGranter,\n refreshTokenGranter,\n clientCredentialsGranter,\n ];\n\n beforeEach(() => {\n log.mockReset();\n time.mockReset();\n oAuth2AccessToken.create.mockReset();\n oAuth2AccessToken.check.mockReset();\n oAuth2RefreshToken.create.mockReset();\n oAuth2RefreshToken.check.mockReset();\n codeGranter.authorizer.authorize.mockReset();\n codeGranter.acknowledger.acknowledge.mockReset();\n codeGranter.authenticator.authenticate.mockReset();\n tokenGranter.authorizer.authorize.mockReset();\n tokenGranter.acknowledger.acknowledge.mockReset();\n passwordGranter.authenticator.authenticate.mockReset();\n refreshTokenGranter.authenticator.authenticate.mockReset();\n clientCredentialsGranter.authenticator.authenticate.mockReset();\n });\n\n test('should create a token', async () => {\n time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());\n oAuth2AccessToken.create.mockResolvedValueOnce({\n token: 'an_access_token',\n expiresAt: Date.parse('2010-03-07T00:00:00Z'),\n });\n oAuth2RefreshToken.create.mockResolvedValueOnce({\n token: 'a_refresh_token',\n expiresAt: Date.parse('2180-03-06T00:00:00Z'),\n });\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: '',\n });\n\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n const response = await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'authorization_code',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n expect({\n response,\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n });\n\n test('should fail with a bad grant type', async () => {\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n\n try {\n await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'yolo',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n throw new YError('E_UNEXPECTED_SUCCESS');\n } catch (err) {\n expect({\n errorCode: (err as YError).code,\n errorParams: (err as YError).params,\n }).toMatchInlineSnapshot(`\n Object {\n \"errorCode\": \"E_UNKNOWN_AUTHENTICATOR_TYPE\",\n \"errorParams\": Array [\n \"yolo\",\n ],\n }\n `);\n expect({\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n }\n });\n});\n"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,mBAAhC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAGAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;EACA,MAAMC,IAAI,GAAGF,IAAI,CAACC,EAAL,EAAb;EACA,MAAME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AAI;MACF,MAAMmC,eAAe,CAAC;QACpBE,kBAAkB,EAAE;UAClBH,aAAa,EAAE,sCADG;UAElBI,KAAK,EAAE;QAFW,CADA;QAKpBC,IAAI,EAAE;UACJC,UAAU,EAAE,MADR;UAEJC,IAAI,EAAE,KAFF;UAGJC,SAAS,EAAE,sCAHP;UAIJC,YAAY,EAAE;QAJV;MALc,CAAD,CAArB;MAYA,MAAM,IAAI7C,MAAJ,CAAW,sBAAX,CAAN;IACD,CAdD,CAcE,OAAOuD,GAAP,EAAY;MACZT,MAAM,CAAC;QACLU,SAAS,EAAGD,GAAD,CAAgBZ,IADtB;QAELc,WAAW,EAAGF,GAAD,CAAgBG;MAFxB,CAAD,CAAN,CAGGC,qBAHH,CAG0B;AAChC;AACA;AACA;AACA;AACA;AACA;AACA,OAVM;MAWAb,MAAM,CAAC;QACLC,4BAA4B,EAAEzC,iBAAiB,CAACC,MAAlB,CAAyByC,IAAzB,CAA8BC,KADvD;QAELC,6BAA6B,EAAEzC,kBAAkB,CAACF,MAAnB,CAA0ByC,IAA1B,CAA+BC,KAFzD;QAGLE,QAAQ,EAAEjD,GAAG,CAAC8C,IAAJ,CAASC,KAAT,CAAeG,MAAf,CAAsB,CAAC,CAACzC,IAAD,CAAD,KAAY,CAACA,IAAI,CAAC0C,QAAL,CAAc,OAAd,CAAnC;MAHL,CAAD,CAAN,CAIGC,eAJH;IAKD;EACF,CAzCG,CAAJ;AA0CD,CApJO,CAAR"}
|
package/dist/index.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import initGetOAuth2Authorize, { definition as getOAuth2AuthorizeDefinition, responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter, clientIdParameter as getOAuth2AuthorizeClientIdParameter, redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter, scopeParameter as getOAuth2AuthorizeScopeParameter, stateParameter as getOAuth2AuthorizeStateParameter } from './handlers/getOAuth2Authorize';
|
|
2
|
-
import initPostOAuth2Acknowledge, { definition as postOAuth2AcknowledgeDefinition } from './handlers/postOAuth2Acknowledge';
|
|
3
|
-
import initPostOAuth2Token, { definition as postOAuth2TokenDefinition, authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema, clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema, refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema, tokenBodySchema as postOAuth2TokenTokenBodySchema } from './handlers/postOAuth2Token';
|
|
4
|
-
import initOAuth2Granters, { OAUTH2_ERRORS_DESCRIPTORS } from './services/oAuth2Granters';
|
|
5
|
-
import initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';
|
|
6
|
-
import initOAuth2CodeGranter from './services/oAuth2CodeGranter';
|
|
7
|
-
import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';
|
|
8
|
-
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';
|
|
9
|
-
import initOAuth2TokenGranter from './services/oAuth2TokenGranter';
|
|
10
|
-
import initPostAuthLogin, { definition as postAuthLoginDefinition } from './handlers/postAuthLogin';
|
|
11
|
-
import initPostAuthLogout, { definition as postAuthLogoutDefinition } from './handlers/postAuthLogout';
|
|
12
|
-
import initPostAuthRefresh, { authCookieHeaderParameter, definition as postAuthRefreshDefinition } from './handlers/postAuthRefresh';
|
|
13
|
-
import initAuthCookiesService, { AUTH_API_PREFIX } from './services/authCookies';
|
|
14
|
-
export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenDefinition, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2CodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2TokenGranter, AUTH_API_PREFIX, authCookieHeaderParameter, initPostAuthLogin, postAuthLoginDefinition, initPostAuthLogout, postAuthLogoutDefinition, initPostAuthRefresh, postAuthRefreshDefinition, initAuthCookiesService };
|
|
15
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["initGetOAuth2Authorize","definition","getOAuth2AuthorizeDefinition","responseTypeParameter","getOAuth2AuthorizeResponseTypeParameter","clientIdParameter","getOAuth2AuthorizeClientIdParameter","redirectURIParameter","getOAuth2AuthorizeRedirectURIParameter","scopeParameter","getOAuth2AuthorizeScopeParameter","stateParameter","getOAuth2AuthorizeStateParameter","initPostOAuth2Acknowledge","postOAuth2AcknowledgeDefinition","initPostOAuth2Token","postOAuth2TokenDefinition","authorizationCodeTokenRequestBodySchema","postOAuth2TokenAuthorizationCodeTokenRequestBodySchema","passwordTokenRequestBodySchema","postOAuth2TokenPasswordTokenRequestBodySchema","clientCredentialsTokenRequestBodySchema","postOAuth2TokenClientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","postOAuth2TokenRefreshTokenRequestBodySchema","tokenBodySchema","postOAuth2TokenTokenBodySchema","initOAuth2Granters","OAUTH2_ERRORS_DESCRIPTORS","initOAuth2ClientCredentialsGranter","initOAuth2CodeGranter","initOAuth2PasswordGranter","initOAuth2RefreshTokenGranter","initOAuth2TokenGranter","initPostAuthLogin","postAuthLoginDefinition","initPostAuthLogout","postAuthLogoutDefinition","initPostAuthRefresh","authCookieHeaderParameter","postAuthRefreshDefinition","initAuthCookiesService","AUTH_API_PREFIX"],"sources":["../src/index.ts"],"sourcesContent":["import initGetOAuth2Authorize, {\n definition as getOAuth2AuthorizeDefinition,\n responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter,\n clientIdParameter as getOAuth2AuthorizeClientIdParameter,\n redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,\n scopeParameter as getOAuth2AuthorizeScopeParameter,\n stateParameter as getOAuth2AuthorizeStateParameter,\n} from './handlers/getOAuth2Authorize';\nimport initPostOAuth2Acknowledge, {\n definition as postOAuth2AcknowledgeDefinition,\n} from './handlers/postOAuth2Acknowledge';\nimport initPostOAuth2Token, {\n definition as postOAuth2TokenDefinition,\n authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,\n clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,\n tokenBodySchema as postOAuth2TokenTokenBodySchema,\n} from './handlers/postOAuth2Token';\nimport initOAuth2Granters, {\n OAUTH2_ERRORS_DESCRIPTORS,\n} from './services/oAuth2Granters';\nimport initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';\nimport initOAuth2CodeGranter from './services/oAuth2CodeGranter';\nimport initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';\nimport initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';\nimport initOAuth2TokenGranter from './services/oAuth2TokenGranter';\nimport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n} from './services/oAuth2Granters';\nimport initPostAuthLogin, {\n definition as postAuthLoginDefinition,\n} from './handlers/postAuthLogin';\nimport initPostAuthLogout, {\n definition as postAuthLogoutDefinition,\n} from './handlers/postAuthLogout';\nimport initPostAuthRefresh, {\n authCookieHeaderParameter,\n definition as postAuthRefreshDefinition,\n} from './handlers/postAuthRefresh';\nimport initAuthCookiesService, {\n AUTH_API_PREFIX,\n} from './services/authCookies';\nimport type {\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n} from './services/authCookies';\n\nexport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n};\nexport {\n initGetOAuth2Authorize,\n getOAuth2AuthorizeDefinition,\n getOAuth2AuthorizeResponseTypeParameter,\n getOAuth2AuthorizeClientIdParameter,\n getOAuth2AuthorizeRedirectURIParameter,\n getOAuth2AuthorizeScopeParameter,\n getOAuth2AuthorizeStateParameter,\n initPostOAuth2Acknowledge,\n postOAuth2AcknowledgeDefinition,\n initPostOAuth2Token,\n postOAuth2TokenDefinition,\n postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n postOAuth2TokenPasswordTokenRequestBodySchema,\n postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n postOAuth2TokenRefreshTokenRequestBodySchema,\n postOAuth2TokenTokenBodySchema,\n OAUTH2_ERRORS_DESCRIPTORS,\n initOAuth2Granters,\n initOAuth2ClientCredentialsGranter,\n initOAuth2CodeGranter,\n initOAuth2PasswordGranter,\n initOAuth2RefreshTokenGranter,\n initOAuth2TokenGranter,\n AUTH_API_PREFIX,\n authCookieHeaderParameter,\n initPostAuthLogin,\n postAuthLoginDefinition,\n initPostAuthLogout,\n postAuthLogoutDefinition,\n initPostAuthRefresh,\n postAuthRefreshDefinition,\n initAuthCookiesService,\n};\n"],"mappings":"AAAA,OAAOA,sBAAP,IACEC,UAAU,IAAIC,4BADhB,EAEEC,qBAAqB,IAAIC,uCAF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