@whook/oauth2 27.0.2 → 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.
- package/README.md +44 -25
- package/dist/index.d.ts +11 -7
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +131 -15
- package/dist/index.test.js.map +1 -1
- package/dist/libs/clients.d.ts +17 -1
- package/dist/libs/clients.js +39 -6
- package/dist/libs/clients.js.map +1 -1
- package/dist/libs/clients.test.d.ts +1 -0
- package/dist/libs/clients.test.js +32 -0
- package/dist/libs/clients.test.js.map +1 -0
- package/dist/libs/errors.d.ts +24 -0
- package/dist/libs/errors.js +42 -0
- package/dist/libs/errors.js.map +1 -1
- package/dist/libs/verifier.d.ts +3 -3
- package/dist/libs/verifier.js +4 -3
- package/dist/libs/verifier.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.d.ts +19 -6
- package/dist/routes/getOAuth2Authorize.js +29 -14
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +3 -4
- package/dist/routes/getOAuth2WellKnownMetadata.js +19 -7
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +81 -0
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +0 -2
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +1 -2
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
- package/dist/routes/postAuthLogin.d.ts +1 -1
- package/dist/routes/postAuthLogin.js +1 -1
- package/dist/routes/postAuthLogin.js.map +1 -1
- package/dist/routes/postAuthRefresh.d.ts +1 -1
- package/dist/routes/postAuthRefresh.js +1 -1
- package/dist/routes/postAuthRefresh.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.d.ts +0 -3
- package/dist/routes/postOAuth2Acknowledge.js +1 -3
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2DeviceAcknowledge.d.ts +64 -0
- package/dist/routes/postOAuth2DeviceAcknowledge.js +84 -0
- package/dist/routes/postOAuth2DeviceAcknowledge.js.map +1 -0
- package/dist/routes/postOAuth2DeviceAcknowledge.test.d.ts +1 -0
- package/dist/routes/postOAuth2DeviceAcknowledge.test.js +369 -0
- package/dist/routes/postOAuth2DeviceAcknowledge.test.js.map +1 -0
- package/dist/routes/postOAuth2DeviceAuthorization.d.ts +133 -0
- package/dist/routes/postOAuth2DeviceAuthorization.js +177 -0
- package/dist/routes/postOAuth2DeviceAuthorization.js.map +1 -0
- package/dist/routes/postOAuth2DeviceAuthorization.test.d.ts +1 -0
- package/dist/routes/postOAuth2DeviceAuthorization.test.js +174 -0
- package/dist/routes/postOAuth2DeviceAuthorization.test.js.map +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +1 -6
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js +11 -14
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -1
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +47 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -1
- package/dist/routes/postOAuth2Token.d.ts +2 -7
- package/dist/routes/postOAuth2Token.js +2 -6
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/routes/postOAuth2Token.test.js +107 -0
- package/dist/routes/postOAuth2Token.test.js.map +1 -1
- package/dist/routes/schemas.d.ts +178 -0
- package/dist/routes/schemas.js +188 -0
- package/dist/routes/schemas.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +0 -70
- package/dist/services/oAuth2AuthorizationCodeGranter.js +7 -84
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -1
- package/dist/services/oAuth2AuthorizationRequests.js +4 -5
- package/dist/services/oAuth2AuthorizationRequests.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +1 -16
- package/dist/services/oAuth2ClientCredentialsGranter.js +7 -25
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.js +332 -0
- package/dist/services/oAuth2DeviceAuthorizationCodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2DeviceAuthorizationGranter.d.ts +54 -0
- package/dist/services/oAuth2DeviceAuthorizationGranter.js +67 -0
- package/dist/services/oAuth2DeviceAuthorizationGranter.js.map +1 -0
- package/dist/services/oAuth2Granters.js +0 -2
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +1 -22
- package/dist/services/oAuth2PasswordGranter.js +5 -30
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +1 -19
- package/dist/services/oAuth2RefreshTokenGranter.js +5 -28
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/package.json +4 -4
- package/src/index.test.ts +169 -26
- package/src/index.ts +21 -26
- package/src/libs/clients.test.ts +47 -0
- package/src/libs/clients.ts +60 -10
- package/src/libs/errors.ts +72 -0
- package/src/libs/verifier.ts +11 -3
- package/src/routes/__snapshots__/postOAuth2DeviceAcknowledge.test.ts.snap +5 -0
- package/src/routes/getOAuth2Authorize.ts +41 -26
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +96 -0
- package/src/routes/getOAuth2WellKnownMetadata.ts +24 -10
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +1 -3
- package/src/routes/postAuthLogin.ts +1 -1
- package/src/routes/postAuthRefresh.ts +1 -1
- package/src/routes/postOAuth2Acknowledge.ts +2 -4
- package/src/routes/postOAuth2DeviceAcknowledge.test.ts +408 -0
- package/src/routes/postOAuth2DeviceAcknowledge.ts +157 -0
- package/src/routes/postOAuth2DeviceAuthorization.test.ts +192 -0
- package/src/routes/postOAuth2DeviceAuthorization.ts +261 -0
- package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +59 -0
- package/src/routes/postOAuth2PushedAuthorizationRequest.ts +16 -22
- package/src/routes/postOAuth2Token.test.ts +119 -0
- package/src/routes/postOAuth2Token.ts +6 -16
- package/src/routes/schemas.ts +210 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +11 -94
- package/src/services/oAuth2AuthorizationRequests.ts +5 -5
- package/src/services/oAuth2ClientCredentialsGranter.ts +8 -27
- package/src/services/oAuth2DeviceAuthorizationCodeGranter.test.ts +372 -0
- package/src/services/oAuth2DeviceAuthorizationGranter.ts +194 -0
- package/src/services/oAuth2Granters.ts +0 -2
- package/src/services/oAuth2PasswordGranter.ts +7 -33
- package/src/services/oAuth2RefreshTokenGranter.ts +6 -31
- package/dist/libs/schemas.d.ts +0 -31
- package/dist/libs/schemas.js +0 -33
- package/dist/libs/schemas.js.map +0 -1
- package/src/libs/schemas.ts +0 -37
package/README.md
CHANGED
|
@@ -22,13 +22,15 @@ act on behalf of them.
|
|
|
22
22
|
|
|
23
23
|
The module provides:
|
|
24
24
|
|
|
25
|
-
-
|
|
26
|
-
(`getOAuth2Authorize`, `postOAuth2Token`, `postOAuth2Revoke
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
- 5 OAuth2 routes definitions implementing the OAuth2 standard endpoints
|
|
26
|
+
(`getOAuth2Authorize`, `postOAuth2Token`, `postOAuth2Revoke`,
|
|
27
|
+
`postOAuth2DeviceAuthorization`, `postOAuth2PushedAuthorizationRequest`) to be
|
|
28
|
+
used by OAuth2 client applications,
|
|
29
|
+
- 5 authentication endpoints to be used by the authorization server directly to
|
|
29
30
|
authenticate users (`postAuthLogin`, `postAuthRefresh`, `postAuthLogout`) and
|
|
30
|
-
acknowledge the client requests (`postOAuth2Acknowledge
|
|
31
|
-
|
|
31
|
+
acknowledge the client requests (`postOAuth2Acknowledge`,
|
|
32
|
+
`postOAuth2DeviceAcknowledge`),
|
|
33
|
+
- 6 OAuth2 services implementing the standard grant types. You can create your
|
|
32
34
|
own granter services to create additional grant types.
|
|
33
35
|
|
|
34
36
|
This module requires you to implement some services it relies on:
|
|
@@ -41,7 +43,40 @@ This module requires you to implement some services it relies on:
|
|
|
41
43
|
- `oAuth2ClientCredentialsService` aimed to check the `client_credential` grant
|
|
42
44
|
type with your own logic (if you use it),
|
|
43
45
|
- `oAuth2AuthorizationCodeService` aimed to check the `code` grant type with
|
|
44
|
-
your own logic (if you use it)
|
|
46
|
+
your own logic (if you use it),
|
|
47
|
+
- `oAuth2DeviceAuthorizationCode` aimed to create, acknowledge and check device
|
|
48
|
+
codes for the device authorization grant type (if you use it).
|
|
49
|
+
|
|
50
|
+
To enable the device authorization flow:
|
|
51
|
+
|
|
52
|
+
- implement `oAuth2DeviceAuthorizationCode` and allow
|
|
53
|
+
`urn:ietf:params:oauth:grant-type:device_code` in the device client's grants.
|
|
54
|
+
Its `acknowledge` method receives
|
|
55
|
+
`(acknowledged, userAuthenticationData, userCode, expectedClientId, acknowledgedScopes)`.
|
|
56
|
+
Before recording approval, denial, or scopes, it must load the stored
|
|
57
|
+
challenge for `userCode` and require its client ID to strictly equal
|
|
58
|
+
`expectedClientId`. Reject mismatches, including missing or empty stored
|
|
59
|
+
client IDs, with `E_OAUTH2_CLIENT_MISMATCH` and leave consent unchanged.
|
|
60
|
+
Existing implementations must add `expectedClientId` before the scopes
|
|
61
|
+
argument and enforce this check in the storage operation.
|
|
62
|
+
- provide `OAUTH2_DEVICE_AUTHORIZATION` with the user-facing `verificationURI`
|
|
63
|
+
and, optionally, the polling `interval` in seconds.
|
|
64
|
+
- override `postOAuth2DeviceAuthorization` and `postOAuth2DeviceAcknowledge` to
|
|
65
|
+
enable them in your application's environments. Configure optional client
|
|
66
|
+
authentication on both `postOAuth2DeviceAuthorization` and `postOAuth2Token`,
|
|
67
|
+
for example `security: [{ basicAuth: ['oauth2'] }, {}]`, so confidential
|
|
68
|
+
clients can authenticate and public clients can omit credentials. Protect
|
|
69
|
+
`postOAuth2DeviceAcknowledge` with your authentication frontend's security
|
|
70
|
+
mechanism, as described below for `postOAuth2Acknowledge`. Add the device
|
|
71
|
+
granter to the registry in `src/services/oAuth2Granters.ts`:
|
|
72
|
+
```ts
|
|
73
|
+
import { alsoInject, location } from 'knifecycle';
|
|
74
|
+
import { initOAuth2Granters } from '@whook/oauth2';
|
|
75
|
+
export default location(
|
|
76
|
+
alsoInject(['oAuth2DeviceAuthorizationGranter'], initOAuth2Granters),
|
|
77
|
+
import.meta.url,
|
|
78
|
+
);
|
|
79
|
+
```
|
|
45
80
|
|
|
46
81
|
## Quick setup
|
|
47
82
|
|
|
@@ -370,17 +405,8 @@ import {
|
|
|
370
405
|
initPostOAuth2Token,
|
|
371
406
|
postOAuth2TokenDefinition,
|
|
372
407
|
postOAuth2TokenTokenBodySchema,
|
|
373
|
-
postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
374
|
-
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
375
|
-
postOAuth2TokenCodeVerifierSchema,
|
|
376
|
-
postOAuth2TokenPasswordTokenRequestBodySchema,
|
|
377
|
-
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
378
408
|
} from '@whook/oauth2';
|
|
379
|
-
import {
|
|
380
|
-
type WhookAPISchemaDefinition,
|
|
381
|
-
type WhookRouteDefinition,
|
|
382
|
-
refersTo,
|
|
383
|
-
} from '@whook/whook';
|
|
409
|
+
import { type WhookRouteDefinition } from '@whook/whook';
|
|
384
410
|
|
|
385
411
|
export const definition = {
|
|
386
412
|
...postOAuth2TokenDefinition,
|
|
@@ -394,14 +420,7 @@ export const definition = {
|
|
|
394
420
|
},
|
|
395
421
|
} as const satisfies WhookRouteDefinition;
|
|
396
422
|
|
|
397
|
-
export {
|
|
398
|
-
postOAuth2TokenTokenBodySchema,
|
|
399
|
-
postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
400
|
-
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
401
|
-
postOAuth2TokenCodeVerifierSchema,
|
|
402
|
-
postOAuth2TokenPasswordTokenRequestBodySchema,
|
|
403
|
-
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
404
|
-
};
|
|
423
|
+
export { postOAuth2TokenTokenBodySchema };
|
|
405
424
|
|
|
406
425
|
export default initPostOAuth2Token;
|
|
407
426
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import initGetOAuth2Authorize, { definition as getOAuth2AuthorizeDefinition, responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter, clientIdParameter as getOAuth2AuthorizeClientIdParameter, redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter, scopeParameter as getOAuth2AuthorizeScopeParameter, stateParameter as getOAuth2AuthorizeStateParameter, requestURIParameter as getOAuth2AuthorizeRequestURIParameter,
|
|
1
|
+
import initGetOAuth2Authorize, { definition as getOAuth2AuthorizeDefinition, responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter, clientIdParameter as getOAuth2AuthorizeClientIdParameter, redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter, scopeParameter as getOAuth2AuthorizeScopeParameter, stateParameter as getOAuth2AuthorizeStateParameter, requestURIParameter as getOAuth2AuthorizeRequestURIParameter, codeChallengeParameter as getOAuth2AuthorizeCodeChallengeParameter, codeChallengeMethodParameter as getOAuth2AuthorizeCodeChallengeMethodParameter } from './routes/getOAuth2Authorize.js';
|
|
2
2
|
import initPostOAuth2Acknowledge, { definition as postOAuth2AcknowledgeDefinition } from './routes/postOAuth2Acknowledge.js';
|
|
3
|
-
import initPostOAuth2Token, { definition as postOAuth2TokenDefinition,
|
|
4
|
-
import initPostOAuth2PushedAuthorizationRequest, { definition as postOAuth2PushedAuthorizationRequestDefinition, pushedAuthorizationRequestBodySchema as postOAuth2PushedAuthorizationRequestBodySchema
|
|
5
|
-
import
|
|
3
|
+
import initPostOAuth2Token, { definition as postOAuth2TokenDefinition, tokenBodySchema as postOAuth2TokenTokenBodySchema } from './routes/postOAuth2Token.js';
|
|
4
|
+
import initPostOAuth2PushedAuthorizationRequest, { definition as postOAuth2PushedAuthorizationRequestDefinition, pushedAuthorizationRequestBodySchema as postOAuth2PushedAuthorizationRequestBodySchema } from './routes/postOAuth2PushedAuthorizationRequest.js';
|
|
5
|
+
import initPostOAuth2DeviceAuthorization, { definition as postOAuth2DeviceAuthorizationDefinition, deviceAuthorizationRequestBodySchema as postOAuth2DeviceAuthorizationRequestBodySchema, userCodeSchema as postOAuth2DeviceAuthorizationUserCodeSchema } from './routes/postOAuth2DeviceAuthorization.js';
|
|
6
|
+
import initPostOAuth2DeviceAcknowledge, { definition as postOAuth2DeviceAcknowledgeDefinition, deviceAcknowledgeRequestBodySchema as postOAuth2DeviceAcknowledgeRequestBodySchema } from './routes/postOAuth2DeviceAcknowledge.js';
|
|
7
|
+
import initGetOAuth2WellKnown, { definition as getOAuth2WellKnownDefinition, endpointAuthenticationMethodsSchema as getOAuth2WellKnownEndpointAuthenticationMethodsSchema, jsonWebAlgorithmsSchema as getOAuth2WellKnownJsonWebAlgorithmsSchema, jsonWebEncryptionsSchema as getOAuth2WellKnownJsonWebEncryptionsSchema, httpsProtocolURISchema as getOAuth2WellKnownHTTPSProtocolURISchema, oAuth2MetadataSchema as getOAuth2WellKnownOAuth2MetadataSchema } from './routes/getOAuth2WellKnownMetadata.js';
|
|
6
8
|
import initGetOAuth2WellKnownProtectedResource, { definition as getOAuth2WellKnownProtectedResourceDefinition, bearerMethodSchema as getOAuth2WellKnownProtectedResourceBearerMethodSchema, oAuth2ProtectedResourceMetadataSchema as getOAuth2WellKnownProtectedResourceSchema } from './routes/getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
7
9
|
import initPostOAuth2Revoke, { definition as postOAuth2RevokeDefinition, tokenTypeHintSchema as postOAuth2RevokeTokenTypeHintSchema, revokeTokenRequestBodySchema as postOAuth2RevokeTokenRequestBodySchema } from './routes/postOAuth2Revoke.js';
|
|
8
10
|
export type * from './routes/postOAuth2Revoke.js';
|
|
@@ -18,6 +20,8 @@ import initOAuth2ImplicitGranter from './services/oAuth2ImplicitGranter.js';
|
|
|
18
20
|
export type * from './services/oAuth2ImplicitGranter.js';
|
|
19
21
|
import initOAuth2AuthorizationCodeGranter from './services/oAuth2AuthorizationCodeGranter.js';
|
|
20
22
|
export type * from './services/oAuth2AuthorizationCodeGranter.js';
|
|
23
|
+
import initOAuth2DeviceAuthorizationGranter from './services/oAuth2DeviceAuthorizationGranter.js';
|
|
24
|
+
export type * from './services/oAuth2DeviceAuthorizationGranter.js';
|
|
21
25
|
import initPostAuthLogin, { definition as postAuthLoginDefinition } from './routes/postAuthLogin.js';
|
|
22
26
|
import initPostAuthLogout, { definition as postAuthLogoutDefinition } from './routes/postAuthLogout.js';
|
|
23
27
|
import initPostAuthRefresh, { authCookieHeaderParameter, definition as postAuthRefreshDefinition } from './routes/postAuthRefresh.js';
|
|
@@ -28,8 +32,8 @@ export type * from './services/authCookies.js';
|
|
|
28
32
|
import initOAuth2AuthorizationRequests from './services/oAuth2AuthorizationRequests.js';
|
|
29
33
|
export * from './services/oAuth2AuthorizationRequests.js';
|
|
30
34
|
export type * from './services/oAuth2AuthorizationRequests.js';
|
|
31
|
-
export * from './
|
|
32
|
-
export type * from './
|
|
35
|
+
export * from './routes/schemas.js';
|
|
36
|
+
export type * from './routes/schemas.js';
|
|
33
37
|
export * from './libs/errors.js';
|
|
34
38
|
export type * from './libs/errors.js';
|
|
35
39
|
export * from './libs/scopes.js';
|
|
@@ -45,4 +49,4 @@ declare module 'yerror' {
|
|
|
45
49
|
E_UNEXPECTED: unknown[];
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter,
|
|
52
|
+
export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodParameter, initGetOAuth2WellKnown, getOAuth2WellKnownDefinition, getOAuth2WellKnownEndpointAuthenticationMethodsSchema, getOAuth2WellKnownJsonWebAlgorithmsSchema, getOAuth2WellKnownJsonWebEncryptionsSchema, getOAuth2WellKnownHTTPSProtocolURISchema, getOAuth2WellKnownOAuth2MetadataSchema, initGetOAuth2WellKnownProtectedResource, getOAuth2WellKnownProtectedResourceDefinition, getOAuth2WellKnownProtectedResourceBearerMethodSchema, getOAuth2WellKnownProtectedResourceSchema, initPostOAuth2Revoke, postOAuth2RevokeDefinition, postOAuth2RevokeTokenTypeHintSchema, postOAuth2RevokeTokenRequestBodySchema, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenDefinition, postOAuth2TokenTokenBodySchema, initPostOAuth2PushedAuthorizationRequest, postOAuth2PushedAuthorizationRequestDefinition, postOAuth2PushedAuthorizationRequestBodySchema, initPostOAuth2DeviceAcknowledge, postOAuth2DeviceAcknowledgeDefinition, postOAuth2DeviceAcknowledgeRequestBodySchema, initPostOAuth2DeviceAuthorization, postOAuth2DeviceAuthorizationDefinition, postOAuth2DeviceAuthorizationRequestBodySchema, postOAuth2DeviceAuthorizationUserCodeSchema, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2ImplicitGranter, initOAuth2DeviceAuthorizationGranter, authCookieHeaderParameter, initPostAuthLogin, postAuthLoginDefinition, initPostAuthLogout, postAuthLogoutDefinition, initPostAuthRefresh, postAuthRefreshDefinition, initAuthCookiesService, initOAuth2AuthorizationRequests, };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import initGetOAuth2Authorize, { definition as getOAuth2AuthorizeDefinition, responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter, clientIdParameter as getOAuth2AuthorizeClientIdParameter, redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter, scopeParameter as getOAuth2AuthorizeScopeParameter, stateParameter as getOAuth2AuthorizeStateParameter, requestURIParameter as getOAuth2AuthorizeRequestURIParameter,
|
|
1
|
+
import initGetOAuth2Authorize, { definition as getOAuth2AuthorizeDefinition, responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter, clientIdParameter as getOAuth2AuthorizeClientIdParameter, redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter, scopeParameter as getOAuth2AuthorizeScopeParameter, stateParameter as getOAuth2AuthorizeStateParameter, requestURIParameter as getOAuth2AuthorizeRequestURIParameter, codeChallengeParameter as getOAuth2AuthorizeCodeChallengeParameter, codeChallengeMethodParameter as getOAuth2AuthorizeCodeChallengeMethodParameter, } from './routes/getOAuth2Authorize.js';
|
|
2
2
|
import initPostOAuth2Acknowledge, { definition as postOAuth2AcknowledgeDefinition, } from './routes/postOAuth2Acknowledge.js';
|
|
3
|
-
import initPostOAuth2Token, { definition as postOAuth2TokenDefinition,
|
|
4
|
-
import initPostOAuth2PushedAuthorizationRequest, { definition as postOAuth2PushedAuthorizationRequestDefinition, pushedAuthorizationRequestBodySchema as postOAuth2PushedAuthorizationRequestBodySchema,
|
|
5
|
-
import
|
|
3
|
+
import initPostOAuth2Token, { definition as postOAuth2TokenDefinition, tokenBodySchema as postOAuth2TokenTokenBodySchema, } from './routes/postOAuth2Token.js';
|
|
4
|
+
import initPostOAuth2PushedAuthorizationRequest, { definition as postOAuth2PushedAuthorizationRequestDefinition, pushedAuthorizationRequestBodySchema as postOAuth2PushedAuthorizationRequestBodySchema, } from './routes/postOAuth2PushedAuthorizationRequest.js';
|
|
5
|
+
import initPostOAuth2DeviceAuthorization, { definition as postOAuth2DeviceAuthorizationDefinition, deviceAuthorizationRequestBodySchema as postOAuth2DeviceAuthorizationRequestBodySchema, userCodeSchema as postOAuth2DeviceAuthorizationUserCodeSchema, } from './routes/postOAuth2DeviceAuthorization.js';
|
|
6
|
+
import initPostOAuth2DeviceAcknowledge, { definition as postOAuth2DeviceAcknowledgeDefinition, deviceAcknowledgeRequestBodySchema as postOAuth2DeviceAcknowledgeRequestBodySchema, } from './routes/postOAuth2DeviceAcknowledge.js';
|
|
7
|
+
import initGetOAuth2WellKnown, { definition as getOAuth2WellKnownDefinition, endpointAuthenticationMethodsSchema as getOAuth2WellKnownEndpointAuthenticationMethodsSchema, jsonWebAlgorithmsSchema as getOAuth2WellKnownJsonWebAlgorithmsSchema, jsonWebEncryptionsSchema as getOAuth2WellKnownJsonWebEncryptionsSchema, httpsProtocolURISchema as getOAuth2WellKnownHTTPSProtocolURISchema, oAuth2MetadataSchema as getOAuth2WellKnownOAuth2MetadataSchema, } from './routes/getOAuth2WellKnownMetadata.js';
|
|
6
8
|
import initGetOAuth2WellKnownProtectedResource, { definition as getOAuth2WellKnownProtectedResourceDefinition, bearerMethodSchema as getOAuth2WellKnownProtectedResourceBearerMethodSchema, oAuth2ProtectedResourceMetadataSchema as getOAuth2WellKnownProtectedResourceSchema, } from './routes/getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
7
9
|
import initPostOAuth2Revoke, { definition as postOAuth2RevokeDefinition, tokenTypeHintSchema as postOAuth2RevokeTokenTypeHintSchema, revokeTokenRequestBodySchema as postOAuth2RevokeTokenRequestBodySchema, } from './routes/postOAuth2Revoke.js';
|
|
8
10
|
import initOAuth2Granters from './services/oAuth2Granters.js';
|
|
@@ -11,6 +13,7 @@ import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter.js';
|
|
|
11
13
|
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter.js';
|
|
12
14
|
import initOAuth2ImplicitGranter from './services/oAuth2ImplicitGranter.js';
|
|
13
15
|
import initOAuth2AuthorizationCodeGranter from './services/oAuth2AuthorizationCodeGranter.js';
|
|
16
|
+
import initOAuth2DeviceAuthorizationGranter from './services/oAuth2DeviceAuthorizationGranter.js';
|
|
14
17
|
import initPostAuthLogin, { definition as postAuthLoginDefinition, } from './routes/postAuthLogin.js';
|
|
15
18
|
import initPostAuthLogout, { definition as postAuthLogoutDefinition, } from './routes/postAuthLogout.js';
|
|
16
19
|
import initPostAuthRefresh, { authCookieHeaderParameter, definition as postAuthRefreshDefinition, } from './routes/postAuthRefresh.js';
|
|
@@ -18,11 +21,11 @@ import initAuthCookiesService from './services/authCookies.js';
|
|
|
18
21
|
export * from './services/authCookies.js';
|
|
19
22
|
import initOAuth2AuthorizationRequests from './services/oAuth2AuthorizationRequests.js';
|
|
20
23
|
export * from './services/oAuth2AuthorizationRequests.js';
|
|
21
|
-
export * from './
|
|
24
|
+
export * from './routes/schemas.js';
|
|
22
25
|
export * from './libs/errors.js';
|
|
23
26
|
export * from './libs/scopes.js';
|
|
24
27
|
export * from './libs/grants.js';
|
|
25
28
|
export * from './libs/redirectURI.js';
|
|
26
29
|
export * from './libs/verifier.js';
|
|
27
|
-
export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter,
|
|
30
|
+
export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodParameter, initGetOAuth2WellKnown, getOAuth2WellKnownDefinition, getOAuth2WellKnownEndpointAuthenticationMethodsSchema, getOAuth2WellKnownJsonWebAlgorithmsSchema, getOAuth2WellKnownJsonWebEncryptionsSchema, getOAuth2WellKnownHTTPSProtocolURISchema, getOAuth2WellKnownOAuth2MetadataSchema, initGetOAuth2WellKnownProtectedResource, getOAuth2WellKnownProtectedResourceDefinition, getOAuth2WellKnownProtectedResourceBearerMethodSchema, getOAuth2WellKnownProtectedResourceSchema, initPostOAuth2Revoke, postOAuth2RevokeDefinition, postOAuth2RevokeTokenTypeHintSchema, postOAuth2RevokeTokenRequestBodySchema, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenDefinition, postOAuth2TokenTokenBodySchema, initPostOAuth2PushedAuthorizationRequest, postOAuth2PushedAuthorizationRequestDefinition, postOAuth2PushedAuthorizationRequestBodySchema, initPostOAuth2DeviceAcknowledge, postOAuth2DeviceAcknowledgeDefinition, postOAuth2DeviceAcknowledgeRequestBodySchema, initPostOAuth2DeviceAuthorization, postOAuth2DeviceAuthorizationDefinition, postOAuth2DeviceAuthorizationRequestBodySchema, postOAuth2DeviceAuthorizationUserCodeSchema, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2ImplicitGranter, initOAuth2DeviceAuthorizationGranter, authCookieHeaderParameter, initPostAuthLogin, postAuthLoginDefinition, initPostAuthLogout, postAuthLogoutDefinition, initPostAuthRefresh, postAuthRefreshDefinition, initAuthCookiesService, initOAuth2AuthorizationRequests, };
|
|
28
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,EAAE,EAC7B,UAAU,IAAI,4BAA4B,EAC1C,qBAAqB,IAAI,uCAAuC,EAChE,iBAAiB,IAAI,mCAAmC,EACxD,oBAAoB,IAAI,sCAAsC,EAC9D,cAAc,IAAI,gCAAgC,EAClD,cAAc,IAAI,gCAAgC,EAClD,mBAAmB,IAAI,qCAAqC,EAC5D,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/dist/index.test.js
CHANGED
|
@@ -6,7 +6,7 @@ import { alsoInject, constant, initializer } from 'knifecycle';
|
|
|
6
6
|
import axios from 'axios';
|
|
7
7
|
import { YError } from 'yerror';
|
|
8
8
|
import { BEARER as BEARER_MECHANISM, BASIC as BASIC_MECHANISM, } from 'http-auth-utils';
|
|
9
|
-
import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter,
|
|
9
|
+
import { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeCodeChallengeParameter, getOAuth2AuthorizeCodeChallengeMethodParameter, clientIdSchema, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, getOAuth2AuthorizeRequestURIParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, initPostOAuth2DeviceAuthorization, postOAuth2TokenDefinition, postOAuth2DeviceAuthorizationDefinition, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2AuthorizationCodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2ImplicitGranter, initOAuth2DeviceAuthorizationGranter, postOAuth2TokenTokenBodySchema, postOAuth2PushedAuthorizationRequestBodySchema, postOAuth2PushedAuthorizationRequestDefinition, initPostOAuth2PushedAuthorizationRequest, postOAuth2DeviceAuthorizationRequestBodySchema, postOAuth2DeviceAuthorizationUserCodeSchema, authorizationCodeSchema, scopeSchema, requestURISchema, codeChallengeSchema, codeChallengeMethodSchema, authorizationCodeTokenRequestBodySchema, passwordTokenRequestBodySchema, clientCredentialsTokenRequestBodySchema, refreshTokenRequestBodySchema, deviceAuthorizationTokenRequestBodySchema, codeVerifierSchema, deviceCodeSchema, plainCodeChallengeMethodSchema, s256CodeChallengeMethodSchema, } from './index.js';
|
|
10
10
|
describe('OAuth2 server', () => {
|
|
11
11
|
const BASE_PATH = '/v1';
|
|
12
12
|
const PORT = 4444;
|
|
@@ -59,6 +59,16 @@ describe('OAuth2 server', () => {
|
|
|
59
59
|
],
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
|
+
[`${BASE_PATH}${postOAuth2DeviceAuthorizationDefinition.path}`]: {
|
|
63
|
+
[postOAuth2DeviceAuthorizationDefinition.method]: {
|
|
64
|
+
...postOAuth2DeviceAuthorizationDefinition.operation,
|
|
65
|
+
security: [
|
|
66
|
+
{
|
|
67
|
+
basicAuth: ['oauth'],
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
},
|
|
62
72
|
},
|
|
63
73
|
components: {
|
|
64
74
|
securitySchemes: {
|
|
@@ -87,18 +97,26 @@ describe('OAuth2 server', () => {
|
|
|
87
97
|
[name]: parameter,
|
|
88
98
|
}), {}),
|
|
89
99
|
schemas: [
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
clientIdSchema,
|
|
101
|
+
scopeSchema,
|
|
102
|
+
requestURISchema,
|
|
103
|
+
codeChallengeSchema,
|
|
104
|
+
plainCodeChallengeMethodSchema,
|
|
105
|
+
s256CodeChallengeMethodSchema,
|
|
106
|
+
codeChallengeMethodSchema,
|
|
107
|
+
authorizationCodeTokenRequestBodySchema,
|
|
108
|
+
passwordTokenRequestBodySchema,
|
|
109
|
+
clientCredentialsTokenRequestBodySchema,
|
|
110
|
+
refreshTokenRequestBodySchema,
|
|
111
|
+
deviceAuthorizationTokenRequestBodySchema,
|
|
112
|
+
postOAuth2DeviceAuthorizationRequestBodySchema,
|
|
113
|
+
postOAuth2DeviceAuthorizationUserCodeSchema,
|
|
114
|
+
deviceCodeSchema,
|
|
98
115
|
postOAuth2TokenTokenBodySchema,
|
|
99
|
-
|
|
116
|
+
codeVerifierSchema,
|
|
100
117
|
postOAuth2PushedAuthorizationRequestBodySchema,
|
|
101
|
-
|
|
118
|
+
requestURISchema,
|
|
119
|
+
authorizationCodeSchema,
|
|
102
120
|
].reduce((schemasHash, { name, schema }) => ({
|
|
103
121
|
...schemasHash,
|
|
104
122
|
[name]: schema,
|
|
@@ -134,6 +152,13 @@ describe('OAuth2 server', () => {
|
|
|
134
152
|
allowedScopes: ['user', 'oauth'],
|
|
135
153
|
rootClientId: 'the_root_client_id',
|
|
136
154
|
};
|
|
155
|
+
const OAUTH2_PAR = {
|
|
156
|
+
mode: 'enabled',
|
|
157
|
+
};
|
|
158
|
+
const OAUTH2_DEVICE_AUTHORIZATION = {
|
|
159
|
+
verificationURI: 'https://auth.example.com/device',
|
|
160
|
+
interval: 8,
|
|
161
|
+
};
|
|
137
162
|
const authentication = {
|
|
138
163
|
check: jest.fn(),
|
|
139
164
|
};
|
|
@@ -154,6 +179,10 @@ describe('OAuth2 server', () => {
|
|
|
154
179
|
create: jest.fn(),
|
|
155
180
|
check: jest.fn(),
|
|
156
181
|
};
|
|
182
|
+
const oAuth2DeviceAuthorizationCode = {
|
|
183
|
+
create: jest.fn(),
|
|
184
|
+
check: jest.fn(),
|
|
185
|
+
};
|
|
157
186
|
const oAuth2Password = {
|
|
158
187
|
check: jest.fn(),
|
|
159
188
|
};
|
|
@@ -184,9 +213,8 @@ describe('OAuth2 server', () => {
|
|
|
184
213
|
$.register(alsoInject(['wrapRouteHandlerWithAuthorization'], initRoutesWrappers));
|
|
185
214
|
// OAuth2 Specifics
|
|
186
215
|
$.register(constant('OAUTH2', OAUTH2));
|
|
187
|
-
$.register(constant('
|
|
188
|
-
|
|
189
|
-
}));
|
|
216
|
+
$.register(constant('OAUTH2_DEVICE_AUTHORIZATION', OAUTH2_DEVICE_AUTHORIZATION));
|
|
217
|
+
$.register(constant('OAUTH2_PAR', OAUTH2_PAR));
|
|
190
218
|
$.register(constant('ERRORS_DESCRIPTORS', {
|
|
191
219
|
...DEFAULT_ERRORS_DESCRIPTORS,
|
|
192
220
|
...AUTHORIZATION_ERRORS_DESCRIPTORS,
|
|
@@ -197,6 +225,7 @@ describe('OAuth2 server', () => {
|
|
|
197
225
|
'postOAuth2Acknowledge',
|
|
198
226
|
'postOAuth2Token',
|
|
199
227
|
'postOAuth2PushedAuthorizationRequest',
|
|
228
|
+
'postOAuth2DeviceAuthorization',
|
|
200
229
|
], initRoutesHandlers));
|
|
201
230
|
$.register(constant('authentication', authentication));
|
|
202
231
|
$.register(constant('readClientGrants', readClientGrants));
|
|
@@ -204,18 +233,25 @@ describe('OAuth2 server', () => {
|
|
|
204
233
|
$.register(constant('oAuth2AccessToken', oAuth2AccessToken));
|
|
205
234
|
$.register(constant('oAuth2RefreshToken', oAuth2RefreshToken));
|
|
206
235
|
$.register(constant('oAuth2AuthorizationCode', oAuth2AuthorizationCode));
|
|
236
|
+
$.register(constant('oAuth2DeviceAuthorizationCode', oAuth2DeviceAuthorizationCode));
|
|
207
237
|
$.register(constant('oAuth2Password', oAuth2Password));
|
|
208
238
|
[
|
|
209
239
|
initGetOAuth2Authorize,
|
|
210
240
|
initPostOAuth2Acknowledge,
|
|
211
241
|
initPostOAuth2Token,
|
|
212
|
-
|
|
242
|
+
initPostOAuth2DeviceAuthorization,
|
|
243
|
+
alsoInject([
|
|
244
|
+
'oAuth2DeviceAuthorizationGranter',
|
|
245
|
+
'oAuth2PasswordGranter',
|
|
246
|
+
'oAuth2ImplicitGranter',
|
|
247
|
+
], initOAuth2Granters),
|
|
213
248
|
initOAuth2ClientCredentialsGranter,
|
|
214
249
|
initOAuth2AuthorizationCodeGranter,
|
|
215
250
|
initOAuth2PasswordGranter,
|
|
216
251
|
initOAuth2RefreshTokenGranter,
|
|
217
252
|
initOAuth2ImplicitGranter,
|
|
218
253
|
initPostOAuth2PushedAuthorizationRequest,
|
|
254
|
+
initOAuth2DeviceAuthorizationGranter,
|
|
219
255
|
].forEach((handlerInitializer) => $.register(handlerInitializer));
|
|
220
256
|
return $;
|
|
221
257
|
}
|
|
@@ -247,6 +283,8 @@ describe('OAuth2 server', () => {
|
|
|
247
283
|
oAuth2RefreshToken.check,
|
|
248
284
|
oAuth2AuthorizationCode.check,
|
|
249
285
|
oAuth2AuthorizationCode.create,
|
|
286
|
+
oAuth2DeviceAuthorizationCode.create,
|
|
287
|
+
oAuth2DeviceAuthorizationCode.check,
|
|
250
288
|
oAuth2Password.check,
|
|
251
289
|
readClientGrants,
|
|
252
290
|
authentication.check,
|
|
@@ -2209,5 +2247,83 @@ describe('OAuth2 server', () => {
|
|
|
2209
2247
|
`);
|
|
2210
2248
|
});
|
|
2211
2249
|
});
|
|
2250
|
+
describe('with the device authorization flow', () => {
|
|
2251
|
+
test('should return HTTP 400 access_denied for a denied device poll', async () => {
|
|
2252
|
+
authentication.check.mockResolvedValueOnce({
|
|
2253
|
+
clientId: 'the_client_id',
|
|
2254
|
+
scopes: ['oauth'],
|
|
2255
|
+
userId: 'auth_user_id',
|
|
2256
|
+
});
|
|
2257
|
+
readClientGrants.mockResolvedValueOnce({
|
|
2258
|
+
allowedGrantTypes: ['urn:ietf:params:oauth:grant-type:device_code'],
|
|
2259
|
+
allowedScopes: ['user'],
|
|
2260
|
+
allowedRedirectURIS: [],
|
|
2261
|
+
isPublicClient: false,
|
|
2262
|
+
authenticationData: {
|
|
2263
|
+
clientId: 'the_client_id',
|
|
2264
|
+
scopes: ['user'],
|
|
2265
|
+
userId: 'client_user_id',
|
|
2266
|
+
},
|
|
2267
|
+
});
|
|
2268
|
+
oAuth2DeviceAuthorizationCode.check.mockRejectedValueOnce(new YError('E_OAUTH2_ACCESS_DENIED', ['the_client_id']));
|
|
2269
|
+
const { status, data } = await axios({
|
|
2270
|
+
method: 'post',
|
|
2271
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2TokenDefinition.path}`,
|
|
2272
|
+
headers: {
|
|
2273
|
+
authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
|
|
2274
|
+
},
|
|
2275
|
+
data: {
|
|
2276
|
+
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
2277
|
+
device_code: 'a_device_code',
|
|
2278
|
+
},
|
|
2279
|
+
validateStatus: () => true,
|
|
2280
|
+
});
|
|
2281
|
+
expect(status).toBe(400);
|
|
2282
|
+
expect(data).toMatchObject({ error: 'access_denied' });
|
|
2283
|
+
expect(oAuth2DeviceAuthorizationCode.check).toHaveBeenCalledTimes(1);
|
|
2284
|
+
expect(oAuth2AccessToken.create).not.toHaveBeenCalled();
|
|
2285
|
+
expect(oAuth2RefreshToken.create).not.toHaveBeenCalled();
|
|
2286
|
+
expect(OAUTH2_ERRORS_DESCRIPTORS.E_OAUTH2_ACCESS_DENIED).toMatchObject({
|
|
2287
|
+
code: 'access_denied',
|
|
2288
|
+
status: 403,
|
|
2289
|
+
});
|
|
2290
|
+
});
|
|
2291
|
+
test.each([
|
|
2292
|
+
['application/json', { client_id: '' }],
|
|
2293
|
+
['application/x-www-form-urlencoded', 'client_id='],
|
|
2294
|
+
])('should reject an empty client ID in %s', async (contentType, body) => {
|
|
2295
|
+
authentication.check.mockResolvedValueOnce({
|
|
2296
|
+
clientId: 'the_client_id',
|
|
2297
|
+
scopes: ['oauth'],
|
|
2298
|
+
userId: 'auth_user_id',
|
|
2299
|
+
});
|
|
2300
|
+
const { status, data } = await axios({
|
|
2301
|
+
method: 'post',
|
|
2302
|
+
url: `http://${HOST}:${PORT}${BASE_PATH}${postOAuth2DeviceAuthorizationDefinition.path}`,
|
|
2303
|
+
headers: {
|
|
2304
|
+
authorization: `basic ${Buffer.from('ali:open_sesame').toString('base64')}`,
|
|
2305
|
+
'content-type': contentType,
|
|
2306
|
+
},
|
|
2307
|
+
data: body,
|
|
2308
|
+
validateStatus: () => true,
|
|
2309
|
+
});
|
|
2310
|
+
expect(status).toBe(400);
|
|
2311
|
+
expect(data).toMatchObject({
|
|
2312
|
+
error: 'bad_request',
|
|
2313
|
+
error_description: 'The request body does not match the schema',
|
|
2314
|
+
error_params: [
|
|
2315
|
+
{ client_id: '' },
|
|
2316
|
+
expect.arrayContaining([
|
|
2317
|
+
expect.objectContaining({
|
|
2318
|
+
instancePath: '/client_id',
|
|
2319
|
+
keyword: 'minLength',
|
|
2320
|
+
}),
|
|
2321
|
+
]),
|
|
2322
|
+
],
|
|
2323
|
+
});
|
|
2324
|
+
expect(readClientGrants).not.toHaveBeenCalled();
|
|
2325
|
+
expect(oAuth2DeviceAuthorizationCode.create).not.toHaveBeenCalled();
|
|
2326
|
+
});
|
|
2327
|
+
});
|
|
2212
2328
|
});
|
|
2213
2329
|
//# sourceMappingURL=index.test.js.map
|