@whook/oauth2 27.0.3 → 27.1.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 (121) hide show
  1. package/README.md +44 -25
  2. package/dist/index.d.ts +11 -7
  3. package/dist/index.js +9 -6
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.test.js +131 -15
  6. package/dist/index.test.js.map +1 -1
  7. package/dist/libs/clients.d.ts +17 -1
  8. package/dist/libs/clients.js +39 -6
  9. package/dist/libs/clients.js.map +1 -1
  10. package/dist/libs/clients.test.d.ts +1 -0
  11. package/dist/libs/clients.test.js +32 -0
  12. package/dist/libs/clients.test.js.map +1 -0
  13. package/dist/libs/errors.d.ts +24 -0
  14. package/dist/libs/errors.js +42 -0
  15. package/dist/libs/errors.js.map +1 -1
  16. package/dist/libs/verifier.d.ts +3 -3
  17. package/dist/libs/verifier.js +4 -3
  18. package/dist/libs/verifier.js.map +1 -1
  19. package/dist/routes/getOAuth2Authorize.d.ts +19 -6
  20. package/dist/routes/getOAuth2Authorize.js +29 -14
  21. package/dist/routes/getOAuth2Authorize.js.map +1 -1
  22. package/dist/routes/getOAuth2WellKnownMetadata.d.ts +3 -4
  23. package/dist/routes/getOAuth2WellKnownMetadata.js +19 -7
  24. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
  25. package/dist/routes/getOAuth2WellKnownMetadata.test.js +81 -0
  26. package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
  27. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +0 -2
  28. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +1 -2
  29. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
  30. package/dist/routes/postAuthLogin.d.ts +1 -1
  31. package/dist/routes/postAuthLogin.js +1 -1
  32. package/dist/routes/postAuthLogin.js.map +1 -1
  33. package/dist/routes/postAuthRefresh.d.ts +1 -1
  34. package/dist/routes/postAuthRefresh.js +1 -1
  35. package/dist/routes/postAuthRefresh.js.map +1 -1
  36. package/dist/routes/postOAuth2Acknowledge.d.ts +0 -3
  37. package/dist/routes/postOAuth2Acknowledge.js +1 -3
  38. package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
  39. package/dist/routes/postOAuth2DeviceAcknowledge.d.ts +64 -0
  40. package/dist/routes/postOAuth2DeviceAcknowledge.js +84 -0
  41. package/dist/routes/postOAuth2DeviceAcknowledge.js.map +1 -0
  42. package/dist/routes/postOAuth2DeviceAcknowledge.test.d.ts +1 -0
  43. package/dist/routes/postOAuth2DeviceAcknowledge.test.js +369 -0
  44. package/dist/routes/postOAuth2DeviceAcknowledge.test.js.map +1 -0
  45. package/dist/routes/postOAuth2DeviceAuthorization.d.ts +133 -0
  46. package/dist/routes/postOAuth2DeviceAuthorization.js +177 -0
  47. package/dist/routes/postOAuth2DeviceAuthorization.js.map +1 -0
  48. package/dist/routes/postOAuth2DeviceAuthorization.test.d.ts +1 -0
  49. package/dist/routes/postOAuth2DeviceAuthorization.test.js +174 -0
  50. package/dist/routes/postOAuth2DeviceAuthorization.test.js.map +1 -0
  51. package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +1 -6
  52. package/dist/routes/postOAuth2PushedAuthorizationRequest.js +11 -14
  53. package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -1
  54. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +47 -0
  55. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -1
  56. package/dist/routes/postOAuth2Token.d.ts +2 -7
  57. package/dist/routes/postOAuth2Token.js +2 -6
  58. package/dist/routes/postOAuth2Token.js.map +1 -1
  59. package/dist/routes/postOAuth2Token.test.js +107 -0
  60. package/dist/routes/postOAuth2Token.test.js.map +1 -1
  61. package/dist/routes/schemas.d.ts +178 -0
  62. package/dist/routes/schemas.js +188 -0
  63. package/dist/routes/schemas.js.map +1 -0
  64. package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +0 -70
  65. package/dist/services/oAuth2AuthorizationCodeGranter.js +7 -84
  66. package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -1
  67. package/dist/services/oAuth2AuthorizationRequests.js +4 -5
  68. package/dist/services/oAuth2AuthorizationRequests.js.map +1 -1
  69. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +1 -16
  70. package/dist/services/oAuth2ClientCredentialsGranter.js +7 -25
  71. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  72. package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.d.ts +1 -0
  73. package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.js +332 -0
  74. package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.js.map +1 -0
  75. package/dist/services/oAuth2DeviceAuthorizationGranter.d.ts +54 -0
  76. package/dist/services/oAuth2DeviceAuthorizationGranter.js +67 -0
  77. package/dist/services/oAuth2DeviceAuthorizationGranter.js.map +1 -0
  78. package/dist/services/oAuth2Granters.js +0 -2
  79. package/dist/services/oAuth2Granters.js.map +1 -1
  80. package/dist/services/oAuth2PasswordGranter.d.ts +1 -22
  81. package/dist/services/oAuth2PasswordGranter.js +5 -30
  82. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  83. package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -19
  84. package/dist/services/oAuth2RefreshTokenGranter.js +5 -28
  85. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  86. package/package.json +2 -2
  87. package/src/index.test.ts +169 -26
  88. package/src/index.ts +21 -26
  89. package/src/libs/clients.test.ts +47 -0
  90. package/src/libs/clients.ts +60 -10
  91. package/src/libs/errors.ts +72 -0
  92. package/src/libs/verifier.ts +11 -3
  93. package/src/routes/__snapshots__/postOAuth2DeviceAcknowledge.test.ts.snap +5 -0
  94. package/src/routes/getOAuth2Authorize.ts +41 -26
  95. package/src/routes/getOAuth2WellKnownMetadata.test.ts +96 -0
  96. package/src/routes/getOAuth2WellKnownMetadata.ts +24 -10
  97. package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +1 -3
  98. package/src/routes/postAuthLogin.ts +1 -1
  99. package/src/routes/postAuthRefresh.ts +1 -1
  100. package/src/routes/postOAuth2Acknowledge.ts +2 -4
  101. package/src/routes/postOAuth2DeviceAcknowledge.test.ts +408 -0
  102. package/src/routes/postOAuth2DeviceAcknowledge.ts +157 -0
  103. package/src/routes/postOAuth2DeviceAuthorization.test.ts +192 -0
  104. package/src/routes/postOAuth2DeviceAuthorization.ts +261 -0
  105. package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +59 -0
  106. package/src/routes/postOAuth2PushedAuthorizationRequest.ts +16 -22
  107. package/src/routes/postOAuth2Token.test.ts +119 -0
  108. package/src/routes/postOAuth2Token.ts +6 -16
  109. package/src/routes/schemas.ts +210 -0
  110. package/src/services/oAuth2AuthorizationCodeGranter.ts +11 -94
  111. package/src/services/oAuth2AuthorizationRequests.ts +5 -5
  112. package/src/services/oAuth2ClientCredentialsGranter.ts +8 -27
  113. package/src/services/oAuth2DeviceAuthorizationCodeGranter.test.ts +372 -0
  114. package/src/services/oAuth2DeviceAuthorizationGranter.ts +194 -0
  115. package/src/services/oAuth2Granters.ts +0 -2
  116. package/src/services/oAuth2PasswordGranter.ts +7 -33
  117. package/src/services/oAuth2RefreshTokenGranter.ts +6 -31
  118. package/dist/libs/schemas.d.ts +0 -31
  119. package/dist/libs/schemas.js +0 -33
  120. package/dist/libs/schemas.js.map +0 -1
  121. package/src/libs/schemas.ts +0 -37
@@ -0,0 +1,84 @@
1
+ import { autoService, location } from 'knifecycle';
2
+ import { refersTo, } from '@whook/whook';
3
+ import { DEVICE_AUTHORIZATION_GRANT_TYPE, } from '../services/oAuth2DeviceAuthorizationGranter.js';
4
+ import { checkGrants } from '../libs/clients.js';
5
+ import { checkGrantType } from '../libs/grants.js';
6
+ import { filterScopes, parseOAuth2Scope } from '../libs/scopes.js';
7
+ import { clientIdSchema, scopeSchema } from './schemas.js';
8
+ import { userCodeSchema } from './postOAuth2DeviceAuthorization.js';
9
+ import { YError } from 'yerror';
10
+ export const deviceAcknowledgeRequestBodySchema = {
11
+ name: 'DeviceAcknowledgeRequestBody',
12
+ schema: {
13
+ type: 'object',
14
+ description: 'Device acknowledge request',
15
+ required: ['clientId', 'userCode', 'scope', 'acknowledged'],
16
+ properties: {
17
+ clientId: refersTo(clientIdSchema),
18
+ userCode: refersTo(userCodeSchema),
19
+ scope: refersTo(scopeSchema),
20
+ acknowledged: {
21
+ type: 'boolean',
22
+ description: 'Whether the user acknowledged the delegation or not.',
23
+ },
24
+ },
25
+ },
26
+ };
27
+ export const definition = {
28
+ method: 'post',
29
+ path: '/oauth2/device_acknowledge',
30
+ config: {
31
+ environments: [],
32
+ private: true,
33
+ },
34
+ operation: {
35
+ operationId: 'postOAuth2DeviceAcknowledge',
36
+ summary: `Implements the logic that allow the authentication frontend
37
+ to process the [Device Authorization](https://datatracker.ietf.org/doc/html/rfc8628#section-3.1).`,
38
+ tags: ['oauth2'],
39
+ parameters: [],
40
+ requestBody: {
41
+ required: true,
42
+ content: {
43
+ 'application/json': {
44
+ schema: refersTo(deviceAcknowledgeRequestBodySchema),
45
+ },
46
+ },
47
+ },
48
+ responses: {
49
+ '204': {
50
+ description: 'Device authorization acknowledged.',
51
+ },
52
+ },
53
+ },
54
+ };
55
+ async function initPostOAuth2DeviceAcknowledge({ OAUTH2, readClientGrants, oAuth2DeviceAuthorizationCode, }) {
56
+ return async ({ body: { clientId, userCode, scope: demandedScope, acknowledged }, authenticationData: userAuthenticationData, }) => {
57
+ if (!userAuthenticationData) {
58
+ throw new YError('E_UNAUTHORIZED');
59
+ }
60
+ const acknowledgeClientGrants = await readClientGrants(userAuthenticationData.clientId);
61
+ checkGrants(userAuthenticationData.clientId, acknowledgeClientGrants);
62
+ if (!acknowledgeClientGrants.canAcknowledge) {
63
+ throw new YError('E_UNAUTHORIZED');
64
+ }
65
+ try {
66
+ const clientGrants = await readClientGrants(clientId);
67
+ checkGrants(clientId, clientGrants);
68
+ checkGrantType(clientGrants.allowedGrantTypes, DEVICE_AUTHORIZATION_GRANT_TYPE);
69
+ const filteredScopes = filterScopes(filterScopes(filterScopes(parseOAuth2Scope(demandedScope), OAUTH2.allowedScopes, !!OAUTH2.strictScopesChecks), clientGrants.allowedScopes, !!OAUTH2.strictScopesChecks), userAuthenticationData.scopes, !!OAUTH2.strictScopesChecks);
70
+ await oAuth2DeviceAuthorizationCode.acknowledge(acknowledged, userAuthenticationData, userCode, clientId, filteredScopes);
71
+ return {
72
+ status: 204,
73
+ headers: {},
74
+ };
75
+ }
76
+ catch (err) {
77
+ // Ensure to break device acknoledgement wait when
78
+ // unexpected errors arise
79
+ throw YError.wrap(err, 'E_UNAUTHORIZED');
80
+ }
81
+ };
82
+ }
83
+ export default location(autoService(initPostOAuth2DeviceAcknowledge), import.meta.url);
84
+ //# sourceMappingURL=postOAuth2DeviceAcknowledge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postOAuth2DeviceAcknowledge.js","sourceRoot":"","sources":["../../src/routes/postOAuth2DeviceAcknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,QAAQ,GAGT,MAAM,cAAc,CAAC;AAMtB,OAAO,EACL,+BAA+B,GAGhC,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,kCAAkC,GA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,CAAC,IAAI,CAAC,GAAG,CAChB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,369 @@
1
+ import { describe, test, beforeEach, jest, expect } from '@jest/globals';
2
+ import initPostOAuth2DeviceAcknowledge from './postOAuth2DeviceAcknowledge.js';
3
+ import { YError } from 'yerror';
4
+ describe('postOAuth2DeviceAcknowledge', () => {
5
+ const OAUTH2 = {
6
+ authenticateURL: 'https://auth.example.com/sign_in',
7
+ allowedScopes: ['user', 'admin'],
8
+ rootClientId: 'root_app_id',
9
+ };
10
+ const readClientGrants = jest.fn();
11
+ const oAuth2DeviceAuthorizationCode = {
12
+ acknowledge: jest.fn(),
13
+ };
14
+ beforeEach(() => {
15
+ readClientGrants.mockReset();
16
+ oAuth2DeviceAuthorizationCode.acknowledge.mockReset();
17
+ });
18
+ test('should acknowledge a device authorization challenge', async () => {
19
+ oAuth2DeviceAuthorizationCode.acknowledge.mockResolvedValueOnce();
20
+ const postOAuth2DeviceAcknowledge = await initPostOAuth2DeviceAcknowledge({
21
+ OAUTH2,
22
+ readClientGrants,
23
+ oAuth2DeviceAuthorizationCode,
24
+ });
25
+ readClientGrants.mockResolvedValueOnce({
26
+ allowedScopes: ['user', 'admin'],
27
+ allowedRedirectURIS: ['https://www.example.com'],
28
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
29
+ authenticationData: {
30
+ clientId: 'root_app_id',
31
+ scopes: ['user', 'admin'],
32
+ userId: 'root_user_id',
33
+ },
34
+ isPublicClient: true,
35
+ canAcknowledge: true,
36
+ });
37
+ readClientGrants.mockResolvedValueOnce({
38
+ allowedScopes: ['user', 'admin'],
39
+ allowedRedirectURIS: ['https://www.example.com'],
40
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
41
+ authenticationData: {
42
+ clientId: 'client_app_id',
43
+ scopes: ['user', 'admin'],
44
+ userId: 'client_user_id',
45
+ },
46
+ isPublicClient: true,
47
+ });
48
+ const response = await postOAuth2DeviceAcknowledge({
49
+ body: {
50
+ clientId: 'client_app_id',
51
+ userCode: 'a_user_code',
52
+ scope: 'user',
53
+ acknowledged: true,
54
+ },
55
+ authenticationData: {
56
+ clientId: 'root_app_id',
57
+ scopes: ['user', 'admin'],
58
+ userId: 'user_id',
59
+ },
60
+ });
61
+ expect({
62
+ response,
63
+ readClientGrantsCalls: readClientGrants.mock.calls,
64
+ oAuth2DeviceAuthorizationCodeCreateCalls: oAuth2DeviceAuthorizationCode.acknowledge.mock.calls,
65
+ }).toMatchInlineSnapshot(`
66
+ {
67
+ "oAuth2DeviceAuthorizationCodeCreateCalls": [
68
+ [
69
+ true,
70
+ {
71
+ "clientId": "root_app_id",
72
+ "scopes": [
73
+ "user",
74
+ "admin",
75
+ ],
76
+ "userId": "user_id",
77
+ },
78
+ "a_user_code",
79
+ "client_app_id",
80
+ [
81
+ "user",
82
+ ],
83
+ ],
84
+ ],
85
+ "readClientGrantsCalls": [
86
+ [
87
+ "root_app_id",
88
+ ],
89
+ [
90
+ "client_app_id",
91
+ ],
92
+ ],
93
+ "response": {
94
+ "headers": {},
95
+ "status": 204,
96
+ },
97
+ }
98
+ `);
99
+ });
100
+ test.each([true, false])('should propagate a stored challenge client mismatch when acknowledged is %p', async (acknowledged) => {
101
+ const mismatchError = new YError('E_OAUTH2_CLIENT_MISMATCH', [
102
+ 'client_app_id',
103
+ 'another_client',
104
+ ]);
105
+ oAuth2DeviceAuthorizationCode.acknowledge.mockRejectedValueOnce(mismatchError);
106
+ readClientGrants.mockImplementation(async (clientId) => ({
107
+ allowedScopes: ['user'],
108
+ allowedRedirectURIS: [],
109
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
110
+ authenticationData: {
111
+ clientId,
112
+ userId: 'client_user_id',
113
+ scopes: ['user'],
114
+ },
115
+ isPublicClient: true,
116
+ canAcknowledge: clientId === 'root_app_id',
117
+ }));
118
+ const postOAuth2DeviceAcknowledge = await initPostOAuth2DeviceAcknowledge({
119
+ OAUTH2,
120
+ readClientGrants,
121
+ oAuth2DeviceAuthorizationCode,
122
+ });
123
+ const authenticationData = {
124
+ clientId: 'root_app_id',
125
+ userId: 'user_id',
126
+ scopes: ['user'],
127
+ };
128
+ await expect(postOAuth2DeviceAcknowledge({
129
+ body: {
130
+ clientId: 'client_app_id',
131
+ userCode: 'a_user_code',
132
+ scope: 'user admin',
133
+ acknowledged,
134
+ },
135
+ authenticationData,
136
+ })).rejects.toMatchSnapshot();
137
+ expect(oAuth2DeviceAuthorizationCode.acknowledge).toHaveBeenCalledWith(acknowledged, authenticationData, 'a_user_code', 'client_app_id', ['user']);
138
+ });
139
+ test('should fail with a bad client grant setup', async () => {
140
+ const postOAuth2DeviceAcknowledge = await initPostOAuth2DeviceAcknowledge({
141
+ OAUTH2,
142
+ readClientGrants,
143
+ oAuth2DeviceAuthorizationCode,
144
+ });
145
+ readClientGrants.mockResolvedValueOnce({
146
+ allowedScopes: ['user', 'admin'],
147
+ allowedRedirectURIS: ['https://www.example.com'],
148
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
149
+ authenticationData: {
150
+ clientId: 'root_app_id',
151
+ scopes: ['user', 'admin'],
152
+ userId: 'root_user_id',
153
+ },
154
+ isPublicClient: true,
155
+ canAcknowledge: true,
156
+ });
157
+ readClientGrants.mockResolvedValueOnce({
158
+ allowedScopes: ['user', 'admin'],
159
+ allowedRedirectURIS: ['https://www.example.com'],
160
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
161
+ authenticationData: {
162
+ clientId: 'another_client',
163
+ scopes: ['user', 'admin'],
164
+ userId: 'client_user_id',
165
+ },
166
+ isPublicClient: true,
167
+ });
168
+ try {
169
+ await postOAuth2DeviceAcknowledge({
170
+ body: {
171
+ clientId: 'client_app_id',
172
+ userCode: 'a_user_code',
173
+ scope: 'user',
174
+ acknowledged: true,
175
+ },
176
+ authenticationData: {
177
+ clientId: 'root_app_id',
178
+ scopes: ['user', 'admin'],
179
+ userId: 'user_id',
180
+ },
181
+ });
182
+ throw new YError('E_UNEXPECTED_SUCCESS');
183
+ }
184
+ catch (err) {
185
+ expect({
186
+ errorCode: err.code,
187
+ errorDebug: err.debug,
188
+ causeErrorCode: err.cause?.code,
189
+ causeErrorDebug: err.cause?.debug,
190
+ readClientGrantsCalls: readClientGrants.mock.calls,
191
+ oAuth2DeviceAuthorizationCodeCreateCalls: oAuth2DeviceAuthorizationCode.acknowledge.mock.calls,
192
+ }).toMatchInlineSnapshot(`
193
+ {
194
+ "causeErrorCode": "E_OAUTH2_CLIENT_GRANTS_MISMATCH",
195
+ "causeErrorDebug": [
196
+ "client_app_id",
197
+ "another_client",
198
+ ],
199
+ "errorCode": "E_UNAUTHORIZED",
200
+ "errorDebug": [],
201
+ "oAuth2DeviceAuthorizationCodeCreateCalls": [],
202
+ "readClientGrantsCalls": [
203
+ [
204
+ "root_app_id",
205
+ ],
206
+ [
207
+ "client_app_id",
208
+ ],
209
+ ],
210
+ }
211
+ `);
212
+ }
213
+ });
214
+ test('should fail with a client without device grant', async () => {
215
+ const postOAuth2DeviceAcknowledge = await initPostOAuth2DeviceAcknowledge({
216
+ OAUTH2,
217
+ readClientGrants,
218
+ oAuth2DeviceAuthorizationCode,
219
+ });
220
+ readClientGrants.mockResolvedValueOnce({
221
+ allowedScopes: ['user', 'admin'],
222
+ allowedRedirectURIS: ['https://www.example.com'],
223
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
224
+ authenticationData: {
225
+ clientId: 'root_app_id',
226
+ scopes: ['user', 'admin'],
227
+ userId: 'root_user_id',
228
+ },
229
+ isPublicClient: true,
230
+ canAcknowledge: true,
231
+ });
232
+ readClientGrants.mockResolvedValueOnce({
233
+ allowedScopes: ['user', 'admin'],
234
+ allowedRedirectURIS: ['https://www.example.com'],
235
+ allowedGrantTypes: ['client_credentials'],
236
+ authenticationData: {
237
+ clientId: 'client_app_id',
238
+ scopes: ['user', 'admin'],
239
+ userId: 'client_user_id',
240
+ },
241
+ isPublicClient: true,
242
+ });
243
+ try {
244
+ await postOAuth2DeviceAcknowledge({
245
+ body: {
246
+ clientId: 'client_app_id',
247
+ userCode: 'a_user_code',
248
+ scope: 'user',
249
+ acknowledged: true,
250
+ },
251
+ authenticationData: {
252
+ clientId: 'root_app_id',
253
+ scopes: ['user', 'admin'],
254
+ userId: 'user_id',
255
+ },
256
+ });
257
+ throw new YError('E_UNEXPECTED_SUCCESS');
258
+ }
259
+ catch (err) {
260
+ expect({
261
+ errorCode: err.code,
262
+ errorDebug: err.debug,
263
+ causeErrorCode: err.cause?.code,
264
+ causeErrorDebug: err.cause?.debug,
265
+ readClientGrantsCalls: readClientGrants.mock.calls,
266
+ oAuth2DeviceAuthorizationCodeCreateCalls: oAuth2DeviceAuthorizationCode.acknowledge.mock.calls,
267
+ }).toMatchInlineSnapshot(`
268
+ {
269
+ "causeErrorCode": "E_OAUTH2_GRANT_TYPE_NOT_ALLOWED",
270
+ "causeErrorDebug": [
271
+ "urn:ietf:params:oauth:grant-type:device_code",
272
+ [
273
+ "client_credentials",
274
+ ],
275
+ ],
276
+ "errorCode": "E_UNAUTHORIZED",
277
+ "errorDebug": [],
278
+ "oAuth2DeviceAuthorizationCodeCreateCalls": [],
279
+ "readClientGrantsCalls": [
280
+ [
281
+ "root_app_id",
282
+ ],
283
+ [
284
+ "client_app_id",
285
+ ],
286
+ ],
287
+ }
288
+ `);
289
+ }
290
+ });
291
+ test('should fail with bad scopes', async () => {
292
+ const postOAuth2DeviceAcknowledge = await initPostOAuth2DeviceAcknowledge({
293
+ OAUTH2: {
294
+ ...OAUTH2,
295
+ strictScopesChecks: true,
296
+ },
297
+ readClientGrants,
298
+ oAuth2DeviceAuthorizationCode,
299
+ });
300
+ readClientGrants.mockResolvedValueOnce({
301
+ allowedScopes: ['user', 'admin'],
302
+ allowedRedirectURIS: ['https://www.example.com'],
303
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
304
+ authenticationData: {
305
+ clientId: 'root_app_id',
306
+ scopes: ['user', 'admin'],
307
+ userId: 'root_user_id',
308
+ },
309
+ isPublicClient: true,
310
+ canAcknowledge: true,
311
+ });
312
+ readClientGrants.mockResolvedValueOnce({
313
+ allowedScopes: ['user', 'admin'],
314
+ allowedRedirectURIS: ['https://www.example.com'],
315
+ allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
316
+ authenticationData: {
317
+ clientId: 'client_app_id',
318
+ scopes: ['user', 'admin'],
319
+ userId: 'client_user_id',
320
+ },
321
+ isPublicClient: true,
322
+ });
323
+ try {
324
+ await postOAuth2DeviceAcknowledge({
325
+ body: {
326
+ clientId: 'client_app_id',
327
+ userCode: 'a_user_code',
328
+ scope: 'user god',
329
+ acknowledged: true,
330
+ },
331
+ authenticationData: {
332
+ clientId: 'root_app_id',
333
+ scopes: ['user', 'admin'],
334
+ userId: 'user_id',
335
+ },
336
+ });
337
+ throw new YError('E_UNEXPECTED_SUCCESS');
338
+ }
339
+ catch (err) {
340
+ expect({
341
+ errorCode: err.code,
342
+ errorDebug: err.debug,
343
+ causeErrorCode: err.cause?.code,
344
+ causeErrorDebug: err.cause?.debug,
345
+ readClientGrantsCalls: readClientGrants.mock.calls,
346
+ oAuth2DeviceAuthorizationCodeCreateCalls: oAuth2DeviceAuthorizationCode.acknowledge.mock.calls,
347
+ }).toMatchInlineSnapshot(`
348
+ {
349
+ "causeErrorCode": "E_OAUTH2_BAD_SCOPE",
350
+ "causeErrorDebug": [
351
+ "god",
352
+ ],
353
+ "errorCode": "E_UNAUTHORIZED",
354
+ "errorDebug": [],
355
+ "oAuth2DeviceAuthorizationCodeCreateCalls": [],
356
+ "readClientGrantsCalls": [
357
+ [
358
+ "root_app_id",
359
+ ],
360
+ [
361
+ "client_app_id",
362
+ ],
363
+ ],
364
+ }
365
+ `);
366
+ }
367
+ });
368
+ });
369
+ //# sourceMappingURL=postOAuth2DeviceAcknowledge.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postOAuth2Devi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1
+ import { type LogService, type TimeService } from 'common-services';
2
+ import { type WhookOAuth2Options, type WhookOAuth2ReadClientGrantsService, type WhookOAuth2ClientId } from '../services/oAuth2Granters.js';
3
+ import { type WhookOAuth2DeviceAuthorizationOptions, type WhookOAuth2DeviceAuthorizationCodeService } from '../services/oAuth2DeviceAuthorizationGranter.js';
4
+ import { type WhookAuthenticationData } from '@whook/authorization';
5
+ export declare const userCodeSchema: {
6
+ readonly name: "OAuth2UserCode";
7
+ readonly schema: {
8
+ readonly type: "string";
9
+ };
10
+ };
11
+ export declare const deviceAuthorizationRequestBodySchema: {
12
+ readonly name: "DeviceAuthorizationRequestBody";
13
+ readonly schema: {
14
+ readonly type: "object";
15
+ readonly description: "Device authorization request, see https://datatracker.ietf.org/doc/html/rfc8628#section-3.1";
16
+ readonly required: [];
17
+ readonly properties: {
18
+ readonly client_id: import("ya-json-schema-types").ExpressiveJSONSchema;
19
+ readonly scope: import("ya-json-schema-types").ExpressiveJSONSchema;
20
+ };
21
+ };
22
+ };
23
+ export declare const definition: {
24
+ readonly method: "post";
25
+ readonly path: "/oauth2/device_authorization";
26
+ readonly config: {
27
+ readonly environments: [];
28
+ };
29
+ readonly operation: {
30
+ readonly operationId: "postOAuth2DeviceAuthorization";
31
+ readonly summary: "Implements the [Device Authorization Endpoint](https://datatracker.ietf.org/doc/html/rfc8628#section-3.1).";
32
+ readonly tags: ["oauth2"];
33
+ readonly parameters: [];
34
+ readonly requestBody: {
35
+ readonly required: false;
36
+ readonly content: {
37
+ readonly 'application/x-www-form-urlencoded': {
38
+ readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
39
+ };
40
+ readonly 'application/json': {
41
+ readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
42
+ };
43
+ };
44
+ };
45
+ readonly responses: {
46
+ readonly '200': {
47
+ readonly description: "Device authorization request accepted.";
48
+ readonly content: {
49
+ readonly 'application/json': {
50
+ readonly schema: {
51
+ readonly type: "object";
52
+ readonly required: ["device_code", "user_code", "verification_uri", "expires_in"];
53
+ readonly properties: {
54
+ readonly device_code: import("ya-json-schema-types").ExpressiveJSONSchema;
55
+ readonly user_code: import("ya-json-schema-types").ExpressiveJSONSchema;
56
+ readonly verification_uri: {
57
+ readonly type: "string";
58
+ readonly format: "uri";
59
+ };
60
+ readonly verification_uri_complete: {
61
+ readonly type: "string";
62
+ readonly format: "uri";
63
+ };
64
+ readonly expires_in: {
65
+ readonly type: "number";
66
+ };
67
+ readonly interval: {
68
+ readonly type: "number";
69
+ readonly multipleOf: 1;
70
+ readonly minimum: 1;
71
+ };
72
+ readonly scope: import("ya-json-schema-types").ExpressiveJSONSchema;
73
+ };
74
+ };
75
+ };
76
+ };
77
+ };
78
+ readonly '400': {
79
+ readonly description: "OAuth2 device authorization error response, see https://datatracker.ietf.org/doc/html/rfc8628#section-3.1.";
80
+ readonly content: {
81
+ readonly 'application/json': {
82
+ readonly schema: {
83
+ readonly type: "object";
84
+ readonly required: ["error"];
85
+ readonly properties: {
86
+ readonly error: {
87
+ readonly type: "string";
88
+ readonly enum: ["invalid_request", "invalid_client", "unauthorized_client", "invalid_scope"];
89
+ };
90
+ readonly error_description: {
91
+ readonly type: "string";
92
+ };
93
+ readonly error_uri: {
94
+ readonly type: "string";
95
+ };
96
+ };
97
+ };
98
+ };
99
+ };
100
+ };
101
+ };
102
+ };
103
+ };
104
+ declare const _default: import("knifecycle").ServiceInitializer<{
105
+ OAUTH2: WhookOAuth2Options;
106
+ OAUTH2_DEVICE_AUTHORIZATION: WhookOAuth2DeviceAuthorizationOptions;
107
+ readClientGrants: WhookOAuth2ReadClientGrantsService;
108
+ oAuth2DeviceAuthorizationCode: Pick<WhookOAuth2DeviceAuthorizationCodeService, "create">;
109
+ time: TimeService;
110
+ log: LogService;
111
+ }, ({ body: { client_id: clientId, scope: demandedScope }, authenticationData: optionalAuthenticationData, }: {
112
+ body: {
113
+ client_id?: WhookOAuth2ClientId;
114
+ scope?: string;
115
+ };
116
+ authenticationData?: WhookAuthenticationData;
117
+ }) => Promise<{
118
+ status: number;
119
+ headers: {
120
+ 'Cache-Control': string;
121
+ Pragma: string;
122
+ };
123
+ body: {
124
+ scope?: string | undefined;
125
+ device_code: string;
126
+ user_code: string;
127
+ verification_uri: string;
128
+ verification_uri_complete: string;
129
+ expires_in: number;
130
+ interval: number;
131
+ };
132
+ }>>;
133
+ export default _default;