@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.
Files changed (133) hide show
  1. package/README.md +106 -70
  2. package/dist/handlers/getOAuth2Authorize.d.ts +8 -6
  3. package/dist/handlers/getOAuth2Authorize.js +122 -165
  4. package/dist/handlers/getOAuth2Authorize.js.map +1 -1
  5. package/dist/handlers/getOAuth2Authorize.test.js +117 -103
  6. package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
  7. package/dist/handlers/postAuthLogin.d.ts +3 -3
  8. package/dist/handlers/postAuthLogin.js +83 -120
  9. package/dist/handlers/postAuthLogin.js.map +1 -1
  10. package/dist/handlers/postAuthLogin.test.js +42 -44
  11. package/dist/handlers/postAuthLogin.test.js.map +1 -1
  12. package/dist/handlers/postAuthLogout.d.ts +1 -1
  13. package/dist/handlers/postAuthLogout.js +26 -42
  14. package/dist/handlers/postAuthLogout.js.map +1 -1
  15. package/dist/handlers/postAuthLogout.test.js +19 -21
  16. package/dist/handlers/postAuthLogout.test.js.map +1 -1
  17. package/dist/handlers/postAuthRefresh.d.ts +4 -4
  18. package/dist/handlers/postAuthRefresh.js +93 -131
  19. package/dist/handlers/postAuthRefresh.js.map +1 -1
  20. package/dist/handlers/postAuthRefresh.test.js +47 -49
  21. package/dist/handlers/postAuthRefresh.test.js.map +1 -1
  22. package/dist/handlers/postOAuth2Acknowledge.d.ts +11 -8
  23. package/dist/handlers/postOAuth2Acknowledge.js +119 -151
  24. package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
  25. package/dist/handlers/postOAuth2Acknowledge.test.js +139 -125
  26. package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
  27. package/dist/handlers/postOAuth2Token.d.ts +4 -4
  28. package/dist/handlers/postOAuth2Token.js +200 -232
  29. package/dist/handlers/postOAuth2Token.js.map +1 -1
  30. package/dist/handlers/postOAuth2Token.test.js +156 -153
  31. package/dist/handlers/postOAuth2Token.test.js.map +1 -1
  32. package/dist/index.d.ts +16 -16
  33. package/dist/index.js +14 -229
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.test.js +697 -620
  36. package/dist/index.test.js.map +1 -1
  37. package/dist/services/authCookies.d.ts +8 -4
  38. package/dist/services/authCookies.js +40 -71
  39. package/dist/services/authCookies.js.map +1 -1
  40. package/dist/services/authCookies.test.js +57 -62
  41. package/dist/services/authCookies.test.js.map +1 -1
  42. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +2 -2
  43. package/dist/services/oAuth2ClientCredentialsGranter.js +34 -52
  44. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  45. package/dist/services/oAuth2CodeGranter.d.ts +1 -1
  46. package/dist/services/oAuth2CodeGranter.js +66 -109
  47. package/dist/services/oAuth2CodeGranter.js.map +1 -1
  48. package/dist/services/oAuth2CodeGranter.test.js +65 -64
  49. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  50. package/dist/services/oAuth2Granters.d.ts +22 -19
  51. package/dist/services/oAuth2Granters.js +131 -138
  52. package/dist/services/oAuth2Granters.js.map +1 -1
  53. package/dist/services/oAuth2PasswordGranter.d.ts +1 -1
  54. package/dist/services/oAuth2PasswordGranter.js +27 -52
  55. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  56. package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -1
  57. package/dist/services/oAuth2RefreshTokenGranter.js +34 -58
  58. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  59. package/dist/services/oAuth2TokenGranter.d.ts +1 -1
  60. package/dist/services/oAuth2TokenGranter.js +50 -86
  61. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  62. package/package.json +54 -96
  63. package/src/__snapshots__/index.test.ts.snap +23 -22
  64. package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +1 -1
  65. package/src/handlers/getOAuth2Authorize.test.ts +49 -13
  66. package/src/handlers/getOAuth2Authorize.ts +17 -16
  67. package/src/handlers/postAuthLogin.test.ts +9 -5
  68. package/src/handlers/postAuthLogin.ts +8 -7
  69. package/src/handlers/postAuthLogout.test.ts +8 -4
  70. package/src/handlers/postAuthLogout.ts +2 -2
  71. package/src/handlers/postAuthRefresh.test.ts +10 -6
  72. package/src/handlers/postAuthRefresh.ts +8 -7
  73. package/src/handlers/postOAuth2Acknowledge.test.ts +83 -35
  74. package/src/handlers/postOAuth2Acknowledge.ts +48 -30
  75. package/src/handlers/postOAuth2Token.test.ts +79 -19
  76. package/src/handlers/postOAuth2Token.ts +7 -7
  77. package/src/index.test.ts +116 -72
  78. package/src/index.ts +21 -19
  79. package/src/services/authCookies.test.ts +2 -2
  80. package/src/services/authCookies.ts +10 -5
  81. package/src/services/oAuth2ClientCredentialsGranter.ts +28 -24
  82. package/src/services/oAuth2CodeGranter.test.ts +42 -18
  83. package/src/services/oAuth2CodeGranter.ts +68 -62
  84. package/src/services/oAuth2Granters.ts +59 -29
  85. package/src/services/oAuth2PasswordGranter.ts +25 -24
  86. package/src/services/oAuth2RefreshTokenGranter.ts +30 -26
  87. package/src/services/oAuth2TokenGranter.ts +45 -43
  88. package/dist/handlers/getOAuth2Authorize.mjs +0 -160
  89. package/dist/handlers/getOAuth2Authorize.mjs.map +0 -1
  90. package/dist/handlers/getOAuth2Authorize.test.mjs +0 -114
  91. package/dist/handlers/getOAuth2Authorize.test.mjs.map +0 -1
  92. package/dist/handlers/postAuthLogin.mjs +0 -108
  93. package/dist/handlers/postAuthLogin.mjs.map +0 -1
  94. package/dist/handlers/postAuthLogin.test.mjs +0 -85
  95. package/dist/handlers/postAuthLogin.test.mjs.map +0 -1
  96. package/dist/handlers/postAuthLogout.mjs +0 -33
  97. package/dist/handlers/postAuthLogout.mjs.map +0 -1
  98. package/dist/handlers/postAuthLogout.test.mjs +0 -30
  99. package/dist/handlers/postAuthLogout.test.mjs.map +0 -1
  100. package/dist/handlers/postAuthRefresh.mjs +0 -121
  101. package/dist/handlers/postAuthRefresh.mjs.map +0 -1
  102. package/dist/handlers/postAuthRefresh.test.mjs +0 -94
  103. package/dist/handlers/postAuthRefresh.test.mjs.map +0 -1
  104. package/dist/handlers/postOAuth2Acknowledge.mjs +0 -150
  105. package/dist/handlers/postOAuth2Acknowledge.mjs.map +0 -1
  106. package/dist/handlers/postOAuth2Acknowledge.test.mjs +0 -140
  107. package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +0 -1
  108. package/dist/handlers/postOAuth2Token.mjs +0 -231
  109. package/dist/handlers/postOAuth2Token.mjs.map +0 -1
  110. package/dist/handlers/postOAuth2Token.test.mjs +0 -160
  111. package/dist/handlers/postOAuth2Token.test.mjs.map +0 -1
  112. package/dist/index.mjs +0 -15
  113. package/dist/index.mjs.map +0 -1
  114. package/dist/index.test.mjs +0 -748
  115. package/dist/index.test.mjs.map +0 -1
  116. package/dist/services/authCookies.mjs +0 -58
  117. package/dist/services/authCookies.mjs.map +0 -1
  118. package/dist/services/authCookies.test.mjs +0 -77
  119. package/dist/services/authCookies.test.mjs.map +0 -1
  120. package/dist/services/oAuth2ClientCredentialsGranter.mjs +0 -41
  121. package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +0 -1
  122. package/dist/services/oAuth2CodeGranter.mjs +0 -98
  123. package/dist/services/oAuth2CodeGranter.mjs.map +0 -1
  124. package/dist/services/oAuth2CodeGranter.test.mjs +0 -81
  125. package/dist/services/oAuth2CodeGranter.test.mjs.map +0 -1
  126. package/dist/services/oAuth2Granters.mjs +0 -127
  127. package/dist/services/oAuth2Granters.mjs.map +0 -1
  128. package/dist/services/oAuth2PasswordGranter.mjs +0 -40
  129. package/dist/services/oAuth2PasswordGranter.mjs.map +0 -1
  130. package/dist/services/oAuth2RefreshTokenGranter.mjs +0 -47
  131. package/dist/services/oAuth2RefreshTokenGranter.mjs.map +0 -1
  132. package/dist/services/oAuth2TokenGranter.mjs +0 -78
  133. package/dist/services/oAuth2TokenGranter.mjs.map +0 -1
@@ -1,251 +1,219 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tokenBodySchema = exports.refreshTokenRequestBodySchema = exports.passwordTokenRequestBodySchema = exports.definition = exports.default = exports.clientCredentialsTokenRequestBodySchema = exports.authorizationCodeTokenRequestBodySchema = void 0;
7
-
8
- var _knifecycle = require("knifecycle");
9
-
10
- var _getOAuth2Authorize = require("./getOAuth2Authorize");
11
-
12
- var _whook = require("@whook/whook");
13
-
14
- var _yerror = _interopRequireDefault(require("yerror"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
1
+ import { autoHandler } from 'knifecycle';
2
+ import { camelCaseObjectProperties } from './getOAuth2Authorize.js';
3
+ import { noop } from '@whook/whook';
4
+ import { YError } from 'yerror';
5
+ import { refersTo } from '@whook/whook';
18
6
  /* Architecture Note #2: OAuth2 acknowledge
19
7
  This endpoint is to be used by the authentication server page
20
8
  to acknowlege that the user accepted the client request.
21
9
  */
22
- const authorizationCodeTokenRequestBodySchema = {
23
- name: 'AuthorizationCodeRequestBody',
24
- schema: {
25
- type: 'object',
26
- description: 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',
27
- required: ['grant_type'],
28
- properties: {
29
- grant_type: {
30
- type: 'string',
31
- enum: ['authorization_code']
32
- },
33
- code: {
34
- type: 'string'
35
- },
36
- client_id: {
37
- type: 'string'
38
- },
39
- redirect_uri: {
40
- type: 'string',
41
- pattern: '^https?://',
42
- format: 'uri'
43
- }
44
- }
45
- }
10
+ export const authorizationCodeTokenRequestBodySchema = {
11
+ name: 'AuthorizationCodeRequestBody',
12
+ schema: {
13
+ type: 'object',
14
+ description: 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',
15
+ required: ['grant_type'],
16
+ properties: {
17
+ grant_type: {
18
+ type: 'string',
19
+ enum: ['authorization_code'],
20
+ },
21
+ code: {
22
+ type: 'string',
23
+ },
24
+ client_id: {
25
+ type: 'string',
26
+ },
27
+ redirect_uri: {
28
+ type: 'string',
29
+ pattern: '^https?://',
30
+ format: 'uri',
31
+ },
32
+ },
33
+ },
46
34
  };
47
- exports.authorizationCodeTokenRequestBodySchema = authorizationCodeTokenRequestBodySchema;
48
- const passwordTokenRequestBodySchema = {
49
- name: 'PasswordRequestBody',
50
- schema: {
51
- type: 'object',
52
- description: 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',
53
- required: ['grant_type', 'username', 'password'],
54
- properties: {
55
- grant_type: {
56
- type: 'string',
57
- enum: ['password']
58
- },
59
- username: {
60
- type: 'string'
61
- },
62
- password: {
63
- type: 'string'
64
- },
65
- scope: {
66
- type: 'string',
67
- description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
68
- }
69
- }
70
- }
35
+ export const passwordTokenRequestBodySchema = {
36
+ name: 'PasswordRequestBody',
37
+ schema: {
38
+ type: 'object',
39
+ description: 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',
40
+ required: ['grant_type', 'username', 'password'],
41
+ properties: {
42
+ grant_type: {
43
+ type: 'string',
44
+ enum: ['password'],
45
+ },
46
+ username: {
47
+ type: 'string',
48
+ },
49
+ password: {
50
+ type: 'string',
51
+ },
52
+ scope: {
53
+ type: 'string',
54
+ description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
55
+ },
56
+ },
57
+ },
71
58
  };
72
- exports.passwordTokenRequestBodySchema = passwordTokenRequestBodySchema;
73
- const clientCredentialsTokenRequestBodySchema = {
74
- name: 'ClientCredentialsRequestBody',
75
- schema: {
76
- type: 'object',
77
- description: 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
78
- required: ['grant_type'],
79
- properties: {
80
- grant_type: {
81
- type: 'string',
82
- enum: ['client_credentials']
83
- },
84
- scope: {
85
- type: 'string',
86
- description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
87
- }
88
- }
89
- }
59
+ export const clientCredentialsTokenRequestBodySchema = {
60
+ name: 'ClientCredentialsRequestBody',
61
+ schema: {
62
+ type: 'object',
63
+ description: 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
64
+ required: ['grant_type'],
65
+ properties: {
66
+ grant_type: {
67
+ type: 'string',
68
+ enum: ['client_credentials'],
69
+ },
70
+ scope: {
71
+ type: 'string',
72
+ description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
73
+ },
74
+ },
75
+ },
90
76
  };
91
- exports.clientCredentialsTokenRequestBodySchema = clientCredentialsTokenRequestBodySchema;
92
- const refreshTokenRequestBodySchema = {
93
- name: 'RefreshTokenRequestBody',
94
- schema: {
95
- type: 'object',
96
- description: 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',
97
- required: ['grant_type', 'refresh_token'],
98
- properties: {
99
- grant_type: {
100
- type: 'string',
101
- enum: ['refresh_token']
102
- },
103
- refresh_token: {
104
- type: 'string'
105
- },
106
- scope: {
107
- type: 'string',
108
- description: 'See https://tools.ietf.org/html/rfc6749#section-3.3'
109
- }
110
- }
111
- }
77
+ export const refreshTokenRequestBodySchema = {
78
+ name: 'RefreshTokenRequestBody',
79
+ schema: {
80
+ type: 'object',
81
+ description: 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',
82
+ required: ['grant_type', 'refresh_token'],
83
+ properties: {
84
+ grant_type: {
85
+ type: 'string',
86
+ enum: ['refresh_token'],
87
+ },
88
+ refresh_token: {
89
+ type: 'string',
90
+ },
91
+ scope: {
92
+ type: 'string',
93
+ description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
94
+ },
95
+ },
96
+ },
112
97
  };
113
- exports.refreshTokenRequestBodySchema = refreshTokenRequestBodySchema;
114
- const tokenBodySchema = {
115
- name: 'TokenRequestBody',
116
- schema: {
117
- oneOf: [(0, _whook.refersTo)(passwordTokenRequestBodySchema), (0, _whook.refersTo)(authorizationCodeTokenRequestBodySchema), (0, _whook.refersTo)(clientCredentialsTokenRequestBodySchema), (0, _whook.refersTo)(refreshTokenRequestBodySchema)]
118
- }
98
+ export const tokenBodySchema = {
99
+ name: 'TokenRequestBody',
100
+ schema: {
101
+ oneOf: [
102
+ refersTo(passwordTokenRequestBodySchema),
103
+ refersTo(authorizationCodeTokenRequestBodySchema),
104
+ refersTo(clientCredentialsTokenRequestBodySchema),
105
+ refersTo(refreshTokenRequestBodySchema),
106
+ ],
107
+ },
119
108
  };
120
- exports.tokenBodySchema = tokenBodySchema;
121
- const definition = {
122
- method: 'post',
123
- path: '/oauth2/token',
124
- operation: {
125
- operationId: 'postOAuth2Token',
126
- summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)
109
+ export const definition = {
110
+ method: 'post',
111
+ path: '/oauth2/token',
112
+ operation: {
113
+ operationId: 'postOAuth2Token',
114
+ summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)
127
115
  as defined per the OAuth2 RFC.`,
128
- tags: ['oauth2'],
129
- parameters: [],
130
- requestBody: {
131
- required: true,
132
- content: {
133
- 'application/x-www-form-urlencoded': {
134
- schema: (0, _whook.refersTo)(tokenBodySchema)
135
- },
136
- 'application/json': {
137
- schema: (0, _whook.refersTo)(tokenBodySchema)
138
- }
139
- }
140
- },
141
- responses: {
142
- '200': {
143
- description: 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',
144
- content: {
145
- 'application/json': {
146
- schema: {
147
- type: 'object',
148
- required: ['access_token', 'token_type'],
149
- properties: {
150
- access_token: {
151
- type: 'string'
152
- },
153
- token_type: {
154
- description: 'See https://tools.ietf.org/html/rfc6749#section-7.1',
155
- type: 'string',
156
- enum: ['bearer', 'mac']
116
+ tags: ['oauth2'],
117
+ parameters: [],
118
+ requestBody: {
119
+ required: true,
120
+ content: {
121
+ 'application/x-www-form-urlencoded': {
122
+ schema: refersTo(tokenBodySchema),
157
123
  },
158
- expires_in: {
159
- description: 'The lifetime in seconds of the access token',
160
- type: 'number'
124
+ 'application/json': {
125
+ schema: refersTo(tokenBodySchema),
161
126
  },
162
- refresh_token: {
163
- description: 'See https://tools.ietf.org/html/rfc6749#section-6',
164
- type: 'string'
165
- }
166
- }
167
- }
168
- }
169
- }
170
- },
171
- '400': {
172
- description: 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',
173
- content: {
174
- 'application/json': {
175
- schema: {
176
- type: 'object',
177
- required: ['error'],
178
- properties: {
179
- error: {
180
- type: 'string',
181
- enum: ['invalid_request', 'invalid_client', 'invalid_grant', 'unauthorized_client', 'unsupported_grant_type', 'invalid_scope']
127
+ },
128
+ },
129
+ responses: {
130
+ '200': {
131
+ description: 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',
132
+ content: {
133
+ 'application/json': {
134
+ schema: {
135
+ type: 'object',
136
+ required: ['access_token', 'token_type'],
137
+ properties: {
138
+ access_token: { type: 'string' },
139
+ token_type: {
140
+ description: 'See https://tools.ietf.org/html/rfc6749#section-7.1',
141
+ type: 'string',
142
+ enum: ['bearer', 'mac'],
143
+ },
144
+ expires_in: {
145
+ description: 'The lifetime in seconds of the access token',
146
+ type: 'number',
147
+ },
148
+ refresh_token: {
149
+ description: 'See https://tools.ietf.org/html/rfc6749#section-6',
150
+ type: 'string',
151
+ },
152
+ },
153
+ },
154
+ },
182
155
  },
183
- error_description: {
184
- type: 'string'
156
+ },
157
+ '400': {
158
+ description: 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',
159
+ content: {
160
+ 'application/json': {
161
+ schema: {
162
+ type: 'object',
163
+ required: ['error'],
164
+ properties: {
165
+ error: {
166
+ type: 'string',
167
+ enum: [
168
+ 'invalid_request',
169
+ 'invalid_client',
170
+ 'invalid_grant',
171
+ 'unauthorized_client',
172
+ 'unsupported_grant_type',
173
+ 'invalid_scope',
174
+ ],
175
+ },
176
+ error_description: { type: 'string' },
177
+ error_uri: { type: 'string' },
178
+ },
179
+ },
180
+ },
185
181
  },
186
- error_uri: {
187
- type: 'string'
188
- }
189
- }
190
- }
191
- }
182
+ },
183
+ },
184
+ },
185
+ };
186
+ export default autoHandler(postOAuth2Token);
187
+ async function postOAuth2Token({ oAuth2Granters, oAuth2AccessToken, oAuth2RefreshToken, time = Date.now.bind(Date), log = noop, }, { body: { grant_type: grantType, ...grantParameters }, authenticationData, }) {
188
+ try {
189
+ const granter = oAuth2Granters.find((granter) => granter.authenticator && granter.authenticator.grantType === grantType);
190
+ if (!granter || !granter.authenticator) {
191
+ throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
192
192
  }
193
- }
193
+ const newAuthenticationData = await granter.authenticator.authenticate(camelCaseObjectProperties(grantParameters), authenticationData);
194
+ const [{ token: accessToken, expiresAt: accessTokenExpiresAt }, { token: refreshToken, expiresAt: refreshTokenExpiresAt },] = await Promise.all([
195
+ oAuth2AccessToken.create(authenticationData, newAuthenticationData),
196
+ oAuth2RefreshToken.create(authenticationData, newAuthenticationData),
197
+ ]);
198
+ const currentTime = time();
199
+ return {
200
+ status: 200,
201
+ headers: {},
202
+ body: {
203
+ access_token: accessToken,
204
+ token_type: 'bearer',
205
+ expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),
206
+ expiration_date: new Date(accessTokenExpiresAt).toISOString(),
207
+ refresh_token: refreshToken,
208
+ refresh_token_expires_in: Math.ceil((refreshTokenExpiresAt - currentTime) / 1000),
209
+ refresh_token_expiration_date: new Date(refreshTokenExpiresAt).toISOString(),
210
+ },
211
+ };
194
212
  }
195
- }
196
- };
197
- exports.definition = definition;
198
-
199
- var _default = (0, _knifecycle.handler)(postOAuth2Token, "postOAuth2Token", ["oAuth2Granters", "oAuth2AccessToken", "oAuth2RefreshToken", "?time", "?log"]);
200
-
201
- exports.default = _default;
202
-
203
- async function postOAuth2Token({
204
- oAuth2Granters,
205
- oAuth2AccessToken,
206
- oAuth2RefreshToken,
207
- time = Date.now.bind(Date),
208
- log = _whook.noop
209
- }, {
210
- body: {
211
- grant_type: grantType,
212
- ...grantParameters
213
- },
214
- authenticationData
215
- }) {
216
- try {
217
- const granter = oAuth2Granters.find(granter => granter.authenticator && granter.authenticator.grantType === grantType);
218
-
219
- if (!granter) {
220
- throw new _yerror.default('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
213
+ catch (err) {
214
+ log('debug', '👫 - OAuth2 token issuing error', err.code);
215
+ log('debug-stack', err.stack || 'no_stack_trace');
216
+ throw YError.cast(err, 'E_OAUTH2');
221
217
  }
222
-
223
- const newAuthenticationData = await granter.authenticator.authenticate((0, _getOAuth2Authorize.camelCaseObjectProperties)(grantParameters), authenticationData);
224
- const [{
225
- token: accessToken,
226
- expiresAt: accessTokenExpiresAt
227
- }, {
228
- token: refreshToken,
229
- expiresAt: refreshTokenExpiresAt
230
- }] = await Promise.all([oAuth2AccessToken.create(authenticationData, newAuthenticationData), oAuth2RefreshToken.create(authenticationData, newAuthenticationData)]);
231
- const currentTime = time();
232
- return {
233
- status: 200,
234
- headers: {},
235
- body: {
236
- access_token: accessToken,
237
- token_type: 'bearer',
238
- expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),
239
- expiration_date: new Date(accessTokenExpiresAt).toISOString(),
240
- refresh_token: refreshToken,
241
- refresh_token_expires_in: Math.ceil((refreshTokenExpiresAt - currentTime) / 1000),
242
- refresh_token_expiration_date: new Date(refreshTokenExpiresAt).toISOString()
243
- }
244
- };
245
- } catch (err) {
246
- log('debug', '👫 - OAuth2 token issuing error', err.code);
247
- log('debug-stack', err.stack);
248
- throw _yerror.default.cast(err, 'E_OAUTH2');
249
- }
250
218
  }
251
219
  //# sourceMappingURL=postOAuth2Token.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postOAuth2Token.ts"],"names":["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","noop","body","grantType","grantParameters","authenticationData","granter","find","authenticator","YError","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"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAeA;AACA;AACA;AACA;AACO,MAAMA,uCAAiE,GAC5E;AACEC,EAAAA,IAAI,EAAE,8BADR;AAEEC,EAAAA,MAAM,EAAE;AACNC,IAAAA,IAAI,EAAE,QADA;AAENC,IAAAA,WAAW,EACT,+EAHI;AAINC,IAAAA,QAAQ,EAAE,CAAC,YAAD,CAJJ;AAKNC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE;AACVJ,QAAAA,IAAI,EAAE,QADI;AAEVK,QAAAA,IAAI,EAAE,CAAC,oBAAD;AAFI,OADF;AAKVC,MAAAA,IAAI,EAAE;AACJN,QAAAA,IAAI,EAAE;AADF,OALI;AAQVO,MAAAA,SAAS,EAAE;AACTP,QAAAA,IAAI,EAAE;AADG,OARD;AAWVQ,MAAAA,YAAY,EAAE;AACZR,QAAAA,IAAI,EAAE,QADM;AAEZS,QAAAA,OAAO,EAAE,YAFG;AAGZC,QAAAA,MAAM,EAAE;AAHI;AAXJ;AALN;AAFV,CADK;;AA4BA,MAAMC,8BAAwD,GAAG;AACtEb,EAAAA,IAAI,EAAE,qBADgE;AAEtEC,EAAAA,MAAM,EAAE;AACNC,IAAAA,IAAI,EAAE,QADA;AAENC,IAAAA,WAAW,EACT,gGAHI;AAINC,IAAAA,QAAQ,EAAE,CAAC,YAAD,EAAe,UAAf,EAA2B,UAA3B,CAJJ;AAKNC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE;AACVJ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BAAqB,GAAGI,WAAzB,IAAwC,IADhB,CANtB;AASJQ,QAAAA,6BAA6B,EAAE,IAAIhC,IAAJ,CAC7BoB,qBAD6B,EAE7BU,WAF6B;AAT3B;AAHD,KAAP;AAiBD,GAzCD,CAyCE,OAAOG,GAAP,EAAY;AACZ9B,IAAAA,GAAG,CAAC,OAAD,EAAU,iCAAV,EAA6C8B,GAAG,CAACrE,IAAjD,CAAH;AACAuC,IAAAA,GAAG,CAAC,aAAD,EAAgB8B,GAAG,CAACC,KAApB,CAAH;AAEA,UAAMtB,gBAAOuB,IAAP,CAAYF,GAAZ,EAAiB,UAAjB,CAAN;AACD;AACF","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) {\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.code);\n log('debug-stack', err.stack);\n\n throw YError.cast(err, 'E_OAUTH2');\n }\n}\n"],"file":"postOAuth2Token.js"}
1
+ {"version":3,"file":"postOAuth2Token.js","sourceRoot":"","sources":["../../src/handlers/postOAuth2Token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAcxC;;;EAGE;AACF,MAAM,CAAC,MAAM,uCAAuC,GAClD;IACE,IAAI,EAAE,8BAA8B;IACpC,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,WAAW,EACT,+EAA+E;QACjF,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,E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