@whook/oauth2 25.2.0 → 26.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.
- package/README.md +147 -98
- package/dist/index.d.ts +30 -11
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1258 -399
- package/dist/index.test.js.map +1 -1
- package/dist/libs/clients.d.ts +2 -0
- package/dist/libs/clients.js +13 -0
- package/dist/libs/clients.js.map +1 -0
- package/dist/libs/errors.d.ts +113 -0
- package/dist/libs/errors.js +178 -0
- package/dist/libs/errors.js.map +1 -0
- package/dist/libs/grants.d.ts +2 -0
- package/dist/libs/grants.js +10 -0
- package/dist/libs/grants.js.map +1 -0
- package/dist/libs/redirectURI.d.ts +7 -0
- package/dist/libs/redirectURI.js +78 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +23 -0
- package/dist/libs/schemas.js +25 -0
- package/dist/libs/schemas.js.map +1 -0
- package/dist/libs/scopes.d.ts +16 -0
- package/dist/libs/scopes.js +37 -0
- package/dist/libs/scopes.js.map +1 -1
- package/dist/libs/utils.d.ts +2 -0
- package/dist/libs/utils.js +17 -0
- package/dist/libs/utils.js.map +1 -0
- package/dist/libs/verifier.d.ts +7 -0
- package/dist/libs/verifier.js +37 -0
- package/dist/libs/verifier.js.map +1 -0
- package/dist/libs/verifier.test.js +21 -0
- package/dist/libs/verifier.test.js.map +1 -0
- package/dist/routes/getOAuth2Authorize.d.ts +13 -50
- package/dist/routes/getOAuth2Authorize.js +60 -86
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +147 -68
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js +20 -9
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +38 -37
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
- package/dist/routes/postAuthLogin.d.ts +14 -9
- package/dist/routes/postAuthLogin.js +10 -5
- package/dist/routes/postAuthLogin.js.map +1 -1
- package/dist/routes/postAuthLogin.test.js +79 -55
- package/dist/routes/postAuthLogin.test.js.map +1 -1
- package/dist/routes/postAuthLogout.d.ts +5 -2
- package/dist/routes/postAuthLogout.js +12 -7
- package/dist/routes/postAuthLogout.js.map +1 -1
- package/dist/routes/postAuthLogout.test.js +35 -17
- package/dist/routes/postAuthLogout.test.js.map +1 -1
- package/dist/routes/postAuthRefresh.d.ts +14 -9
- package/dist/routes/postAuthRefresh.js +10 -6
- package/dist/routes/postAuthRefresh.js.map +1 -1
- package/dist/routes/postAuthRefresh.test.js +90 -59
- package/dist/routes/postAuthRefresh.test.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.d.ts +20 -10
- package/dist/routes/postOAuth2Acknowledge.js +54 -38
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +137 -72
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/routes/postOAuth2Revoke.d.ts +99 -0
- package/dist/routes/postOAuth2Revoke.js +102 -0
- package/dist/routes/postOAuth2Revoke.js.map +1 -0
- package/dist/routes/postOAuth2Revoke.test.d.ts +1 -0
- package/dist/routes/postOAuth2Revoke.test.js +161 -0
- package/dist/routes/postOAuth2Revoke.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +35 -108
- package/dist/routes/postOAuth2Token.js +53 -114
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/routes/postOAuth2Token.test.js +493 -61
- package/dist/routes/postOAuth2Token.test.js.map +1 -1
- package/dist/services/authCookies.d.ts +9 -13
- package/dist/services/authCookies.js +1 -1
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +129 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +221 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +474 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +28 -12
- package/dist/services/oAuth2ClientCredentialsGranter.js +39 -21
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js +265 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +81 -86
- package/dist/services/oAuth2Granters.js +2 -67
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2ImplicitGranter.d.ts +38 -0
- package/dist/services/oAuth2ImplicitGranter.js +72 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +727 -0
- package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +43 -10
- package/dist/services/oAuth2PasswordGranter.js +53 -18
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.test.d.ts +1 -0
- package/dist/services/oAuth2PasswordGranter.test.js +455 -0
- package/dist/services/oAuth2PasswordGranter.test.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +42 -9
- package/dist/services/oAuth2RefreshTokenGranter.js +60 -21
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.test.d.ts +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js +403 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js.map +1 -0
- package/package.json +11 -11
- package/src/index.test.ts +1314 -404
- package/src/index.ts +46 -53
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +325 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +120 -0
- package/src/libs/schemas.ts +27 -0
- package/src/libs/scopes.ts +49 -0
- package/src/libs/utils.ts +24 -0
- package/src/libs/verifier.test.ts +37 -0
- package/src/libs/verifier.ts +57 -0
- package/src/routes/getOAuth2Authorize.test.ts +179 -96
- package/src/routes/getOAuth2Authorize.ts +97 -124
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +58 -60
- package/src/routes/getOAuth2WellKnownMetadata.ts +26 -11
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +4 -6
- package/src/routes/postAuthLogin.test.ts +86 -57
- package/src/routes/postAuthLogin.ts +24 -14
- package/src/routes/postAuthLogout.test.ts +42 -18
- package/src/routes/postAuthLogout.ts +22 -8
- package/src/routes/postAuthRefresh.test.ts +98 -61
- package/src/routes/postAuthRefresh.ts +25 -13
- package/src/routes/postOAuth2Acknowledge.test.ts +169 -110
- package/src/routes/postOAuth2Acknowledge.ts +101 -61
- package/src/routes/postOAuth2Revoke.test.ts +179 -0
- package/src/routes/postOAuth2Revoke.ts +156 -0
- package/src/routes/postOAuth2Token.test.ts +570 -108
- package/src/routes/postOAuth2Token.ts +92 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +16 -18
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +564 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +388 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +101 -195
- package/src/services/oAuth2ImplicitGranter.test.ts +811 -0
- package/src/services/oAuth2ImplicitGranter.ts +163 -0
- package/src/services/oAuth2PasswordGranter.test.ts +493 -0
- package/src/services/oAuth2PasswordGranter.ts +116 -40
- package/src/services/oAuth2RefreshTokenGranter.test.ts +441 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +118 -51
- package/src/types.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +0 -41
- package/dist/services/oAuth2CodeGranter.js +0 -105
- package/dist/services/oAuth2CodeGranter.js.map +0 -1
- package/dist/services/oAuth2CodeGranter.test.js +0 -123
- package/dist/services/oAuth2CodeGranter.test.js.map +0 -1
- package/dist/services/oAuth2TokenGranter.d.ts +0 -22
- package/dist/services/oAuth2TokenGranter.js +0 -64
- package/dist/services/oAuth2TokenGranter.js.map +0 -1
- package/src/__snapshots__/index.test.ts.snap +0 -401
- package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -37
- package/src/routes/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -61
- package/src/routes/__snapshots__/postOAuth2Token.test.ts.snap +0 -52
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +0 -52
- package/src/services/oAuth2CodeGranter.test.ts +0 -176
- package/src/services/oAuth2CodeGranter.ts +0 -210
- package/src/services/oAuth2TokenGranter.ts +0 -119
- /package/dist/{services/oAuth2CodeGranter.test.d.ts → libs/verifier.test.d.ts} +0 -0
|
@@ -1,30 +1,52 @@
|
|
|
1
1
|
import { autoService, location } from 'knifecycle';
|
|
2
|
-
import { noop } from '@whook/whook';
|
|
2
|
+
import { noop, refersTo, type WhookAPISchemaDefinition } from '@whook/whook';
|
|
3
3
|
import { YError } from 'yerror';
|
|
4
4
|
import { type LogService } from 'common-services';
|
|
5
5
|
import {
|
|
6
|
-
type
|
|
7
|
-
type
|
|
6
|
+
type WhookOAuth2GranterService,
|
|
7
|
+
type WhookOAuth2ReadClientGrantsService,
|
|
8
|
+
type WhookOAuth2Options,
|
|
9
|
+
type WhookOAuth2GranterDefinitions,
|
|
8
10
|
} from './oAuth2Granters.js';
|
|
9
|
-
import { type
|
|
10
|
-
import {
|
|
11
|
+
import { type WhookAuthenticationScope } from '@whook/authorization';
|
|
12
|
+
import { checkGrantType } from '../libs/grants.js';
|
|
13
|
+
import { filterScopes } from '../libs/scopes.js';
|
|
14
|
+
import { scopeSchema } from '../libs/schemas.js';
|
|
11
15
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
export const CLIENT_CREDENTIALS_GRANT_TYPE = 'client_credentials';
|
|
17
|
+
|
|
18
|
+
export const clientCredentialsTokenRequestBodySchema = {
|
|
19
|
+
name: 'ClientCredentialsRequestBody',
|
|
20
|
+
schema: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
description:
|
|
23
|
+
'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',
|
|
24
|
+
required: ['grant_type'],
|
|
25
|
+
properties: {
|
|
26
|
+
grant_type: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
const: CLIENT_CREDENTIALS_GRANT_TYPE,
|
|
29
|
+
},
|
|
30
|
+
scope: refersTo(scopeSchema),
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} as const satisfies WhookAPISchemaDefinition;
|
|
34
|
+
|
|
35
|
+
export interface WhookOAuth2ClientCredentialsGranterDependencies {
|
|
36
|
+
OAUTH2: WhookOAuth2Options;
|
|
37
|
+
readClientGrants: WhookOAuth2ReadClientGrantsService;
|
|
15
38
|
log?: LogService;
|
|
16
39
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
|
|
41
|
+
export interface WhookOAuth2ClientCredentialsGranterDefinitions extends WhookOAuth2GranterDefinitions {
|
|
42
|
+
grantType: typeof CLIENT_CREDENTIALS_GRANT_TYPE;
|
|
43
|
+
authenticateParameters: {
|
|
44
|
+
demandedScopes: WhookAuthenticationScope[];
|
|
45
|
+
};
|
|
21
46
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Record<string, unknown>,
|
|
26
|
-
OAuth2ClientCredentialsGranterParameters
|
|
27
|
-
>;
|
|
47
|
+
|
|
48
|
+
export type WhookOAuth2ClientCredentialsGranterService =
|
|
49
|
+
WhookOAuth2GranterService<WhookOAuth2ClientCredentialsGranterDefinitions>;
|
|
28
50
|
|
|
29
51
|
export default location(
|
|
30
52
|
autoService(initOAuth2ClientCredentialsGranter),
|
|
@@ -35,45 +57,48 @@ export default location(
|
|
|
35
57
|
// https://tools.ietf.org/html/rfc6749#section-4.4
|
|
36
58
|
async function initOAuth2ClientCredentialsGranter({
|
|
37
59
|
OAUTH2,
|
|
38
|
-
|
|
60
|
+
readClientGrants,
|
|
39
61
|
log = noop,
|
|
40
|
-
}:
|
|
62
|
+
}: WhookOAuth2ClientCredentialsGranterDependencies): Promise<WhookOAuth2ClientCredentialsGranterService> {
|
|
41
63
|
const authenticateWithClientCredentials: NonNullable<
|
|
42
|
-
|
|
43
|
-
>
|
|
44
|
-
{ scope: demandedScope = '' },
|
|
45
|
-
authenticationData,
|
|
46
|
-
) => {
|
|
47
|
-
// The client must be authenticated
|
|
64
|
+
WhookOAuth2ClientCredentialsGranterService['authenticate']
|
|
65
|
+
> = async ({ demandedScopes }, authenticationData) => {
|
|
48
66
|
if (!authenticationData) {
|
|
49
67
|
throw new YError('E_UNAUTHORIZED');
|
|
50
68
|
}
|
|
51
69
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
const grants = await readClientGrants(authenticationData.clientId);
|
|
71
|
+
|
|
72
|
+
if (authenticationData.clientId !== grants.authenticationData.clientId) {
|
|
73
|
+
throw new YError('E_OAUTH2_CLIENT_GRANTS_MISMATCH', [
|
|
74
|
+
authenticationData.clientId,
|
|
75
|
+
grants.authenticationData.clientId,
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
checkGrantType(grants.allowedGrantTypes, CLIENT_CREDENTIALS_GRANT_TYPE);
|
|
80
|
+
|
|
81
|
+
const filteredScopes = filterScopes(
|
|
82
|
+
demandedScopes.length
|
|
83
|
+
? demandedScopes
|
|
84
|
+
: OAUTH2.defaultToClientScope
|
|
85
|
+
? authenticationData.scopes
|
|
86
|
+
: [],
|
|
87
|
+
grants.allowedScopes,
|
|
88
|
+
!!OAUTH2.strictScopesChecks,
|
|
89
|
+
);
|
|
59
90
|
|
|
60
91
|
return {
|
|
61
92
|
...authenticationData,
|
|
62
|
-
|
|
63
|
-
? demandedScope
|
|
64
|
-
: OAUTH2.defaultToClientScope
|
|
65
|
-
? authenticationData.scope
|
|
66
|
-
: '',
|
|
93
|
+
scopes: filteredScopes,
|
|
67
94
|
};
|
|
68
95
|
};
|
|
69
96
|
|
|
70
97
|
log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');
|
|
71
98
|
|
|
72
99
|
return {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
authenticate: authenticateWithClientCredentials,
|
|
77
|
-
},
|
|
100
|
+
grantType: CLIENT_CREDENTIALS_GRANT_TYPE,
|
|
101
|
+
issuesRefreshToken: false,
|
|
102
|
+
authenticate: authenticateWithClientCredentials,
|
|
78
103
|
};
|
|
79
104
|
}
|
|
@@ -1,225 +1,131 @@
|
|
|
1
1
|
import { type Dependencies, initializer, location } from 'knifecycle';
|
|
2
|
+
import { type WhookErrorsDescriptors } from '@whook/whook';
|
|
2
3
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
} from '@whook/
|
|
7
|
-
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
4
|
+
type WhookAuthenticationScope,
|
|
5
|
+
type WhookAuthenticationData,
|
|
6
|
+
type WhookBaseAuthenticationData,
|
|
7
|
+
} from '@whook/authorization';
|
|
8
8
|
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
E_UNKNOWN_ACKNOWLEDGER_TYPE: [responseType: string];
|
|
12
|
-
E_APPLICATION_ID_MISMATCH: [
|
|
13
|
-
clientApplicationId: string,
|
|
14
|
-
authenticationApplicationId: string,
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Thrown when the refresh token is expired/invalid
|
|
19
|
-
*/
|
|
20
|
-
E_BAD_REFRESH_TOKEN: [];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Thrown when application has no access allowed
|
|
24
|
-
*/
|
|
25
|
-
E_ACCESS_DENIED: [clientId: string];
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Thrown when the OAuth2 server had unexpected errors
|
|
29
|
-
*/
|
|
30
|
-
E_OAUTH2: [];
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Thrown when refresh_token cookie is absent and required
|
|
34
|
-
*/
|
|
35
|
-
E_REFRESH_COOKIE: [cookie: string];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Thrown when server requires PKCE
|
|
39
|
-
*/
|
|
40
|
-
E_PKCE_REQUIRED: [responseType: string];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Thrown when server does not support PKCE
|
|
44
|
-
*/
|
|
45
|
-
E_PKCE_NOT_SUPPORTED: [responseType: string];
|
|
9
|
+
export interface WhookOAuth2Types {
|
|
10
|
+
clientId: string;
|
|
46
11
|
}
|
|
47
12
|
|
|
48
|
-
export
|
|
49
|
-
keyof OAuth2YErrorRegistry,
|
|
50
|
-
WhookErrorsDescriptors[string]
|
|
51
|
-
> = {
|
|
52
|
-
E_UNKNOWN_AUTHORIZER_TYPE: {
|
|
53
|
-
code: 'unsupported_response_type',
|
|
54
|
-
status: 400,
|
|
55
|
-
description: `The type "$0" is not supported.`,
|
|
56
|
-
uri: DEFAULT_ERROR_URI,
|
|
57
|
-
help: DEFAULT_HELP_URI,
|
|
58
|
-
},
|
|
59
|
-
E_APPLICATION_ID_MISMATCH: {
|
|
60
|
-
code: 'unauthorized_client',
|
|
61
|
-
status: 400,
|
|
62
|
-
description: `The clients ids "$0"/"$1" are inconsistent.`,
|
|
63
|
-
uri: DEFAULT_ERROR_URI,
|
|
64
|
-
help: DEFAULT_HELP_URI,
|
|
65
|
-
},
|
|
66
|
-
E_BAD_REFRESH_TOKEN: {
|
|
67
|
-
code: 'invalid_request',
|
|
68
|
-
status: 400,
|
|
69
|
-
description: 'The refresh token is expired/invalid.',
|
|
70
|
-
uri: DEFAULT_ERROR_URI,
|
|
71
|
-
help: DEFAULT_HELP_URI,
|
|
72
|
-
},
|
|
73
|
-
E_UNKNOWN_ACKNOWLEDGER_TYPE: {
|
|
74
|
-
code: 'unsupported_response_type',
|
|
75
|
-
status: 400,
|
|
76
|
-
description: `Type "$0" not supported.`,
|
|
77
|
-
uri: DEFAULT_ERROR_URI,
|
|
78
|
-
help: DEFAULT_HELP_URI,
|
|
79
|
-
},
|
|
80
|
-
E_ACCESS_DENIED: {
|
|
81
|
-
code: 'access_denied',
|
|
82
|
-
status: 403,
|
|
83
|
-
description: 'The user denied access to your application (id: "$0").',
|
|
84
|
-
uri: DEFAULT_ERROR_URI,
|
|
85
|
-
help: DEFAULT_HELP_URI,
|
|
86
|
-
},
|
|
87
|
-
E_OAUTH2: {
|
|
88
|
-
code: 'server_error',
|
|
89
|
-
status: 500,
|
|
90
|
-
uri: DEFAULT_ERROR_URI,
|
|
91
|
-
help: DEFAULT_HELP_URI,
|
|
92
|
-
},
|
|
93
|
-
E_REFRESH_COOKIE: {
|
|
94
|
-
code: 'invalid_request',
|
|
95
|
-
status: 400,
|
|
96
|
-
description: `Could not find any refresh_token value in the cookie header ($0).`,
|
|
97
|
-
uri: DEFAULT_ERROR_URI,
|
|
98
|
-
help: DEFAULT_HELP_URI,
|
|
99
|
-
},
|
|
100
|
-
E_PKCE_REQUIRED: {
|
|
101
|
-
code: 'invalid_request',
|
|
102
|
-
status: 400,
|
|
103
|
-
description: 'Code challenge required for this response type ($0)',
|
|
104
|
-
uri: DEFAULT_ERROR_URI,
|
|
105
|
-
help: DEFAULT_HELP_URI,
|
|
106
|
-
},
|
|
107
|
-
E_PKCE_NOT_SUPPORTED: {
|
|
108
|
-
code: 'invalid_request',
|
|
109
|
-
status: 400,
|
|
110
|
-
description: 'Code challenge not supported for this response type ($0)',
|
|
111
|
-
uri: DEFAULT_ERROR_URI,
|
|
112
|
-
help: DEFAULT_HELP_URI,
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export interface OAuth2PasswordService<
|
|
117
|
-
USERNAME extends string = string,
|
|
118
|
-
PASSWORD extends string = string,
|
|
119
|
-
> {
|
|
120
|
-
check: (
|
|
121
|
-
authenticationData: WhookAuthenticationData,
|
|
122
|
-
username: USERNAME,
|
|
123
|
-
password: PASSWORD,
|
|
124
|
-
demandedScope: WhookAuthenticationData['scope'],
|
|
125
|
-
) => Promise<WhookAuthenticationData>;
|
|
126
|
-
}
|
|
13
|
+
export type WhookOAuth2ClientId = WhookOAuth2Types['clientId'];
|
|
127
14
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
additionalParameters?: Record<string, unknown>,
|
|
133
|
-
) => Promise<{
|
|
134
|
-
token: TOKEN;
|
|
135
|
-
expiresAt: number;
|
|
136
|
-
}>;
|
|
137
|
-
check: (
|
|
138
|
-
authenticationData: WhookAuthenticationData,
|
|
139
|
-
token: TOKEN,
|
|
140
|
-
scope?: WhookAuthenticationData['scope'],
|
|
141
|
-
) => Promise<WhookAuthenticationData>;
|
|
15
|
+
declare module '@whook/authorization' {
|
|
16
|
+
export interface WhookAuthenticationData extends WhookBaseAuthenticationData {
|
|
17
|
+
clientId: WhookOAuth2ClientId;
|
|
18
|
+
}
|
|
142
19
|
}
|
|
143
20
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
export type
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
21
|
+
/**
|
|
22
|
+
* A service that returns acknowledgments for a given client
|
|
23
|
+
*/
|
|
24
|
+
export type WhookOAuth2ReadClientGrantsService = (
|
|
25
|
+
clientId: WhookOAuth2ClientId,
|
|
26
|
+
) => Promise<{
|
|
27
|
+
/** Grant types the client can be used with */
|
|
28
|
+
allowedGrantTypes: string[];
|
|
29
|
+
/** Scopes the client can delegate */
|
|
30
|
+
allowedScopes: WhookAuthenticationScope[];
|
|
31
|
+
/** Redirect URIS the client can be used with */
|
|
32
|
+
allowedRedirectURIS: string[];
|
|
33
|
+
/** Authentication data of the client */
|
|
34
|
+
authenticationData: WhookAuthenticationData;
|
|
35
|
+
/** Whether the client is public or private */
|
|
36
|
+
isPublicClient: boolean;
|
|
37
|
+
/** Whether the client can acknowledge for a user */
|
|
38
|
+
canAcknowledge?: boolean;
|
|
157
39
|
}>;
|
|
158
40
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
41
|
+
/**
|
|
42
|
+
* A function handling the OAuth2 authorize step
|
|
43
|
+
*/
|
|
44
|
+
export type WhookOAuth2GranterAuthorize<T extends object> = (
|
|
45
|
+
authorizeParameters: {
|
|
46
|
+
clientId: WhookOAuth2ClientId;
|
|
47
|
+
demandedRedirectURI?: string;
|
|
48
|
+
demandedScopes: WhookAuthenticationScope[];
|
|
164
49
|
},
|
|
165
|
-
|
|
50
|
+
additionalParameters: T,
|
|
166
51
|
) => Promise<{
|
|
167
|
-
|
|
52
|
+
clientId: WhookOAuth2ClientId;
|
|
168
53
|
redirectURI: string;
|
|
169
|
-
|
|
54
|
+
scopes: WhookAuthenticationScope[];
|
|
170
55
|
}>;
|
|
171
56
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
export type
|
|
178
|
-
|
|
179
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A function handling the Whook specific acknowledge
|
|
59
|
+
* step allowing to build a front end over it (for users
|
|
60
|
+
* to actually authorize clients to act on their behalf)
|
|
61
|
+
*/
|
|
62
|
+
export type WhookOAuth2GranterAcknowledge<
|
|
63
|
+
T extends object,
|
|
64
|
+
U extends object,
|
|
180
65
|
> = (
|
|
181
|
-
|
|
66
|
+
/** The acknowledging user authentication data */
|
|
67
|
+
userAuthenticationData: WhookAuthenticationData,
|
|
182
68
|
acknowledgeParameters: {
|
|
183
|
-
clientId:
|
|
184
|
-
|
|
185
|
-
|
|
69
|
+
clientId: WhookOAuth2ClientId;
|
|
70
|
+
demandedRedirectURI: string;
|
|
71
|
+
demandedScopes: WhookAuthenticationScope[];
|
|
186
72
|
},
|
|
187
|
-
|
|
73
|
+
acknowledgeData: T,
|
|
188
74
|
) => Promise<{
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
75
|
+
acknowledgedAuthenticationData: WhookAuthenticationData;
|
|
76
|
+
acknowledgedRedirectURI: string;
|
|
77
|
+
acknowledgedScopes: WhookAuthenticationScope[];
|
|
78
|
+
acknowledgedData: U;
|
|
192
79
|
}>;
|
|
193
80
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
81
|
+
/**
|
|
82
|
+
* A function handling the authenticate step
|
|
83
|
+
*/
|
|
84
|
+
export type WhookOAuth2GranterAuthenticate<T extends object> = (
|
|
85
|
+
authenticateParameters: T,
|
|
86
|
+
optionalAuthenticationData?: WhookAuthenticationData | undefined,
|
|
87
|
+
) => Promise<WhookAuthenticationData>;
|
|
88
|
+
|
|
89
|
+
export interface WhookOAuth2GranterDefinitions {
|
|
90
|
+
grantType?: string;
|
|
91
|
+
responseType?: string;
|
|
92
|
+
authorizeParameters: Record<string, string>;
|
|
93
|
+
acknowledgeParameters: Record<string, unknown>;
|
|
94
|
+
acknowledgedData: Record<string, unknown>;
|
|
95
|
+
authenticateParameters: Record<string, unknown>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface WhookOAuth2GranterService<
|
|
99
|
+
T extends WhookOAuth2GranterDefinitions,
|
|
199
100
|
> {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
authenticator?: {
|
|
210
|
-
grantType: string;
|
|
211
|
-
authenticate: Oauth2GranterAuthenticate<W>;
|
|
212
|
-
};
|
|
101
|
+
grantType: T['grantType'];
|
|
102
|
+
responseType?: T['responseType'];
|
|
103
|
+
issuesRefreshToken: boolean;
|
|
104
|
+
authorize?: WhookOAuth2GranterAuthorize<T['authorizeParameters']>;
|
|
105
|
+
acknowledge?: WhookOAuth2GranterAcknowledge<
|
|
106
|
+
T['acknowledgeParameters'],
|
|
107
|
+
T['acknowledgedData']
|
|
108
|
+
>;
|
|
109
|
+
authenticate?: WhookOAuth2GranterAuthenticate<T['authenticateParameters']>;
|
|
213
110
|
}
|
|
214
111
|
|
|
215
|
-
export interface
|
|
112
|
+
export interface WhookOAuth2Options {
|
|
113
|
+
/** Id of the root application */
|
|
114
|
+
rootClientId: WhookOAuth2ClientId;
|
|
115
|
+
/** Where client authenticate */
|
|
216
116
|
authenticateURL: string;
|
|
117
|
+
/** The available scopes of the whole application */
|
|
118
|
+
allowedScopes: WhookAuthenticationScope[];
|
|
119
|
+
/** Whether the client scope should be used as the default scope */
|
|
217
120
|
defaultToClientScope?: boolean;
|
|
121
|
+
/** Whether PKCE should be forced or not */
|
|
218
122
|
forcePKCE?: boolean;
|
|
123
|
+
/** Whether scopes should not only be filtered but strictly checked */
|
|
124
|
+
strictScopesChecks?: boolean;
|
|
219
125
|
}
|
|
220
126
|
|
|
221
|
-
export interface
|
|
222
|
-
OAUTH2:
|
|
127
|
+
export interface WhookOAuth2Config {
|
|
128
|
+
OAUTH2: WhookOAuth2Options;
|
|
223
129
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
224
130
|
}
|
|
225
131
|
|
|
@@ -230,10 +136,10 @@ export default location(
|
|
|
230
136
|
type: 'service',
|
|
231
137
|
inject: [
|
|
232
138
|
'oAuth2ClientCredentialsGranter',
|
|
233
|
-
'
|
|
139
|
+
'oAuth2AuthorizationCodeGranter',
|
|
234
140
|
'oAuth2PasswordGranter',
|
|
235
141
|
'oAuth2RefreshTokenGranter',
|
|
236
|
-
'
|
|
142
|
+
'oAuth2ImplicitGranter',
|
|
237
143
|
],
|
|
238
144
|
},
|
|
239
145
|
async (services: Dependencies) =>
|