@whook/oauth2 18.0.3 → 19.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 +36 -46
- package/dist/index.d.ts +8 -8
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +19 -18
- package/dist/index.test.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.d.ts +100 -0
- package/dist/{handlers → routes}/getOAuth2Authorize.js +39 -36
- package/dist/routes/getOAuth2Authorize.js.map +1 -0
- package/dist/{handlers → routes}/getOAuth2Authorize.test.js +14 -10
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -0
- package/dist/routes/postAuthLogin.d.ts +89 -0
- package/dist/{handlers → routes}/postAuthLogin.js +40 -39
- package/dist/routes/postAuthLogin.js.map +1 -0
- package/dist/routes/postAuthLogin.test.js.map +1 -0
- package/dist/routes/postAuthLogout.d.ts +28 -0
- package/dist/{handlers → routes}/postAuthLogout.js +9 -9
- package/dist/routes/postAuthLogout.js.map +1 -0
- package/dist/{handlers → routes}/postAuthLogout.test.js +1 -1
- package/dist/routes/postAuthLogout.test.js.map +1 -0
- package/dist/routes/postAuthRefresh.d.ts +94 -0
- package/dist/{handlers → routes}/postAuthRefresh.js +43 -42
- package/dist/routes/postAuthRefresh.js.map +1 -0
- package/dist/routes/postAuthRefresh.test.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.d.ts +97 -0
- package/dist/{handlers → routes}/postOAuth2Acknowledge.js +46 -44
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +198 -0
- package/dist/{handlers → routes}/postOAuth2Token.js +36 -34
- package/dist/routes/postOAuth2Token.js.map +1 -0
- package/dist/routes/postOAuth2Token.test.js.map +1 -0
- package/dist/services/authCookies.d.ts +3 -3
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +8 -8
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.d.ts +4 -5
- package/dist/services/oAuth2CodeGranter.js +2 -0
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +2 -2
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +25 -25
- package/dist/services/oAuth2Granters.js +1 -1
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.d.ts +4 -5
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +4 -5
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.d.ts +4 -5
- package/dist/services/oAuth2TokenGranter.js +4 -0
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/package.json +10 -9
- package/src/__snapshots__/index.test.ts.snap +1 -0
- package/src/index.test.ts +39 -52
- package/src/index.ts +20 -20
- package/src/{handlers → routes}/getOAuth2Authorize.test.ts +18 -14
- package/src/routes/getOAuth2Authorize.ts +217 -0
- package/src/{handlers → routes}/postAuthLogin.test.ts +3 -2
- package/src/routes/postAuthLogin.ts +118 -0
- package/src/{handlers → routes}/postAuthLogout.test.ts +2 -2
- package/src/routes/postAuthLogout.ts +38 -0
- package/src/{handlers → routes}/postAuthRefresh.test.ts +3 -2
- package/src/routes/postAuthRefresh.ts +138 -0
- package/src/{handlers → routes}/postOAuth2Acknowledge.test.ts +23 -39
- package/src/{handlers → routes}/postOAuth2Acknowledge.ts +88 -96
- package/src/{handlers → routes}/postOAuth2Token.test.ts +12 -11
- package/src/{handlers → routes}/postOAuth2Token.ts +124 -129
- package/src/services/authCookies.test.ts +1 -1
- package/src/services/authCookies.ts +3 -5
- package/src/services/oAuth2ClientCredentialsGranter.ts +10 -15
- package/src/services/oAuth2CodeGranter.test.ts +12 -21
- package/src/services/oAuth2CodeGranter.ts +9 -11
- package/src/services/oAuth2Granters.ts +35 -57
- package/src/services/oAuth2PasswordGranter.ts +7 -11
- package/src/services/oAuth2RefreshTokenGranter.ts +7 -11
- package/src/services/oAuth2TokenGranter.ts +12 -12
- package/src/types.d.ts +7 -0
- package/dist/handlers/getOAuth2Authorize.d.ts +0 -27
- package/dist/handlers/getOAuth2Authorize.js.map +0 -1
- package/dist/handlers/getOAuth2Authorize.test.js.map +0 -1
- package/dist/handlers/postAuthLogin.d.ts +0 -28
- package/dist/handlers/postAuthLogin.js.map +0 -1
- package/dist/handlers/postAuthLogin.test.js.map +0 -1
- package/dist/handlers/postAuthLogout.d.ts +0 -12
- package/dist/handlers/postAuthLogout.js.map +0 -1
- package/dist/handlers/postAuthLogout.test.js.map +0 -1
- package/dist/handlers/postAuthRefresh.d.ts +0 -28
- package/dist/handlers/postAuthRefresh.js.map +0 -1
- package/dist/handlers/postAuthRefresh.test.js.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.d.ts +0 -31
- package/dist/handlers/postOAuth2Acknowledge.js.map +0 -1
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +0 -1
- package/dist/handlers/postOAuth2Token.d.ts +0 -36
- package/dist/handlers/postOAuth2Token.js.map +0 -1
- package/dist/handlers/postOAuth2Token.test.js.map +0 -1
- package/src/handlers/getOAuth2Authorize.ts +0 -214
- package/src/handlers/postAuthLogin.ts +0 -123
- package/src/handlers/postAuthLogout.ts +0 -38
- package/src/handlers/postAuthRefresh.ts +0 -143
- /package/dist/{handlers → routes}/getOAuth2Authorize.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthLogin.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthLogin.test.js +0 -0
- /package/dist/{handlers → routes}/postAuthLogout.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthRefresh.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postAuthRefresh.test.js +0 -0
- /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postOAuth2Acknowledge.test.js +0 -0
- /package/dist/{handlers → routes}/postOAuth2Token.test.d.ts +0 -0
- /package/dist/{handlers → routes}/postOAuth2Token.test.js +0 -0
- /package/src/{handlers → routes}/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -0
- /package/src/{handlers → routes}/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -0
- /package/src/{handlers → routes}/__snapshots__/postOAuth2Token.test.ts.snap +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2CodeGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2CodeGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"oAuth2CodeGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2CodeGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAQhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAkBxC,eAAe,QAAQ,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE7E,2BAA2B;AAC3B,kDAAkD;AAClD,KAAK,UAAU,qBAAqB,CAAC,EACnC,UAAU,EACV,gBAAgB,EAChB,GAAG,GAAG,IAAI,GACoB;IAC9B,MAAM,iBAAiB,GAEN,KAAK,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,GAAG,EAAE,EAA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YACrB,aAAa,EAAE,kBAAkB,CAAC,aAAa;YAC/C,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;QAEH,MAAM,qBAAqB,GAAG,MAAM,UAAU,CAAC,KAAK,CAClD,kBAAkB,EAClB,IAAI,EACJ,WAAW,CACZ,CAAC;QAEF,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,6CAA6C,CAAC,CAAC;IAE5D,OAAO;QACL,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE;YACV,YAAY,EAAE,MAAM;YACpB,SAAS,EAAE,iBAAiB;SAC7B;QACD,YAAY,EAAE;YACZ,kBAAkB,EAAE,MAAM;YAC1B,WAAW,EAAE,mBAAmB;SACjC;QACD,aAAa,EAAE;YACb,SAAS,EAAE,oBAAoB;YAC/B,YAAY,EAAE,oBAAoB;SACnC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
2
2
|
import initOAuth2CodeGranter from './oAuth2CodeGranter.js';
|
|
3
3
|
describe('OAuth2CodeGranter', () => {
|
|
4
4
|
const oAuth2Code = {
|
|
@@ -13,7 +13,7 @@ describe('OAuth2CodeGranter', () => {
|
|
|
13
13
|
checkApplication.mockReset();
|
|
14
14
|
log.mockReset();
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
test('should work with a complete valid flow', async () => {
|
|
17
17
|
const oAuth2CodeGranter = await initOAuth2CodeGranter({
|
|
18
18
|
checkApplication,
|
|
19
19
|
oAuth2Code,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2CodeGranter.test.js","sourceRoot":"","sources":["../../src/services/oAuth2CodeGranter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"oAuth2Code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AM,gBAAgB,GAAG,MAAM,iBAAiB,CAAC,UAAU,EAAE,SAAS,CAAC;YACrE,QAAQ,EAAE,sCAAsC;YAChD,WAAW,EAAE,qCAAqC;YAClD,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,kBAAkB,GACtB,MAAM,iBAAiB,CAAC,YAAY,EAAE,WAAW,CAC/C;YACE,aAAa,EAAE,sCAAsC;YACrD,KAAK,EAAE,aAAa;SACM,EAC5B;YACE,QAAQ,EAAE,sCAAsC;YAChD,WAAW,EAAE,qCAAqC;YAClD,KAAK,EAAE,MAAM;SACd,EACD,EAAE,CACH,CAAC;QACJ,MAAM,mBAAmB,GACvB,MAAM,iBAAiB,CAAC,aAAa,EAAE,YAAY,CACjD;YACE,QAAQ,EAAE,sCAAsC;YAChD,WAAW,EAAE,qCAAqC;YAClD,IAAI,EAAE,MAAM;SACb,EACD;YACE,aAAa,EAAE,sCAAsC;YACrD,KAAK,EAAE,MAAM;SACa,CAC7B,CAAC;QAEJ,MAAM,CAAC;YACL,gBAAgB;YAChB,kBAAkB;YAClB,mBAAmB;SACpB,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;KAmBxB,CAAC,CAAC;QACH,MAAM,CAAC;YACL,qBAAqB,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK;YACnD,oBAAoB,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK;YACjD,qBAAqB,EAAE,gBAAgB,CAAC,IAAI,CAAC,KAAK;YAClD,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK;SACzB,CAAC,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
1
|
+
import { type WhookErrorsDescriptors } from '@whook/whook';
|
|
2
|
+
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
3
3
|
export declare const OAUTH2_ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
4
|
-
export type OAuth2CodeService<
|
|
5
|
-
create: (authenticationData:
|
|
4
|
+
export type OAuth2CodeService<CODE = string> = {
|
|
5
|
+
create: (authenticationData: WhookAuthenticationData, redirectURI: string, additionalParameters: {
|
|
6
6
|
[name: string]: unknown;
|
|
7
7
|
}) => Promise<CODE>;
|
|
8
|
-
check: (authenticationData:
|
|
8
|
+
check: (authenticationData: WhookAuthenticationData, code: CODE, redirectURI: string) => Promise<WhookAuthenticationData & {
|
|
9
9
|
redirectURI: string;
|
|
10
10
|
} & {
|
|
11
11
|
[name: string]: unknown;
|
|
12
12
|
}>;
|
|
13
13
|
};
|
|
14
|
-
export type OAuth2PasswordService<
|
|
15
|
-
check: (authenticationData:
|
|
14
|
+
export type OAuth2PasswordService<USERNAME = string, PASSWORD = string> = {
|
|
15
|
+
check: (authenticationData: WhookAuthenticationData, username: USERNAME, password: PASSWORD, demandedScope: WhookAuthenticationData['scope']) => Promise<WhookAuthenticationData>;
|
|
16
16
|
};
|
|
17
|
-
export type OAuth2AccessTokenService<
|
|
18
|
-
create: (authenticationData:
|
|
17
|
+
export type OAuth2AccessTokenService<TOKEN = string> = {
|
|
18
|
+
create: (authenticationData: WhookAuthenticationData, tokenAuthenticationData: WhookAuthenticationData, additionalParameters?: {
|
|
19
19
|
[name: string]: unknown;
|
|
20
20
|
}) => Promise<{
|
|
21
21
|
token: TOKEN;
|
|
22
22
|
expiresAt: number;
|
|
23
23
|
}>;
|
|
24
|
-
check: (authenticationData:
|
|
24
|
+
check: (authenticationData: WhookAuthenticationData, token: TOKEN, scope?: WhookAuthenticationData['scope']) => Promise<WhookAuthenticationData>;
|
|
25
25
|
};
|
|
26
|
-
export type OAuth2RefreshTokenService<
|
|
26
|
+
export type OAuth2RefreshTokenService<TOKEN = string> = OAuth2AccessTokenService<TOKEN>;
|
|
27
27
|
export type CheckApplicationService = {
|
|
28
28
|
(context: {
|
|
29
29
|
applicationId: string;
|
|
@@ -37,37 +37,37 @@ export type CheckApplicationService = {
|
|
|
37
37
|
redirectURI: string;
|
|
38
38
|
}>;
|
|
39
39
|
};
|
|
40
|
-
export type OAuth2GranterAuthorize<AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<string, unknown
|
|
41
|
-
clientId:
|
|
40
|
+
export type OAuth2GranterAuthorize<AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>> = (context: {
|
|
41
|
+
clientId: WhookAuthenticationData['applicationId'];
|
|
42
42
|
redirectURI: string;
|
|
43
|
-
scope:
|
|
43
|
+
scope: WhookAuthenticationData['scope'];
|
|
44
44
|
}, authorizeParameters?: AUTHORIZE_PARAMETERS) => Promise<{
|
|
45
|
-
applicationId:
|
|
45
|
+
applicationId: WhookAuthenticationData['applicationId'];
|
|
46
46
|
redirectURI: string;
|
|
47
|
-
scope:
|
|
47
|
+
scope: WhookAuthenticationData['scope'];
|
|
48
48
|
}>;
|
|
49
|
-
export type Oauth2GranterAuthenticate<GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown
|
|
50
|
-
export type OAuth2GranterAcknowledge<ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<string, unknown
|
|
51
|
-
clientId:
|
|
49
|
+
export type Oauth2GranterAuthenticate<GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown>> = (grantParameters: GRANT_PARAMETERS, authenticationData: WhookAuthenticationData) => Promise<WhookAuthenticationData>;
|
|
50
|
+
export type OAuth2GranterAcknowledge<ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>> = (authenticationData: WhookAuthenticationData, acknowledgeParameters: {
|
|
51
|
+
clientId: WhookAuthenticationData['applicationId'];
|
|
52
52
|
redirectURI: string;
|
|
53
|
-
scope:
|
|
54
|
-
}, additionalParameters: ACKNOWLEDGE_PARAMETERS) => Promise<
|
|
53
|
+
scope: WhookAuthenticationData['scope'];
|
|
54
|
+
}, additionalParameters: ACKNOWLEDGE_PARAMETERS) => Promise<WhookAuthenticationData & {
|
|
55
55
|
redirectURI: string;
|
|
56
56
|
[name: string]: unknown;
|
|
57
57
|
}>;
|
|
58
|
-
export type OAuth2GranterService<AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>, ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>, GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown
|
|
58
|
+
export type OAuth2GranterService<AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>, ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<string, unknown>, GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown>> = {
|
|
59
59
|
type: string;
|
|
60
60
|
authorizer?: {
|
|
61
61
|
responseType: string;
|
|
62
|
-
authorize: OAuth2GranterAuthorize<AUTHORIZE_PARAMETERS
|
|
62
|
+
authorize: OAuth2GranterAuthorize<AUTHORIZE_PARAMETERS>;
|
|
63
63
|
};
|
|
64
64
|
acknowledger?: {
|
|
65
65
|
acknowledgmentType: string;
|
|
66
|
-
acknowledge: OAuth2GranterAcknowledge<ACKNOWLEDGE_PARAMETERS
|
|
66
|
+
acknowledge: OAuth2GranterAcknowledge<ACKNOWLEDGE_PARAMETERS>;
|
|
67
67
|
};
|
|
68
68
|
authenticator?: {
|
|
69
69
|
grantType: string;
|
|
70
|
-
authenticate: Oauth2GranterAuthenticate<GRANT_PARAMETERS
|
|
70
|
+
authenticate: Oauth2GranterAuthenticate<GRANT_PARAMETERS>;
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
73
|
export type OAuth2Options = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { initializer, location } from 'knifecycle';
|
|
2
|
-
import { DEFAULT_ERROR_URI, DEFAULT_HELP_URI } from '@whook/whook';
|
|
2
|
+
import { DEFAULT_ERROR_URI, DEFAULT_HELP_URI, } from '@whook/whook';
|
|
3
3
|
export const OAUTH2_ERRORS_DESCRIPTORS = {
|
|
4
4
|
E_UNKNOWN_AUTHORIZER_TYPE: {
|
|
5
5
|
code: 'unsupported_response_type',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2Granters.js","sourceRoot":"","sources":["../../src/services/oAuth2Granters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"oAuth2Granters.js","sourceRoot":"","sources":["../../src/services/oAuth2Granters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,cAAc,CAAC;AAGtB,MAAM,CAAC,MAAM,yBAAyB,GAA2B;IAC/D,yBAAyB,EAAE;QACzB,IAAI,EAAE,2BAA2B;QACjC,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,iCAAiC;QAC9C,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,wBAAwB,EAAE;QACxB,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,gCAAgC;QAC7C,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,6BAA6B,EAAE;QAC7B,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,oCAAoC;QACjD,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,qBAAqB;QAC3B,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,iCAAiC;QAC9C,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,kBAAkB,EAAE;QAClB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,GAAG;QACX,WAAW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AE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,eAAe,EAAE;QACf,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,6CAA6C;QAC1D,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,6BAA6B,EAAE;QAC7B,IAAI,EAAE,wBAAwB;QAC9B,MAAM,EAAE,GAAG;QACX,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,GAAG;QACX,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;IACD,gBAAgB,EAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,mEAAmE;QAChF,GAAG,EAAE,iBAAiB;QACtB,IAAI,EAAE,gBAAgB;KACvB;CACF,CAAC;AA8IF,eAAe,QAAQ,CACrB,WAAW,CACT;IACE,IAAI,EAAE,gBAAgB;IACtB,IAAI,EAAE,SAAS;IACf,MAAM,EAAE;QACN,gCAAgC;QAChC,mBAAmB;QACnB,uBAAuB;QACvB,2BAA2B;QAC3B,oBAAoB;KACrB;CACF,EACD,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CACtE,EACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAChB,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
1
|
+
import { type LogService } from 'common-services';
|
|
2
|
+
import { type OAuth2GranterService, type OAuth2PasswordService, type CheckApplicationService } from './oAuth2Granters.js';
|
|
4
3
|
export type OAuth2PasswordGranterDependencies = {
|
|
5
4
|
oAuth2Password: OAuth2PasswordService;
|
|
6
5
|
checkApplication: CheckApplicationService;
|
|
@@ -11,6 +10,6 @@ export type OAuth2PasswordGranterParameters = {
|
|
|
11
10
|
password: string;
|
|
12
11
|
scope?: string;
|
|
13
12
|
};
|
|
14
|
-
export type OAuth2PasswordGranterService
|
|
15
|
-
declare const _default: import("knifecycle").ServiceInitializer<OAuth2PasswordGranterDependencies, OAuth2PasswordGranterService
|
|
13
|
+
export type OAuth2PasswordGranterService = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2PasswordGranterParameters>;
|
|
14
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2PasswordGranterDependencies, OAuth2PasswordGranterService>;
|
|
16
15
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2PasswordGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2PasswordGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"oAuth2PasswordGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2PasswordGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAwBhC,eAAe,QAAQ,CACrB,WAAW,CAAC,yBAAyB,CAAC,EACtC,MAAM,CAAC,IAAI,CAAC,GAAG,CAChB,CAAC;AAEF,4CAA4C;AAC5C,kDAAkD;AAClD,KAAK,UAAU,yBAAyB,CAAC,EACvC,cAAc,EACd,gBAAgB,EAChB,GAAG,GAAG,IAAI,GACwB;IAClC,MAAM,wBAAwB,GAEV,KAAK,EACvB,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,GAAG,EAAE,EAAE,EACjD,kBAAkB,EAClB,EAAE;QACF,mCAAmC;QACnC,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,gBAAgB,CAAC;YACrB,aAAa,EAAE,kBAAkB,CAAC,aAAa;YAC/C,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,aAAa;SACrB,CAAC,CAAC;QAEH,MAAM,uBAAuB,GAAG,MAAM,cAAc,CAAC,KAAK,CACxD,kBAAkB,EAClB,QAAQ,EACR,QAAQ,EACR,aAAa,CACd,CAAC;QAEF,OAAO,uBAAuB,CAAC;IACjC,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,iDAAiD,CAAC,CAAC;IAEhE,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,aAAa,EAAE;YACb,SAAS,EAAE,UAAU;YACrB,YAAY,EAAE,wBAAwB;SACvC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
1
|
+
import { type LogService } from 'common-services';
|
|
2
|
+
import { type OAuth2GranterService, type CheckApplicationService, type OAuth2RefreshTokenService } from './oAuth2Granters.js';
|
|
4
3
|
export type OAuth2RefreshTokenGranterDependencies = {
|
|
5
4
|
checkApplication: CheckApplicationService;
|
|
6
5
|
oAuth2RefreshToken: OAuth2RefreshTokenService;
|
|
@@ -10,6 +9,6 @@ export type OAuth2RefreshTokenGranterParameters = {
|
|
|
10
9
|
refreshToken: string;
|
|
11
10
|
scope?: string;
|
|
12
11
|
};
|
|
13
|
-
export type OAuth2RefreshTokenGranterService
|
|
14
|
-
declare const _default: import("knifecycle").ServiceInitializer<OAuth2RefreshTokenGranterDependencies, OAuth2RefreshTokenGranterService
|
|
12
|
+
export type OAuth2RefreshTokenGranterService = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2RefreshTokenGranterParameters>;
|
|
13
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2RefreshTokenGranterDependencies, OAuth2RefreshTokenGranterService>;
|
|
15
14
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2RefreshTokenGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2RefreshTokenGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"oAuth2RefreshTokenGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2RefreshTokenGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAuBhC,eAAe,QAAQ,CACrB,WAAW,CAAC,6BAA6B,CAAC,EAC1C,MAAM,CAAC,IAAI,CAAC,GAAG,CAChB,CAAC;AAEF,sBAAsB;AACtB,8CAA8C;AAC9C,KAAK,UAAU,6BAA6B,CAAC,EAC3C,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,GAAG,IAAI,GAC4B;IACtC,MAAM,4BAA4B,GAEd,KAAK,EACvB,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,GAAG,EAAE,EAAE,EAC3C,kBAAkB,EAClB,EAAE;QACF,IAAI,CAAC;YACH,mCAAmC;YACnC,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACxB,MAAM,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACrC,CAAC;YAED,MAAM,gBAAgB,CAAC;gBACrB,aAAa,EAAE,kBAAkB,CAAC,aAAa;gBAC/C,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,aAAa;aACrB,CAAC,CAAC;YAEH,MAAM,qBAAqB,GAAG,MAAM,kBAAkB,CAAC,KAAK,CAC1D,kBAAkB,EAClB,YAAY,EACZ,aAAa,CACd,CAAC;YAEF,OAAO,qBAAqB,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAK,GAAc,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;gBAC3C,MAAM,MAAM,CAAC,IAAI,CAAC,GAAY,EAAE,qBAAqB,CAAC,CAAC;YACzD,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,qDAAqD,CAAC,CAAC;IAEpE,OAAO;QACL,IAAI,EAAE,SAAS;QACf,aAAa,EAAE;YACb,SAAS,EAAE,eAAe;YAC1B,YAAY,EAAE,4BAA4B;SAC3C;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
1
|
+
import { type LogService, type TimeService } from 'common-services';
|
|
2
|
+
import { type OAuth2GranterService, type OAuth2AccessTokenService, type CheckApplicationService, type OAuth2CodeService } from './oAuth2Granters.js';
|
|
4
3
|
export declare const IMPLICIT_GRANTER_TYPE = "token";
|
|
5
4
|
export type OAuth2TokenGranterDependencies = {
|
|
6
5
|
oAuth2Code: OAuth2CodeService;
|
|
@@ -10,6 +9,6 @@ export type OAuth2TokenGranterDependencies = {
|
|
|
10
9
|
log?: LogService;
|
|
11
10
|
};
|
|
12
11
|
export type OAuth2TokenGranterParameters = Record<string, unknown>;
|
|
13
|
-
export type OAuth2TokenGranterService
|
|
14
|
-
declare const _default: import("knifecycle").ServiceInitializer<OAuth2TokenGranterDependencies, OAuth2TokenGranterService
|
|
12
|
+
export type OAuth2TokenGranterService = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2TokenGranterParameters>;
|
|
13
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2TokenGranterDependencies, OAuth2TokenGranterService>;
|
|
15
14
|
export default _default;
|
|
@@ -28,10 +28,14 @@ async function initOAuth2TokenGranter({ checkApplication, oAuth2AccessToken, tim
|
|
|
28
28
|
type: IMPLICIT_GRANTER_TYPE,
|
|
29
29
|
});
|
|
30
30
|
const { token: accessToken, expiresAt: accessTokenExpiresAt } = await oAuth2AccessToken.create(authenticationData, {
|
|
31
|
+
// TODO: check a way to avoid this by adding params
|
|
32
|
+
...authenticationData,
|
|
31
33
|
applicationId: clientId,
|
|
32
34
|
scope: providedScope,
|
|
33
35
|
}, additionalParameters);
|
|
34
36
|
return {
|
|
37
|
+
// TODO: check a way to avoid this by adding params
|
|
38
|
+
...authenticationData,
|
|
35
39
|
applicationId: clientId,
|
|
36
40
|
redirectURI: finalRedirectURI,
|
|
37
41
|
scope: providedScope,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oAuth2TokenGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2TokenGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"oAuth2TokenGranter.js","sourceRoot":"","sources":["../../src/services/oAuth2TokenGranter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AASpC,MAAM,CAAC,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAgB7C,eAAe,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AO;YACL,mDAAmD;YACnD,GAAG,kBAAkB;YACrB,aAAa,EAAE,QAAQ;YACvB,WAAW,EAAE,gBAAgB;YAC7B,KAAK,EAAE,aAAa;YACpB,WAAW;YACX,SAAS,EAAE,QAAQ;YACnB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,oBAAoB,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;SAC9D,CAAC;IACJ,CAAC,CAAC;IAEF,GAAG,CAAC,OAAO,EAAE,8CAA8C,CAAC,CAAC;IAE7D,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE;YACV,YAAY,EAAE,OAAO;YACrB,SAAS,EAAE,kBAAkB;SAC9B;QACD,YAAY,EAAE;YACZ,kBAAkB,EAAE,OAAO;YAC3B,WAAW,EAAE,oBAAoB;SAClC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"name": "@whook/oauth2",
|
|
26
|
-
"version": "
|
|
26
|
+
"version": "19.0.0",
|
|
27
27
|
"description": "OAuth2 implementation for Whook servers",
|
|
28
28
|
"type": "module",
|
|
29
29
|
"main": "dist/index.js",
|
|
@@ -43,16 +43,17 @@
|
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/nfroidure/whook",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@whook/authorization": "^
|
|
47
|
-
"@whook/whook": "^
|
|
46
|
+
"@whook/authorization": "^19.0.0",
|
|
47
|
+
"@whook/whook": "^19.0.0",
|
|
48
48
|
"camelcase": "^8.0.0",
|
|
49
|
-
"common-services": "^17.0.
|
|
49
|
+
"common-services": "^17.0.1",
|
|
50
50
|
"cookie": "^1.0.2",
|
|
51
|
-
"knifecycle": "^
|
|
52
|
-
"
|
|
53
|
-
"
|
|
51
|
+
"knifecycle": "^19.0.0",
|
|
52
|
+
"type-fest": "^4.33.0",
|
|
53
|
+
"ya-json-schema-types": "^1.0.1",
|
|
54
|
+
"ya-open-api-types": "^1.2.0",
|
|
54
55
|
"yerror": "^8.0.0",
|
|
55
|
-
"yhttperror": "^8.
|
|
56
|
+
"yhttperror": "^8.1.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@eslint/js": "^9.16.0",
|
|
@@ -136,5 +137,5 @@
|
|
|
136
137
|
"overrides": {
|
|
137
138
|
"eslint": "^9.16.0"
|
|
138
139
|
},
|
|
139
|
-
"gitHead": "
|
|
140
|
+
"gitHead": "4963a2a6f790aff942dc0080666619e6ca9c4076"
|
|
140
141
|
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import {
|
|
3
3
|
describe,
|
|
4
|
-
|
|
4
|
+
test,
|
|
5
5
|
beforeAll,
|
|
6
6
|
beforeEach,
|
|
7
7
|
afterAll,
|
|
@@ -13,12 +13,12 @@ import {
|
|
|
13
13
|
prepareProcess,
|
|
14
14
|
prepareEnvironment as basePrepareEnvironment,
|
|
15
15
|
DEFAULT_ERRORS_DESCRIPTORS,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
initRoutesWrappers,
|
|
17
|
+
initRoutesHandlers,
|
|
18
18
|
} from '@whook/whook';
|
|
19
19
|
import {
|
|
20
20
|
AUTHORIZATION_ERRORS_DESCRIPTORS,
|
|
21
|
-
|
|
21
|
+
initWrapRouteHandlerWithAuthorization,
|
|
22
22
|
} from '@whook/authorization';
|
|
23
23
|
import { alsoInject, constant, initializer } from 'knifecycle';
|
|
24
24
|
import axios from 'axios';
|
|
@@ -51,26 +51,17 @@ import {
|
|
|
51
51
|
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
52
52
|
postOAuth2TokenTokenBodySchema,
|
|
53
53
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
54
|
+
type OAuth2Options,
|
|
55
|
+
type CheckApplicationService,
|
|
56
|
+
type OAuth2PasswordService,
|
|
57
|
+
type OAuth2CodeService,
|
|
58
|
+
type OAuth2RefreshTokenService,
|
|
59
|
+
type OAuth2AccessTokenService,
|
|
54
60
|
} from './index.js';
|
|
55
|
-
import type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
OAuth2CodeService,
|
|
60
|
-
OAuth2RefreshTokenService,
|
|
61
|
-
OAuth2AccessTokenService,
|
|
62
|
-
} from './index.js';
|
|
63
|
-
import type { Knifecycle } from 'knifecycle';
|
|
64
|
-
import type { OpenAPIV3_1 } from 'openapi-types';
|
|
65
|
-
import type { Logger } from 'common-services';
|
|
66
|
-
import type {
|
|
67
|
-
AuthenticationService,
|
|
68
|
-
BaseAuthenticationData,
|
|
69
|
-
} from '@whook/authorization';
|
|
70
|
-
|
|
71
|
-
type CustomAuthenticationData = BaseAuthenticationData & {
|
|
72
|
-
userId: string;
|
|
73
|
-
};
|
|
61
|
+
import { type Knifecycle } from 'knifecycle';
|
|
62
|
+
import { type OpenAPI } from 'ya-open-api-types';
|
|
63
|
+
import { type Logger } from 'common-services';
|
|
64
|
+
import { type WhookAuthenticationService } from '@whook/authorization';
|
|
74
65
|
|
|
75
66
|
describe('OAuth2 server', () => {
|
|
76
67
|
const BASE_PATH = '/v1';
|
|
@@ -84,7 +75,7 @@ describe('OAuth2 server', () => {
|
|
|
84
75
|
const time = jest.fn();
|
|
85
76
|
const $autoload = jest.fn();
|
|
86
77
|
|
|
87
|
-
const API:
|
|
78
|
+
const API: OpenAPI = {
|
|
88
79
|
openapi: '3.1.0',
|
|
89
80
|
info: {
|
|
90
81
|
version: '1.0.0',
|
|
@@ -162,28 +153,23 @@ describe('OAuth2 server', () => {
|
|
|
162
153
|
authenticateURL: 'https://auth.example.com/sign_in',
|
|
163
154
|
};
|
|
164
155
|
const authentication = {
|
|
165
|
-
check:
|
|
166
|
-
jest.fn<AuthenticationService<any, CustomAuthenticationData>['check']>(),
|
|
156
|
+
check: jest.fn<WhookAuthenticationService<any>['check']>(),
|
|
167
157
|
};
|
|
168
158
|
const checkApplication = jest.fn<CheckApplicationService>();
|
|
169
159
|
const oAuth2AccessToken = {
|
|
170
|
-
create:
|
|
171
|
-
|
|
172
|
-
check:
|
|
173
|
-
jest.fn<OAuth2AccessTokenService<CustomAuthenticationData>['check']>(),
|
|
160
|
+
create: jest.fn<OAuth2AccessTokenService['create']>(),
|
|
161
|
+
check: jest.fn<OAuth2AccessTokenService['check']>(),
|
|
174
162
|
};
|
|
175
163
|
const oAuth2RefreshToken = {
|
|
176
|
-
create:
|
|
177
|
-
|
|
178
|
-
check:
|
|
179
|
-
jest.fn<OAuth2RefreshTokenService<CustomAuthenticationData>['check']>(),
|
|
164
|
+
create: jest.fn<OAuth2RefreshTokenService['create']>(),
|
|
165
|
+
check: jest.fn<OAuth2RefreshTokenService['check']>(),
|
|
180
166
|
};
|
|
181
167
|
const oAuth2Code = {
|
|
182
|
-
create: jest.fn<OAuth2CodeService
|
|
183
|
-
check: jest.fn<OAuth2CodeService
|
|
168
|
+
create: jest.fn<OAuth2CodeService['create']>(),
|
|
169
|
+
check: jest.fn<OAuth2CodeService['check']>(),
|
|
184
170
|
};
|
|
185
171
|
const oAuth2Password = {
|
|
186
|
-
check: jest.fn<OAuth2PasswordService
|
|
172
|
+
check: jest.fn<OAuth2PasswordService['check']>(),
|
|
187
173
|
};
|
|
188
174
|
|
|
189
175
|
let $instance;
|
|
@@ -203,6 +189,7 @@ describe('OAuth2 server', () => {
|
|
|
203
189
|
);
|
|
204
190
|
$.register(constant('BASE_PATH', BASE_PATH));
|
|
205
191
|
$.register(constant('API', API));
|
|
192
|
+
$.register(constant('DEFINITIONS', API));
|
|
206
193
|
$.register(constant('APP_ENV', 'local'));
|
|
207
194
|
$.register(
|
|
208
195
|
constant('ENV', {
|
|
@@ -217,11 +204,11 @@ describe('OAuth2 server', () => {
|
|
|
217
204
|
$.register(constant('time', time));
|
|
218
205
|
|
|
219
206
|
// Auth
|
|
220
|
-
const
|
|
207
|
+
const ROUTES_WRAPPERS_NAMES = ['wrapRouteHandlerWithAuthorization'];
|
|
221
208
|
|
|
222
|
-
$.register(
|
|
223
|
-
$.register(alsoInject(
|
|
224
|
-
$.register(constant('
|
|
209
|
+
$.register(initWrapRouteHandlerWithAuthorization);
|
|
210
|
+
$.register(alsoInject(ROUTES_WRAPPERS_NAMES, initRoutesWrappers));
|
|
211
|
+
$.register(constant('ROUTES_WRAPPERS_NAMES', ROUTES_WRAPPERS_NAMES));
|
|
225
212
|
|
|
226
213
|
// OAuth2 Specifics
|
|
227
214
|
$.register(constant('OAUTH2', OAUTH2));
|
|
@@ -235,7 +222,7 @@ describe('OAuth2 server', () => {
|
|
|
235
222
|
$.register(
|
|
236
223
|
alsoInject(
|
|
237
224
|
['getOAuth2Authorize', 'postOAuth2Acknowledge', 'postOAuth2Token'],
|
|
238
|
-
|
|
225
|
+
initRoutesHandlers,
|
|
239
226
|
),
|
|
240
227
|
);
|
|
241
228
|
$.register(constant('authentication', authentication));
|
|
@@ -299,7 +286,7 @@ describe('OAuth2 server', () => {
|
|
|
299
286
|
});
|
|
300
287
|
|
|
301
288
|
describe('with the password flow', () => {
|
|
302
|
-
|
|
289
|
+
test('should produce new tokens', async () => {
|
|
303
290
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
304
291
|
[
|
|
305
292
|
oAuth2AccessToken.check,
|
|
@@ -406,7 +393,7 @@ describe('OAuth2 server', () => {
|
|
|
406
393
|
});
|
|
407
394
|
|
|
408
395
|
describe('with the refresh token flow', () => {
|
|
409
|
-
|
|
396
|
+
test('should produce new tokens', async () => {
|
|
410
397
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
411
398
|
[
|
|
412
399
|
oAuth2AccessToken.check,
|
|
@@ -511,7 +498,7 @@ describe('OAuth2 server', () => {
|
|
|
511
498
|
});
|
|
512
499
|
|
|
513
500
|
describe('with the client credentials flow', () => {
|
|
514
|
-
|
|
501
|
+
test('should produce new tokens', async () => {
|
|
515
502
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
516
503
|
[
|
|
517
504
|
oAuth2AccessToken.check,
|
|
@@ -611,7 +598,7 @@ describe('OAuth2 server', () => {
|
|
|
611
598
|
});
|
|
612
599
|
|
|
613
600
|
describe('with the code flow', () => {
|
|
614
|
-
|
|
601
|
+
test('should build the authorization redirection', async () => {
|
|
615
602
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
616
603
|
[
|
|
617
604
|
authentication.check,
|
|
@@ -691,7 +678,7 @@ describe('OAuth2 server', () => {
|
|
|
691
678
|
}).toMatchSnapshot();
|
|
692
679
|
});
|
|
693
680
|
|
|
694
|
-
|
|
681
|
+
test('should redirect with a code', async () => {
|
|
695
682
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
696
683
|
[
|
|
697
684
|
oAuth2AccessToken.check,
|
|
@@ -756,7 +743,7 @@ describe('OAuth2 server', () => {
|
|
|
756
743
|
"etag": undefined,
|
|
757
744
|
"keep-alive": undefined,
|
|
758
745
|
"last-modified": undefined,
|
|
759
|
-
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo%3Fa_param%3Da_value&code=a_code",
|
|
746
|
+
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&user_id=2&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo%3Fa_param%3Da_value&code=a_code",
|
|
760
747
|
"server": undefined,
|
|
761
748
|
"transaction-id": "4",
|
|
762
749
|
"transfer-encoding": "chunked",
|
|
@@ -778,7 +765,7 @@ describe('OAuth2 server', () => {
|
|
|
778
765
|
}).toMatchSnapshot();
|
|
779
766
|
});
|
|
780
767
|
|
|
781
|
-
|
|
768
|
+
test('should produce new tokens', async () => {
|
|
782
769
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
783
770
|
[
|
|
784
771
|
oAuth2AccessToken.check,
|
|
@@ -883,7 +870,7 @@ describe('OAuth2 server', () => {
|
|
|
883
870
|
});
|
|
884
871
|
|
|
885
872
|
describe('with the implicit flow', () => {
|
|
886
|
-
|
|
873
|
+
test('should build the authorization redirection', async () => {
|
|
887
874
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
888
875
|
[
|
|
889
876
|
authentication.check,
|
|
@@ -961,7 +948,7 @@ describe('OAuth2 server', () => {
|
|
|
961
948
|
}).toMatchSnapshot();
|
|
962
949
|
});
|
|
963
950
|
|
|
964
|
-
|
|
951
|
+
test('should redirect with a token', async () => {
|
|
965
952
|
time.mockReturnValue(Date.parse('2010-03-06T00:00:00Z'));
|
|
966
953
|
[
|
|
967
954
|
oAuth2AccessToken.check,
|
|
@@ -1035,7 +1022,7 @@ describe('OAuth2 server', () => {
|
|
|
1035
1022
|
"etag": undefined,
|
|
1036
1023
|
"keep-alive": undefined,
|
|
1037
1024
|
"last-modified": undefined,
|
|
1038
|
-
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&access_token=an_access_token&token_type=bearer&expires_in=86400",
|
|
1025
|
+
"location": "http://redirect.example.com/yolo?a_param=a_value&client_id=acdc41ce-acdc-41ce-acdc-41ceacdc41ce&scope=user&state=xyz&user_id=2&redirect_uri=http%3A%2F%2Fredirect.example.com%2Fyolo&access_token=an_access_token&token_type=bearer&expires_in=86400",
|
|
1039
1026
|
"server": undefined,
|
|
1040
1027
|
"transaction-id": "7",
|
|
1041
1028
|
"transfer-encoding": "chunked",
|
package/src/index.ts
CHANGED
|
@@ -5,10 +5,10 @@ import initGetOAuth2Authorize, {
|
|
|
5
5
|
redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,
|
|
6
6
|
scopeParameter as getOAuth2AuthorizeScopeParameter,
|
|
7
7
|
stateParameter as getOAuth2AuthorizeStateParameter,
|
|
8
|
-
} from './
|
|
8
|
+
} from './routes/getOAuth2Authorize.js';
|
|
9
9
|
import initPostOAuth2Acknowledge, {
|
|
10
10
|
definition as postOAuth2AcknowledgeDefinition,
|
|
11
|
-
} from './
|
|
11
|
+
} from './routes/postOAuth2Acknowledge.js';
|
|
12
12
|
import initPostOAuth2Token, {
|
|
13
13
|
definition as postOAuth2TokenDefinition,
|
|
14
14
|
authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,
|
|
@@ -16,7 +16,7 @@ import initPostOAuth2Token, {
|
|
|
16
16
|
clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
17
17
|
refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
18
18
|
tokenBodySchema as postOAuth2TokenTokenBodySchema,
|
|
19
|
-
} from './
|
|
19
|
+
} from './routes/postOAuth2Token.js';
|
|
20
20
|
import initOAuth2Granters, {
|
|
21
21
|
OAUTH2_ERRORS_DESCRIPTORS,
|
|
22
22
|
} from './services/oAuth2Granters.js';
|
|
@@ -25,34 +25,34 @@ import initOAuth2CodeGranter from './services/oAuth2CodeGranter.js';
|
|
|
25
25
|
import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter.js';
|
|
26
26
|
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter.js';
|
|
27
27
|
import initOAuth2TokenGranter from './services/oAuth2TokenGranter.js';
|
|
28
|
-
import
|
|
29
|
-
OAuth2CodeService,
|
|
30
|
-
OAuth2PasswordService,
|
|
31
|
-
OAuth2AccessTokenService,
|
|
32
|
-
OAuth2RefreshTokenService,
|
|
33
|
-
CheckApplicationService,
|
|
34
|
-
OAuth2GranterService,
|
|
35
|
-
OAuth2Options,
|
|
36
|
-
OAuth2Config,
|
|
28
|
+
import {
|
|
29
|
+
type OAuth2CodeService,
|
|
30
|
+
type OAuth2PasswordService,
|
|
31
|
+
type OAuth2AccessTokenService,
|
|
32
|
+
type OAuth2RefreshTokenService,
|
|
33
|
+
type CheckApplicationService,
|
|
34
|
+
type OAuth2GranterService,
|
|
35
|
+
type OAuth2Options,
|
|
36
|
+
type OAuth2Config,
|
|
37
37
|
} from './services/oAuth2Granters.js';
|
|
38
38
|
import initPostAuthLogin, {
|
|
39
39
|
definition as postAuthLoginDefinition,
|
|
40
|
-
} from './
|
|
40
|
+
} from './routes/postAuthLogin.js';
|
|
41
41
|
import initPostAuthLogout, {
|
|
42
42
|
definition as postAuthLogoutDefinition,
|
|
43
|
-
} from './
|
|
43
|
+
} from './routes/postAuthLogout.js';
|
|
44
44
|
import initPostAuthRefresh, {
|
|
45
45
|
authCookieHeaderParameter,
|
|
46
46
|
definition as postAuthRefreshDefinition,
|
|
47
|
-
} from './
|
|
47
|
+
} from './routes/postAuthRefresh.js';
|
|
48
48
|
import initAuthCookiesService, {
|
|
49
49
|
AUTH_API_PREFIX,
|
|
50
50
|
} from './services/authCookies.js';
|
|
51
|
-
import
|
|
52
|
-
AuthCookiesConfig,
|
|
53
|
-
AuthCookiesService,
|
|
54
|
-
AuthCookiesData,
|
|
55
|
-
AuthHandlersConfig,
|
|
51
|
+
import {
|
|
52
|
+
type AuthCookiesConfig,
|
|
53
|
+
type AuthCookiesService,
|
|
54
|
+
type AuthCookiesData,
|
|
55
|
+
type AuthHandlersConfig,
|
|
56
56
|
} from './services/authCookies.js';
|
|
57
57
|
|
|
58
58
|
export type {
|