@whook/oauth2 8.3.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/LICENSE +20 -0
- package/README.md +384 -0
- package/dist/handlers/getOAuth2Authorize.d.ts +26 -0
- package/dist/handlers/getOAuth2Authorize.js +192 -0
- package/dist/handlers/getOAuth2Authorize.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.mjs +169 -0
- package/dist/handlers/getOAuth2Authorize.mjs.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.d.ts +1 -0
- package/dist/handlers/getOAuth2Authorize.test.js +122 -0
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs +114 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.d.ts +45 -0
- package/dist/handlers/postAuthLogin.js +125 -0
- package/dist/handlers/postAuthLogin.js.map +1 -0
- package/dist/handlers/postAuthLogin.mjs +108 -0
- package/dist/handlers/postAuthLogin.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.test.d.ts +1 -0
- package/dist/handlers/postAuthLogin.test.js +90 -0
- package/dist/handlers/postAuthLogin.test.js.map +1 -0
- package/dist/handlers/postAuthLogin.test.mjs +85 -0
- package/dist/handlers/postAuthLogin.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.d.ts +12 -0
- package/dist/handlers/postAuthLogout.js +46 -0
- package/dist/handlers/postAuthLogout.js.map +1 -0
- package/dist/handlers/postAuthLogout.mjs +33 -0
- package/dist/handlers/postAuthLogout.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.test.d.ts +1 -0
- package/dist/handlers/postAuthLogout.test.js +35 -0
- package/dist/handlers/postAuthLogout.test.js.map +1 -0
- package/dist/handlers/postAuthLogout.test.mjs +30 -0
- package/dist/handlers/postAuthLogout.test.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.d.ts +45 -0
- package/dist/handlers/postAuthRefresh.js +140 -0
- package/dist/handlers/postAuthRefresh.js.map +1 -0
- package/dist/handlers/postAuthRefresh.mjs +122 -0
- package/dist/handlers/postAuthRefresh.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.test.d.ts +1 -0
- package/dist/handlers/postAuthRefresh.test.js +99 -0
- package/dist/handlers/postAuthRefresh.test.js.map +1 -0
- package/dist/handlers/postAuthRefresh.test.mjs +94 -0
- package/dist/handlers/postAuthRefresh.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.d.ts +28 -0
- package/dist/handlers/postOAuth2Acknowledge.js +165 -0
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs +150 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js +148 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs +140 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.d.ts +36 -0
- package/dist/handlers/postOAuth2Token.js +263 -0
- package/dist/handlers/postOAuth2Token.js.map +1 -0
- package/dist/handlers/postOAuth2Token.mjs +242 -0
- package/dist/handlers/postOAuth2Token.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Token.test.js +166 -0
- package/dist/handlers/postOAuth2Token.test.js.map +1 -0
- package/dist/handlers/postOAuth2Token.test.mjs +160 -0
- package/dist/handlers/postOAuth2Token.test.mjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +230 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +15 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +759 -0
- package/dist/index.test.js.map +1 -0
- package/dist/index.test.mjs +748 -0
- package/dist/index.test.mjs.map +1 -0
- package/dist/services/authCookies.d.ts +26 -0
- package/dist/services/authCookies.js +74 -0
- package/dist/services/authCookies.js.map +1 -0
- package/dist/services/authCookies.mjs +58 -0
- package/dist/services/authCookies.mjs.map +1 -0
- package/dist/services/authCookies.test.d.ts +1 -0
- package/dist/services/authCookies.test.js +82 -0
- package/dist/services/authCookies.test.js.map +1 -0
- package/dist/services/authCookies.test.mjs +77 -0
- package/dist/services/authCookies.test.mjs.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +17 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js +56 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs +41 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +17 -0
- package/dist/services/oAuth2CodeGranter.js +115 -0
- package/dist/services/oAuth2CodeGranter.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.mjs +98 -0
- package/dist/services/oAuth2CodeGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.test.js +86 -0
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.mjs +81 -0
- package/dist/services/oAuth2CodeGranter.test.mjs.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +79 -0
- package/dist/services/oAuth2Granters.js +140 -0
- package/dist/services/oAuth2Granters.js.map +1 -0
- package/dist/services/oAuth2Granters.mjs +127 -0
- package/dist/services/oAuth2Granters.mjs.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +16 -0
- package/dist/services/oAuth2PasswordGranter.js +55 -0
- package/dist/services/oAuth2PasswordGranter.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.mjs +40 -0
- package/dist/services/oAuth2PasswordGranter.mjs.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +15 -0
- package/dist/services/oAuth2RefreshTokenGranter.js +62 -0
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs +47 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +1 -0
- package/dist/services/oAuth2TokenGranter.d.ts +15 -0
- package/dist/services/oAuth2TokenGranter.js +92 -0
- package/dist/services/oAuth2TokenGranter.js.map +1 -0
- package/dist/services/oAuth2TokenGranter.mjs +78 -0
- package/dist/services/oAuth2TokenGranter.mjs.map +1 -0
- package/package.json +205 -0
- package/src/__snapshots__/index.test.ts.snap +396 -0
- package/src/handlers/__snapshots__/getOAuth2Authorize.test.ts.snap +38 -0
- package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +61 -0
- package/src/handlers/__snapshots__/postOAuth2Token.test.ts.snap +52 -0
- package/src/handlers/getOAuth2Authorize.test.ts +142 -0
- package/src/handlers/getOAuth2Authorize.ts +222 -0
- package/src/handlers/postAuthLogin.test.ts +88 -0
- package/src/handlers/postAuthLogin.ts +123 -0
- package/src/handlers/postAuthLogout.test.ts +33 -0
- package/src/handlers/postAuthLogout.ts +38 -0
- package/src/handlers/postAuthRefresh.test.ts +97 -0
- package/src/handlers/postAuthRefresh.ts +146 -0
- package/src/handlers/postOAuth2Acknowledge.test.ts +175 -0
- package/src/handlers/postOAuth2Acknowledge.ts +209 -0
- package/src/handlers/postOAuth2Token.test.ts +153 -0
- package/src/handlers/postOAuth2Token.ts +302 -0
- package/src/index.test.ts +936 -0
- package/src/index.ts +105 -0
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +49 -0
- package/src/services/authCookies.test.ts +93 -0
- package/src/services/authCookies.ts +82 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +76 -0
- package/src/services/oAuth2CodeGranter.test.ts +94 -0
- package/src/services/oAuth2CodeGranter.ts +133 -0
- package/src/services/oAuth2Granters.ts +274 -0
- package/src/services/oAuth2PasswordGranter.ts +75 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +77 -0
- package/src/services/oAuth2TokenGranter.ts +105 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { service as _service } from 'knifecycle';
|
|
2
|
+
import { noop } from '@whook/whook';
|
|
3
|
+
import YError from 'yerror';
|
|
4
|
+
export default _service(initOAuth2ClientCredentialsGranter, "oAuth2ClientCredentialsGranter", ["OAUTH2", "checkApplication", "?log"]); // Client Credentials Grant
|
|
5
|
+
// https://tools.ietf.org/html/rfc6749#section-4.4
|
|
6
|
+
|
|
7
|
+
async function initOAuth2ClientCredentialsGranter({
|
|
8
|
+
OAUTH2,
|
|
9
|
+
checkApplication,
|
|
10
|
+
log = noop
|
|
11
|
+
}) {
|
|
12
|
+
const authenticateWithClientCredentials = async ({
|
|
13
|
+
scope: demandedScope = ''
|
|
14
|
+
}, authenticationData) => {
|
|
15
|
+
// The client must be authenticated
|
|
16
|
+
if (!authenticationData) {
|
|
17
|
+
throw new YError('E_UNAUTHORIZED');
|
|
18
|
+
} // Checking the scope and availability of the demanded
|
|
19
|
+
// grant type
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
await checkApplication({
|
|
23
|
+
applicationId: authenticationData.applicationId,
|
|
24
|
+
type: 'client_credentials',
|
|
25
|
+
scope: demandedScope
|
|
26
|
+
});
|
|
27
|
+
return { ...authenticationData,
|
|
28
|
+
scope: demandedScope ? demandedScope : OAUTH2.defaultToClientScope ? authenticationData.scope : ''
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');
|
|
33
|
+
return {
|
|
34
|
+
type: 'client_credentials',
|
|
35
|
+
authenticator: {
|
|
36
|
+
grantType: 'client_credentials',
|
|
37
|
+
authenticate: authenticateWithClientCredentials
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=oAuth2ClientCredentialsGranter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2ClientCredentialsGranter.ts"],"names":["autoService","noop","YError","initOAuth2ClientCredentialsGranter","OAUTH2","checkApplication","log","authenticateWithClientCredentials","scope","demandedScope","authenticationData","applicationId","type","defaultToClientScope","authenticator","grantType","authenticate"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AA8BA,eAAeF,QAAW,CAACG,kCAAD,2EAA1B,C,CAEA;AACA;;AACA,eAAeA,kCAAf,CAAkD;AAChDC,EAAAA,MADgD;AAEhDC,EAAAA,gBAFgD;AAGhDC,EAAAA,GAAG,GAAGL;AAH0C,CAAlD,EAI+F;AAC7F,QAAMM,iCAAyG,GAC7G,OAAO;AAAEC,IAAAA,KAAK,EAAEC,aAAa,GAAG;AAAzB,GAAP,EAAsCC,kBAAtC,KAA6D;AAC3D;AACA,QAAI,CAACA,kBAAL,EAAyB;AACvB,YAAM,IAAIR,MAAJ,CAAW,gBAAX,CAAN;AACD,KAJ0D,CAM3D;AACA;;;AACA,UAAMG,gBAAgB,CAAC;AACrBM,MAAAA,aAAa,EAAED,kBAAkB,CAACC,aADb;AAErBC,MAAAA,IAAI,EAAE,oBAFe;AAGrBJ,MAAAA,KAAK,EAAEC;AAHc,KAAD,CAAtB;AAMA,WAAO,EACL,GAAGC,kBADE;AAELF,MAAAA,KAAK,EAAEC,aAAa,GAChBA,aADgB,GAEhBL,MAAM,CAACS,oBAAP,GACAH,kBAAkB,CAACF,KADnB,GAEA;AANC,KAAP;AAQD,GAvBH;;AAyBAF,EAAAA,GAAG,CAAC,OAAD,EAAU,0DAAV,CAAH;AAEA,SAAO;AACLM,IAAAA,IAAI,EAAE,oBADD;AAELE,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,oBADE;AAEbC,MAAAA,YAAY,EAAET;AAFD;AAFV,GAAP;AAOD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\nimport type { OAuth2Options } from '..';\n\nexport type OAuth2ClientCredentialsGranterDependencies = {\n OAUTH2: OAuth2Options;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2ClientCredentialsGranterParameters<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = {\n username: string;\n password: string;\n scope?: AUTHENTICATION_DATA['scope'];\n};\nexport type OAuth2ClientCredentialsGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2ClientCredentialsGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2ClientCredentialsGranter);\n\n// Client Credentials Grant\n// https://tools.ietf.org/html/rfc6749#section-4.4\nasync function initOAuth2ClientCredentialsGranter({\n OAUTH2,\n checkApplication,\n log = noop,\n}: OAuth2ClientCredentialsGranterDependencies): Promise<OAuth2ClientCredentialsGranterService> {\n const authenticateWithClientCredentials: OAuth2ClientCredentialsGranterService['authenticator']['authenticate'] =\n async ({ scope: demandedScope = '' }, authenticationData) => {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // Checking the scope and availability of the demanded\n // grant type\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'client_credentials',\n scope: demandedScope,\n });\n\n return {\n ...authenticationData,\n scope: demandedScope\n ? demandedScope\n : OAUTH2.defaultToClientScope\n ? authenticationData.scope\n : '',\n };\n };\n\n log('debug', '👫 - OAuth2ClientCredentialsGranter Service Initialized!');\n\n return {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: authenticateWithClientCredentials,\n },\n };\n}\n"],"file":"oAuth2ClientCredentialsGranter.mjs"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LogService } from 'common-services';
|
|
2
|
+
import type { OAuth2GranterService, OAuth2CodeService, CheckApplicationService } from './oAuth2Granters';
|
|
3
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
|
+
export declare const CODE_GRANTER_TYPE = "code";
|
|
5
|
+
export declare type OAuth2CodeGranterDependencies = {
|
|
6
|
+
oAuth2Code: OAuth2CodeService;
|
|
7
|
+
checkApplication: CheckApplicationService;
|
|
8
|
+
log?: LogService;
|
|
9
|
+
};
|
|
10
|
+
export declare type OAuth2CodeGranterParameters = {
|
|
11
|
+
code: string;
|
|
12
|
+
redirectURI: string;
|
|
13
|
+
clientId: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type OAuth2CodeGranterService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData> = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2CodeGranterParameters, AUTHENTICATION_DATA>;
|
|
16
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2CodeGranterDependencies, OAuth2CodeGranterService<BaseAuthenticationData<string, string>>>;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.CODE_GRANTER_TYPE = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
var _whook = require("@whook/whook");
|
|
11
|
+
|
|
12
|
+
var _yerror = _interopRequireDefault(require("yerror"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const CODE_GRANTER_TYPE = 'code';
|
|
17
|
+
exports.CODE_GRANTER_TYPE = CODE_GRANTER_TYPE;
|
|
18
|
+
|
|
19
|
+
var _default = (0, _knifecycle.service)(initOAuth2CodeGranter, "oAuth2CodeGranter", ["oAuth2Code", "checkApplication", "?log"]); // Authorization Code Grant
|
|
20
|
+
// https://tools.ietf.org/html/rfc6749#section-4.1
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
exports.default = _default;
|
|
24
|
+
|
|
25
|
+
async function initOAuth2CodeGranter({
|
|
26
|
+
oAuth2Code,
|
|
27
|
+
checkApplication,
|
|
28
|
+
log = _whook.noop
|
|
29
|
+
}) {
|
|
30
|
+
const authorizeWithCode = async ({
|
|
31
|
+
clientId,
|
|
32
|
+
redirectURI,
|
|
33
|
+
scope = ''
|
|
34
|
+
}) => {
|
|
35
|
+
const {
|
|
36
|
+
redirectURI: finalRedirectURI
|
|
37
|
+
} = await checkApplication({
|
|
38
|
+
applicationId: clientId,
|
|
39
|
+
type: CODE_GRANTER_TYPE,
|
|
40
|
+
redirectURI,
|
|
41
|
+
scope
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
applicationId: clientId,
|
|
45
|
+
redirectURI: finalRedirectURI,
|
|
46
|
+
scope
|
|
47
|
+
};
|
|
48
|
+
}; // Authorization Code Response:
|
|
49
|
+
// https://tools.ietf.org/html/rfc6749#section-4.1.2
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const acknowledgeWithCode = async (authenticationData, {
|
|
53
|
+
clientId,
|
|
54
|
+
redirectURI,
|
|
55
|
+
scope
|
|
56
|
+
}, additionalParameters) => {
|
|
57
|
+
const code = await oAuth2Code.create({ ...authenticationData,
|
|
58
|
+
applicationId: clientId,
|
|
59
|
+
scope
|
|
60
|
+
}, redirectURI, additionalParameters);
|
|
61
|
+
return {
|
|
62
|
+
applicationId: clientId,
|
|
63
|
+
redirectURI,
|
|
64
|
+
scope,
|
|
65
|
+
code
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const authenticateWithCode = async ({
|
|
70
|
+
code,
|
|
71
|
+
clientId,
|
|
72
|
+
redirectURI
|
|
73
|
+
}, authenticationData) => {
|
|
74
|
+
// The client must be authenticated (for now, see below)
|
|
75
|
+
if (!authenticationData) {
|
|
76
|
+
throw new _yerror.default('E_UNAUTHORIZED');
|
|
77
|
+
} // This check is not really necessary atm but it acts
|
|
78
|
+
// as a reminder that this grant type could be used
|
|
79
|
+
// without authenticating the client. In this
|
|
80
|
+
// scenario, the authenticationData should be deducted
|
|
81
|
+
// from the clientId and the code given in parameters
|
|
82
|
+
// See https://tools.ietf.org/html/rfc6749#section-4.1.3
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (clientId && clientId !== authenticationData.applicationId) {
|
|
86
|
+
throw new _yerror.default('E_UNAUTHORIZED', clientId, authenticationData.applicationId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await checkApplication({
|
|
90
|
+
applicationId: authenticationData.applicationId,
|
|
91
|
+
type: CODE_GRANTER_TYPE,
|
|
92
|
+
scope: ''
|
|
93
|
+
});
|
|
94
|
+
const newAuthenticationData = await oAuth2Code.check(authenticationData, code, redirectURI);
|
|
95
|
+
return newAuthenticationData;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
log('debug', '👫 - OAuth2CodeGranter Service Initialized!');
|
|
99
|
+
return {
|
|
100
|
+
type: CODE_GRANTER_TYPE,
|
|
101
|
+
authorizer: {
|
|
102
|
+
responseType: 'code',
|
|
103
|
+
authorize: authorizeWithCode
|
|
104
|
+
},
|
|
105
|
+
acknowledger: {
|
|
106
|
+
acknowledgmentType: 'code',
|
|
107
|
+
acknowledge: acknowledgeWithCode
|
|
108
|
+
},
|
|
109
|
+
authenticator: {
|
|
110
|
+
grantType: 'authorization_code',
|
|
111
|
+
authenticate: authenticateWithCode
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=oAuth2CodeGranter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2CodeGranter.ts"],"names":["CODE_GRANTER_TYPE","initOAuth2CodeGranter","oAuth2Code","checkApplication","log","noop","authorizeWithCode","clientId","redirectURI","scope","finalRedirectURI","applicationId","type","acknowledgeWithCode","authenticationData","additionalParameters","code","create","authenticateWithCode","YError","newAuthenticationData","check","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AASO,MAAMA,iBAAiB,GAAG,MAA1B;;;eAqBQ,yBAAYC,qBAAZ,kE,EAEf;AACA;;;;;AACA,eAAeA,qBAAf,CAAqC;AACnCC,EAAAA,UADmC;AAEnCC,EAAAA,gBAFmC;AAGnCC,EAAAA,GAAG,GAAGC;AAH6B,CAArC,EAIqE;AACnE,QAAMC,iBAAsE,GAC1E,OAAO;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,WAAZ;AAAyBC,IAAAA,KAAK,GAAG;AAAjC,GAAP,KAAiD;AAC/C,UAAM;AAAED,MAAAA,WAAW,EAAEE;AAAf,QAAoC,MAAMP,gBAAgB,CAAC;AAC/DQ,MAAAA,aAAa,EAAEJ,QADgD;AAE/DK,MAAAA,IAAI,EAAEZ,iBAFyD;AAG/DQ,MAAAA,WAH+D;AAI/DC,MAAAA;AAJ+D,KAAD,CAAhE;AAOA,WAAO;AACLE,MAAAA,aAAa,EAAEJ,QADV;AAELC,MAAAA,WAAW,EAAEE,gBAFR;AAGLD,MAAAA;AAHK,KAAP;AAKD,GAdH,CADmE,CAiBnE;AACA;;;AACA,QAAMI,mBAA4E,GAChF,OACEC,kBADF,EAEE;AAAEP,IAAAA,QAAF;AAAYC,IAAAA,WAAZ;AAAyBC,IAAAA;AAAzB,GAFF,EAGEM,oBAHF,KAIK;AACH,UAAMC,IAAI,GAAG,MAAMd,UAAU,CAACe,MAAX,CACjB,EAAE,GAAGH,kBAAL;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,EAAEd;AAFD,KANT;AAULe,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,oBADE;AAEbC,MAAAA,YAAY,EAAEZ;AAFD;AAVV,GAAP;AAeD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n OAuth2CodeService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const CODE_GRANTER_TYPE = 'code';\n\nexport type OAuth2CodeGranterDependencies = {\n oAuth2Code: OAuth2CodeService;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2CodeGranterParameters = {\n code: string;\n redirectURI: string;\n clientId: string;\n};\nexport type OAuth2CodeGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2CodeGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2CodeGranter);\n\n// Authorization Code Grant\n// https://tools.ietf.org/html/rfc6749#section-4.1\nasync function initOAuth2CodeGranter({\n oAuth2Code,\n checkApplication,\n log = noop,\n}: OAuth2CodeGranterDependencies): Promise<OAuth2CodeGranterService> {\n const authorizeWithCode: OAuth2CodeGranterService['authorizer']['authorize'] =\n async ({ clientId, redirectURI, scope = '' }) => {\n const { redirectURI: finalRedirectURI } = await checkApplication({\n applicationId: clientId,\n type: CODE_GRANTER_TYPE,\n redirectURI,\n scope,\n });\n\n return {\n applicationId: clientId,\n redirectURI: finalRedirectURI,\n scope,\n };\n };\n\n // Authorization Code Response:\n // https://tools.ietf.org/html/rfc6749#section-4.1.2\n const acknowledgeWithCode: OAuth2CodeGranterService['acknowledger']['acknowledge'] =\n async (\n authenticationData,\n { clientId, redirectURI, scope },\n additionalParameters,\n ) => {\n const code = await oAuth2Code.create(\n { ...authenticationData, applicationId: clientId, scope },\n redirectURI,\n additionalParameters,\n );\n\n return {\n applicationId: clientId,\n redirectURI,\n scope,\n code,\n };\n };\n\n const authenticateWithCode: OAuth2CodeGranterService['authenticator']['authenticate'] =\n async ({ code, clientId, redirectURI }, authenticationData) => {\n // The client must be authenticated (for now, see below)\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // This check is not really necessary atm but it acts\n // as a reminder that this grant type could be used\n // without authenticating the client. In this\n // scenario, the authenticationData should be deducted\n // from the clientId and the code given in parameters\n // See https://tools.ietf.org/html/rfc6749#section-4.1.3\n if (clientId && clientId !== authenticationData.applicationId) {\n throw new YError(\n 'E_UNAUTHORIZED',\n clientId,\n authenticationData.applicationId,\n );\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: CODE_GRANTER_TYPE,\n scope: '',\n });\n\n const newAuthenticationData = await oAuth2Code.check(\n authenticationData,\n code,\n redirectURI,\n );\n\n return newAuthenticationData;\n };\n\n log('debug', '👫 - OAuth2CodeGranter Service Initialized!');\n\n return {\n type: CODE_GRANTER_TYPE,\n authorizer: {\n responseType: 'code',\n authorize: authorizeWithCode,\n },\n acknowledger: {\n acknowledgmentType: 'code',\n acknowledge: acknowledgeWithCode,\n },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: authenticateWithCode,\n },\n };\n}\n"],"file":"oAuth2CodeGranter.js"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { service as _service } from 'knifecycle';
|
|
2
|
+
import { noop } from '@whook/whook';
|
|
3
|
+
import YError from 'yerror';
|
|
4
|
+
export const CODE_GRANTER_TYPE = 'code';
|
|
5
|
+
export default _service(initOAuth2CodeGranter, "oAuth2CodeGranter", ["oAuth2Code", "checkApplication", "?log"]); // Authorization Code Grant
|
|
6
|
+
// https://tools.ietf.org/html/rfc6749#section-4.1
|
|
7
|
+
|
|
8
|
+
async function initOAuth2CodeGranter({
|
|
9
|
+
oAuth2Code,
|
|
10
|
+
checkApplication,
|
|
11
|
+
log = noop
|
|
12
|
+
}) {
|
|
13
|
+
const authorizeWithCode = async ({
|
|
14
|
+
clientId,
|
|
15
|
+
redirectURI,
|
|
16
|
+
scope = ''
|
|
17
|
+
}) => {
|
|
18
|
+
const {
|
|
19
|
+
redirectURI: finalRedirectURI
|
|
20
|
+
} = await checkApplication({
|
|
21
|
+
applicationId: clientId,
|
|
22
|
+
type: CODE_GRANTER_TYPE,
|
|
23
|
+
redirectURI,
|
|
24
|
+
scope
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
applicationId: clientId,
|
|
28
|
+
redirectURI: finalRedirectURI,
|
|
29
|
+
scope
|
|
30
|
+
};
|
|
31
|
+
}; // Authorization Code Response:
|
|
32
|
+
// https://tools.ietf.org/html/rfc6749#section-4.1.2
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const acknowledgeWithCode = async (authenticationData, {
|
|
36
|
+
clientId,
|
|
37
|
+
redirectURI,
|
|
38
|
+
scope
|
|
39
|
+
}, additionalParameters) => {
|
|
40
|
+
const code = await oAuth2Code.create({ ...authenticationData,
|
|
41
|
+
applicationId: clientId,
|
|
42
|
+
scope
|
|
43
|
+
}, redirectURI, additionalParameters);
|
|
44
|
+
return {
|
|
45
|
+
applicationId: clientId,
|
|
46
|
+
redirectURI,
|
|
47
|
+
scope,
|
|
48
|
+
code
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const authenticateWithCode = async ({
|
|
53
|
+
code,
|
|
54
|
+
clientId,
|
|
55
|
+
redirectURI
|
|
56
|
+
}, authenticationData) => {
|
|
57
|
+
// The client must be authenticated (for now, see below)
|
|
58
|
+
if (!authenticationData) {
|
|
59
|
+
throw new YError('E_UNAUTHORIZED');
|
|
60
|
+
} // This check is not really necessary atm but it acts
|
|
61
|
+
// as a reminder that this grant type could be used
|
|
62
|
+
// without authenticating the client. In this
|
|
63
|
+
// scenario, the authenticationData should be deducted
|
|
64
|
+
// from the clientId and the code given in parameters
|
|
65
|
+
// See https://tools.ietf.org/html/rfc6749#section-4.1.3
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (clientId && clientId !== authenticationData.applicationId) {
|
|
69
|
+
throw new YError('E_UNAUTHORIZED', clientId, authenticationData.applicationId);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await checkApplication({
|
|
73
|
+
applicationId: authenticationData.applicationId,
|
|
74
|
+
type: CODE_GRANTER_TYPE,
|
|
75
|
+
scope: ''
|
|
76
|
+
});
|
|
77
|
+
const newAuthenticationData = await oAuth2Code.check(authenticationData, code, redirectURI);
|
|
78
|
+
return newAuthenticationData;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
log('debug', '👫 - OAuth2CodeGranter Service Initialized!');
|
|
82
|
+
return {
|
|
83
|
+
type: CODE_GRANTER_TYPE,
|
|
84
|
+
authorizer: {
|
|
85
|
+
responseType: 'code',
|
|
86
|
+
authorize: authorizeWithCode
|
|
87
|
+
},
|
|
88
|
+
acknowledger: {
|
|
89
|
+
acknowledgmentType: 'code',
|
|
90
|
+
acknowledge: acknowledgeWithCode
|
|
91
|
+
},
|
|
92
|
+
authenticator: {
|
|
93
|
+
grantType: 'authorization_code',
|
|
94
|
+
authenticate: authenticateWithCode
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=oAuth2CodeGranter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2CodeGranter.ts"],"names":["autoService","noop","YError","CODE_GRANTER_TYPE","initOAuth2CodeGranter","oAuth2Code","checkApplication","log","authorizeWithCode","clientId","redirectURI","scope","finalRedirectURI","applicationId","type","acknowledgeWithCode","authenticationData","additionalParameters","code","create","authenticateWithCode","newAuthenticationData","check","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC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IAAF;AAAQT,IAAAA,QAAR;AAAkBC,IAAAA;AAAlB,GAAP,EAAwCM,kBAAxC,KAA+D;AAC7D;AACA,QAAI,CAACA,kBAAL,EAAyB;AACvB,YAAM,IAAId,MAAJ,CAAW,gBAAX,CAAN;AACD,KAJ4D,CAM7D;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAIO,QAAQ,IAAIA,QAAQ,KAAKO,kBAAkB,CAACH,aAAhD,EAA+D;AAC7D,YAAM,IAAIX,MAAJ,CACJ,gBADI,EAEJO,QAFI,EAGJO,kBAAkB,CAACH,aAHf,CAAN;AAKD;;AAED,UAAMP,gBAAgB,CAAC;AACrBO,MAAAA,aAAa,EAAEG,kBAAkB,CAACH,aADb;AAErBC,MAAAA,IAAI,EAAEX,iBAFe;AAGrBQ,MAAAA,KAAK,EAAE;AAHc,KAAD,CAAtB;AAMA,UAAMU,qBAAqB,GAAG,MAAMhB,UAAU,CAACiB,KAAX,CAClCN,kBADkC,EAElCE,IAFkC,EAGlCR,WAHkC,CAApC;AAMA,WAAOW,qBAAP;AACD,GAlCH;;AAoCAd,EAAAA,GAAG,CAAC,OAAD,EAAU,6CAAV,CAAH;AAEA,SAAO;AACLO,IAAAA,IAAI,EAAEX,iBADD;AAELoB,IAAAA,UAAU,EAAE;AACVC,MAAAA,YAAY,EAAE,MADJ;AAEVC,MAAAA,SAAS,EAAEjB;AAFD,KAFP;AAMLkB,IAAAA,YAAY,EAAE;AACZC,MAAAA,kBAAkB,EAAE,MADR;AAEZC,MAAAA,WAAW,EAAEb;AAFD,KANT;AAULc,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,oBADE;AAEbC,MAAAA,YAAY,EAAEX;AAFD;AAVV,GAAP;AAeD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n OAuth2CodeService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const CODE_GRANTER_TYPE = 'code';\n\nexport type OAuth2CodeGranterDependencies = {\n oAuth2Code: OAuth2CodeService;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2CodeGranterParameters = {\n code: string;\n redirectURI: string;\n clientId: string;\n};\nexport type OAuth2CodeGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2CodeGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2CodeGranter);\n\n// Authorization Code Grant\n// https://tools.ietf.org/html/rfc6749#section-4.1\nasync function initOAuth2CodeGranter({\n oAuth2Code,\n checkApplication,\n log = noop,\n}: OAuth2CodeGranterDependencies): Promise<OAuth2CodeGranterService> {\n const authorizeWithCode: OAuth2CodeGranterService['authorizer']['authorize'] =\n async ({ clientId, redirectURI, scope = '' }) => {\n const { redirectURI: finalRedirectURI } = await checkApplication({\n applicationId: clientId,\n type: CODE_GRANTER_TYPE,\n redirectURI,\n scope,\n });\n\n return {\n applicationId: clientId,\n redirectURI: finalRedirectURI,\n scope,\n };\n };\n\n // Authorization Code Response:\n // https://tools.ietf.org/html/rfc6749#section-4.1.2\n const acknowledgeWithCode: OAuth2CodeGranterService['acknowledger']['acknowledge'] =\n async (\n authenticationData,\n { clientId, redirectURI, scope },\n additionalParameters,\n ) => {\n const code = await oAuth2Code.create(\n { ...authenticationData, applicationId: clientId, scope },\n redirectURI,\n additionalParameters,\n );\n\n return {\n applicationId: clientId,\n redirectURI,\n scope,\n code,\n };\n };\n\n const authenticateWithCode: OAuth2CodeGranterService['authenticator']['authenticate'] =\n async ({ code, clientId, redirectURI }, authenticationData) => {\n // The client must be authenticated (for now, see below)\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // This check is not really necessary atm but it acts\n // as a reminder that this grant type could be used\n // without authenticating the client. In this\n // scenario, the authenticationData should be deducted\n // from the clientId and the code given in parameters\n // See https://tools.ietf.org/html/rfc6749#section-4.1.3\n if (clientId && clientId !== authenticationData.applicationId) {\n throw new YError(\n 'E_UNAUTHORIZED',\n clientId,\n authenticationData.applicationId,\n );\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: CODE_GRANTER_TYPE,\n scope: '',\n });\n\n const newAuthenticationData = await oAuth2Code.check(\n authenticationData,\n code,\n redirectURI,\n );\n\n return newAuthenticationData;\n };\n\n log('debug', '👫 - OAuth2CodeGranter Service Initialized!');\n\n return {\n type: CODE_GRANTER_TYPE,\n authorizer: {\n responseType: 'code',\n authorize: authorizeWithCode,\n },\n acknowledger: {\n acknowledgmentType: 'code',\n acknowledge: acknowledgeWithCode,\n },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: authenticateWithCode,\n },\n };\n}\n"],"file":"oAuth2CodeGranter.mjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _oAuth2CodeGranter = _interopRequireDefault(require("./oAuth2CodeGranter"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('OAuth2CodeGranter', () => {
|
|
8
|
+
const oAuth2Code = {
|
|
9
|
+
create: jest.fn(),
|
|
10
|
+
check: jest.fn()
|
|
11
|
+
};
|
|
12
|
+
const checkApplication = jest.fn();
|
|
13
|
+
const log = jest.fn();
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
oAuth2Code.create.mockReset();
|
|
16
|
+
oAuth2Code.check.mockReset();
|
|
17
|
+
checkApplication.mockReset();
|
|
18
|
+
log.mockReset();
|
|
19
|
+
});
|
|
20
|
+
it('should work with a complete valid flow', async () => {
|
|
21
|
+
const oAuth2CodeGranter = await (0, _oAuth2CodeGranter.default)({
|
|
22
|
+
checkApplication,
|
|
23
|
+
oAuth2Code,
|
|
24
|
+
log
|
|
25
|
+
});
|
|
26
|
+
checkApplication.mockResolvedValue({
|
|
27
|
+
redirectURI: 'https://www.example.com'
|
|
28
|
+
});
|
|
29
|
+
oAuth2Code.create.mockResolvedValueOnce('yolo');
|
|
30
|
+
oAuth2Code.check.mockResolvedValueOnce({
|
|
31
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
32
|
+
scope: 'user'
|
|
33
|
+
});
|
|
34
|
+
const authorizerResult = await oAuth2CodeGranter.authorizer.authorize({
|
|
35
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
36
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
37
|
+
scope: 'user'
|
|
38
|
+
});
|
|
39
|
+
const acknowledgerResult = await oAuth2CodeGranter.acknowledger.acknowledge({
|
|
40
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
41
|
+
scope: 'user, admin'
|
|
42
|
+
}, {
|
|
43
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
44
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
45
|
+
scope: 'user'
|
|
46
|
+
}, {});
|
|
47
|
+
const authenticatorResult = await oAuth2CodeGranter.authenticator.authenticate({
|
|
48
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
49
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
50
|
+
code: 'yolo'
|
|
51
|
+
}, {
|
|
52
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
53
|
+
scope: 'user'
|
|
54
|
+
});
|
|
55
|
+
expect({
|
|
56
|
+
authorizerResult,
|
|
57
|
+
acknowledgerResult,
|
|
58
|
+
authenticatorResult
|
|
59
|
+
}).toMatchInlineSnapshot(`
|
|
60
|
+
Object {
|
|
61
|
+
"acknowledgerResult": Object {
|
|
62
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
63
|
+
"code": "yolo",
|
|
64
|
+
"redirectURI": "https://www.example.com/oauth2/code",
|
|
65
|
+
"scope": "user",
|
|
66
|
+
},
|
|
67
|
+
"authenticatorResult": Object {
|
|
68
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
69
|
+
"scope": "user",
|
|
70
|
+
},
|
|
71
|
+
"authorizerResult": Object {
|
|
72
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
73
|
+
"redirectURI": "https://www.example.com",
|
|
74
|
+
"scope": "user",
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
`);
|
|
78
|
+
expect({
|
|
79
|
+
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
80
|
+
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
81
|
+
checkApplicationCalls: checkApplication.mock.calls,
|
|
82
|
+
logCalls: log.mock.calls
|
|
83
|
+
}).toMatchSnapshot();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=oAuth2CodeGranter.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2CodeGranter.test.ts"],"names":["describe","oAuth2Code","create","jest","fn","check","checkApplication","log","beforeEach","mockReset","it","oAuth2CodeGranter","mockResolvedValue","redirectURI","mockResolvedValueOnce","applicationId","scope","authorizerResult","authorizer","authorize","clientId","acknowledgerResult","acknowledger","acknowledge","authenticatorResult","authenticator","authenticate","code","expect","toMatchInlineSnapshot","oAuth2CodeCreateCalls","mock","calls","oAuth2CodeCheckCalls","checkApplicationCalls","logCalls","toMatchSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,mBAAD,EAAsB,MAAM;AAClC,QAAMC,UAAU,GAAG;AACjBC,IAAAA,MAAM,EAAEC,IAAI,CAACC,EAAL,EADS;AAEjBC,IAAAA,KAAK,EAAEF,IAAI,CAACC,EAAL;AA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,KAL+B,EAU/B,EAV+B,CAAjC;AAYA,UAAMQ,mBAAmB,GACvB,MAAMb,iBAAiB,CAACc,aAAlB,CAAgCC,YAAhC,CACJ;AACEN,MAAAA,QAAQ,EAAE,sCADZ;AAEEP,MAAAA,WAAW,EAAE,qCAFf;AAGEc,MAAAA,IAAI,EAAE;AAHR,KADI,EAMJ;AACEZ,MAAAA,aAAa,EAAE,sCADjB;AAEEC,MAAAA,KAAK,EAAE;AAFT,KANI,CADR;AAaAY,IAAAA,MAAM,CAAC;AACLX,MAAAA,gBADK;AAELI,MAAAA,kBAFK;AAGLG,MAAAA;AAHK,KAAD,CAAN,CAIGK,qBAJH,CAI0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAtBI;AAuBAD,IAAAA,MAAM,CAAC;AACLE,MAAAA,qBAAqB,EAAE7B,UAAU,CAACC,MAAX,CAAkB6B,IAAlB,CAAuBC,KADzC;AAELC,MAAAA,oBAAoB,EAAEhC,UAAU,CAACI,KAAX,CAAiB0B,IAAjB,CAAsBC,KAFvC;AAGLE,MAAAA,qBAAqB,EAAE5B,gBAAgB,CAACyB,IAAjB,CAAsBC,KAHxC;AAILG,MAAAA,QAAQ,EAAE5B,GAAG,CAACwB,IAAJ,CAASC;AAJd,KAAD,CAAN,CAKGI,eALH;AAMD,GA3EC,CAAF;AA4ED,CA3FO,CAAR","sourcesContent":["import initOAuth2CodeGranter from './oAuth2CodeGranter';\n\ndescribe('OAuth2CodeGranter', () => {\n const oAuth2Code = {\n create: jest.fn(),\n check: jest.fn(),\n };\n const checkApplication = jest.fn();\n const log = jest.fn();\n\n beforeEach(() => {\n oAuth2Code.create.mockReset();\n oAuth2Code.check.mockReset();\n checkApplication.mockReset();\n log.mockReset();\n });\n\n it('should work with a complete valid flow', async () => {\n const oAuth2CodeGranter = await initOAuth2CodeGranter({\n checkApplication,\n oAuth2Code,\n log,\n });\n\n checkApplication.mockResolvedValue({\n redirectURI: 'https://www.example.com',\n });\n oAuth2Code.create.mockResolvedValueOnce('yolo');\n oAuth2Code.check.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n });\n\n const authorizerResult = await oAuth2CodeGranter.authorizer.authorize({\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n });\n const acknowledgerResult = await oAuth2CodeGranter.acknowledger.acknowledge(\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user, admin',\n },\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n },\n {},\n );\n const authenticatorResult =\n await oAuth2CodeGranter.authenticator.authenticate(\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n code: 'yolo',\n },\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n );\n\n expect({\n authorizerResult,\n acknowledgerResult,\n authenticatorResult,\n }).toMatchInlineSnapshot(`\n Object {\n \"acknowledgerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"code\": \"yolo\",\n \"redirectURI\": \"https://www.example.com/oauth2/code\",\n \"scope\": \"user\",\n },\n \"authenticatorResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"scope\": \"user\",\n },\n \"authorizerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"redirectURI\": \"https://www.example.com\",\n \"scope\": \"user\",\n },\n }\n `);\n expect({\n oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,\n oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,\n checkApplicationCalls: checkApplication.mock.calls,\n logCalls: log.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"file":"oAuth2CodeGranter.test.js"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import initOAuth2CodeGranter from './oAuth2CodeGranter';
|
|
2
|
+
describe('OAuth2CodeGranter', () => {
|
|
3
|
+
const oAuth2Code = {
|
|
4
|
+
create: jest.fn(),
|
|
5
|
+
check: jest.fn()
|
|
6
|
+
};
|
|
7
|
+
const checkApplication = jest.fn();
|
|
8
|
+
const log = jest.fn();
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
oAuth2Code.create.mockReset();
|
|
11
|
+
oAuth2Code.check.mockReset();
|
|
12
|
+
checkApplication.mockReset();
|
|
13
|
+
log.mockReset();
|
|
14
|
+
});
|
|
15
|
+
it('should work with a complete valid flow', async () => {
|
|
16
|
+
const oAuth2CodeGranter = await initOAuth2CodeGranter({
|
|
17
|
+
checkApplication,
|
|
18
|
+
oAuth2Code,
|
|
19
|
+
log
|
|
20
|
+
});
|
|
21
|
+
checkApplication.mockResolvedValue({
|
|
22
|
+
redirectURI: 'https://www.example.com'
|
|
23
|
+
});
|
|
24
|
+
oAuth2Code.create.mockResolvedValueOnce('yolo');
|
|
25
|
+
oAuth2Code.check.mockResolvedValueOnce({
|
|
26
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
27
|
+
scope: 'user'
|
|
28
|
+
});
|
|
29
|
+
const authorizerResult = await oAuth2CodeGranter.authorizer.authorize({
|
|
30
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
31
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
32
|
+
scope: 'user'
|
|
33
|
+
});
|
|
34
|
+
const acknowledgerResult = await oAuth2CodeGranter.acknowledger.acknowledge({
|
|
35
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
36
|
+
scope: 'user, admin'
|
|
37
|
+
}, {
|
|
38
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
39
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
40
|
+
scope: 'user'
|
|
41
|
+
}, {});
|
|
42
|
+
const authenticatorResult = await oAuth2CodeGranter.authenticator.authenticate({
|
|
43
|
+
clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
44
|
+
redirectURI: 'https://www.example.com/oauth2/code',
|
|
45
|
+
code: 'yolo'
|
|
46
|
+
}, {
|
|
47
|
+
applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',
|
|
48
|
+
scope: 'user'
|
|
49
|
+
});
|
|
50
|
+
expect({
|
|
51
|
+
authorizerResult,
|
|
52
|
+
acknowledgerResult,
|
|
53
|
+
authenticatorResult
|
|
54
|
+
}).toMatchInlineSnapshot(`
|
|
55
|
+
Object {
|
|
56
|
+
"acknowledgerResult": Object {
|
|
57
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
58
|
+
"code": "yolo",
|
|
59
|
+
"redirectURI": "https://www.example.com/oauth2/code",
|
|
60
|
+
"scope": "user",
|
|
61
|
+
},
|
|
62
|
+
"authenticatorResult": Object {
|
|
63
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
64
|
+
"scope": "user",
|
|
65
|
+
},
|
|
66
|
+
"authorizerResult": Object {
|
|
67
|
+
"applicationId": "abbacaca-abba-caca-abba-cacaabbacaca",
|
|
68
|
+
"redirectURI": "https://www.example.com",
|
|
69
|
+
"scope": "user",
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
`);
|
|
73
|
+
expect({
|
|
74
|
+
oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,
|
|
75
|
+
oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,
|
|
76
|
+
checkApplicationCalls: checkApplication.mock.calls,
|
|
77
|
+
logCalls: log.mock.calls
|
|
78
|
+
}).toMatchSnapshot();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
//# sourceMappingURL=oAuth2CodeGranter.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2CodeGranter.test.ts"],"names":["initOAuth2CodeGranter","describe","oAuth2Code","create","jest","fn","check","checkApplication","log","beforeEach","mockReset","it","oAuth2CodeGranter","mockResolvedValue","redirectURI","mockResolvedValueOnce","applicationId","scope","authorizerResult","authorizer","authorize","clientId","acknowledgerResult","acknowledger","acknowledge","authenticatorResult","authenticator","authenticate","code","expect","toMatchInlineSnapshot","oAuth2CodeCreateCalls","mock","calls","oAuth2CodeCheckCalls","checkApplicationCalls","logCalls","toMatchSnapshot"],"mappings":"AAAA,OAAOA,qBAAP,MAAkC,qBAAlC;AAEAC,QAAQ,CAAC,mBAAD,EAAsB,MAAM;AAClC,QAAMC,UAAU,GAAG;AACjBC,IAAAA,MAAM,EAAEC,IAAI,CAACC,EAAL,EADS;AAEjBC,IAAAA,KAAK,EAAEF,IAAI,CAACC,EAAL;AAFU,GAAnB;AAIA,QAAME,gBAAgB,GAAGH,IAAI,CAACC,EAAL,EAAzB;AACA,QAAMG,GAAG,GAAGJ,IAAI,CAACC,EAAL,EAAZ;AAEAI,EAAAA,UAAU,CAAC,MAAM;AACfP,IAAAA,UAAU,CAACC,MAAX,CAAkBO,SAAlB;AACAR,IAAAA,UAAU,CAACI,KAAX,CAAiBI,SAAjB;AACAH,IAAAA,gBAAgB,CAACG,SAAjB;AACAF,IAAAA,GAAG,CAACE,SAAJ;AACD,GALS,CAAV;AAOAC,EAAAA,EAAE,CAAC,wCAAD,EAA2C,YAAY;AACvD,UAAMC,iBAAiB,GAAG,MAAMZ,qBAAqB,CAAC;AACpDO,MAAAA,gBADoD;AAEpDL,MAAAA,UAFoD;AAGpDM,MAAAA;AAHoD,KAAD,CAArD;AAMAD,IAAAA,gBAAgB,CAACM,iBAAjB,CAAmC;AACjCC,MAAAA,WAAW,EAAE;AADoB,KAAnC;AAGAZ,IAAAA,UAAU,CAACC,MAAX,CAAkBY,qBAAlB,CAAwC,MAAxC;AACAb,IAAAA,UAA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,KAAX,CAAiB0B,IAAjB,CAAsBC,KAFvC;AAGLE,MAAAA,qBAAqB,EAAE5B,gBAAgB,CAACyB,IAAjB,CAAsBC,KAHxC;AAILG,MAAAA,QAAQ,EAAE5B,GAAG,CAACwB,IAAJ,CAASC;AAJd,KAAD,CAAN,CAKGI,eALH;AAMD,GA3EC,CAAF;AA4ED,CA3FO,CAAR","sourcesContent":["import initOAuth2CodeGranter from './oAuth2CodeGranter';\n\ndescribe('OAuth2CodeGranter', () => {\n const oAuth2Code = {\n create: jest.fn(),\n check: jest.fn(),\n };\n const checkApplication = jest.fn();\n const log = jest.fn();\n\n beforeEach(() => {\n oAuth2Code.create.mockReset();\n oAuth2Code.check.mockReset();\n checkApplication.mockReset();\n log.mockReset();\n });\n\n it('should work with a complete valid flow', async () => {\n const oAuth2CodeGranter = await initOAuth2CodeGranter({\n checkApplication,\n oAuth2Code,\n log,\n });\n\n checkApplication.mockResolvedValue({\n redirectURI: 'https://www.example.com',\n });\n oAuth2Code.create.mockResolvedValueOnce('yolo');\n oAuth2Code.check.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n });\n\n const authorizerResult = await oAuth2CodeGranter.authorizer.authorize({\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n });\n const acknowledgerResult = await oAuth2CodeGranter.acknowledger.acknowledge(\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user, admin',\n },\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n scope: 'user',\n },\n {},\n );\n const authenticatorResult =\n await oAuth2CodeGranter.authenticator.authenticate(\n {\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com/oauth2/code',\n code: 'yolo',\n },\n {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n );\n\n expect({\n authorizerResult,\n acknowledgerResult,\n authenticatorResult,\n }).toMatchInlineSnapshot(`\n Object {\n \"acknowledgerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"code\": \"yolo\",\n \"redirectURI\": \"https://www.example.com/oauth2/code\",\n \"scope\": \"user\",\n },\n \"authenticatorResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"scope\": \"user\",\n },\n \"authorizerResult\": Object {\n \"applicationId\": \"abbacaca-abba-caca-abba-cacaabbacaca\",\n \"redirectURI\": \"https://www.example.com\",\n \"scope\": \"user\",\n },\n }\n `);\n expect({\n oAuth2CodeCreateCalls: oAuth2Code.create.mock.calls,\n oAuth2CodeCheckCalls: oAuth2Code.check.mock.calls,\n checkApplicationCalls: checkApplication.mock.calls,\n logCalls: log.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"file":"oAuth2CodeGranter.test.mjs"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { WhookErrorsDescriptors } from '@whook/whook';
|
|
2
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
3
|
+
export declare const OAUTH2_ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
4
|
+
export declare type OAuth2CodeService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData, CODE = string> = {
|
|
5
|
+
create: (authenticationData: AUTHENTICATION_DATA, redirectURI: string, additionalParameters: {
|
|
6
|
+
[name: string]: unknown;
|
|
7
|
+
}) => Promise<CODE>;
|
|
8
|
+
check: (authenticationData: AUTHENTICATION_DATA, code: CODE, redirectURI: string) => Promise<AUTHENTICATION_DATA & {
|
|
9
|
+
redirectURI: string;
|
|
10
|
+
} & {
|
|
11
|
+
[name: string]: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
export declare type OAuth2PasswordService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData, USERNAME = string, PASSWORD = string> = {
|
|
15
|
+
check: (authenticationData: AUTHENTICATION_DATA, username: USERNAME, password: PASSWORD, demandedScope: AUTHENTICATION_DATA['scope']) => Promise<AUTHENTICATION_DATA>;
|
|
16
|
+
};
|
|
17
|
+
export declare type OAuth2AccessTokenService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData, TOKEN = string> = {
|
|
18
|
+
create: (authenticationData: AUTHENTICATION_DATA, tokenAuthenticationData: AUTHENTICATION_DATA, additionalParameters?: {
|
|
19
|
+
[name: string]: unknown;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
token: TOKEN;
|
|
22
|
+
expiresAt: number;
|
|
23
|
+
}>;
|
|
24
|
+
check: (authenticationData: AUTHENTICATION_DATA, token: TOKEN, scope?: AUTHENTICATION_DATA['scope']) => Promise<AUTHENTICATION_DATA>;
|
|
25
|
+
};
|
|
26
|
+
export declare type OAuth2RefreshTokenService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData, TOKEN = string> = OAuth2AccessTokenService<AUTHENTICATION_DATA, TOKEN>;
|
|
27
|
+
export declare type CheckApplicationService = {
|
|
28
|
+
(context: {
|
|
29
|
+
applicationId: string;
|
|
30
|
+
type: string;
|
|
31
|
+
scope: string;
|
|
32
|
+
redirectURI?: string;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
applicationId: string;
|
|
35
|
+
type: string;
|
|
36
|
+
scope: string;
|
|
37
|
+
redirectURI: string;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
export declare 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>, AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData> = {
|
|
41
|
+
type: string;
|
|
42
|
+
authorizer?: {
|
|
43
|
+
responseType: string;
|
|
44
|
+
authorize: (context: {
|
|
45
|
+
clientId: AUTHENTICATION_DATA['applicationId'];
|
|
46
|
+
redirectURI: string;
|
|
47
|
+
scope: AUTHENTICATION_DATA['scope'];
|
|
48
|
+
}, authorizeParameters?: AUTHORIZE_PARAMETERS) => Promise<{
|
|
49
|
+
applicationId: AUTHENTICATION_DATA['applicationId'];
|
|
50
|
+
redirectURI: string;
|
|
51
|
+
scope: AUTHENTICATION_DATA['scope'];
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
acknowledger?: {
|
|
55
|
+
acknowledgmentType: string;
|
|
56
|
+
acknowledge: (authenticationData: AUTHENTICATION_DATA, acknowledgeParameters: {
|
|
57
|
+
clientId: AUTHENTICATION_DATA['applicationId'];
|
|
58
|
+
redirectURI: string;
|
|
59
|
+
scope: AUTHENTICATION_DATA['applicationId'];
|
|
60
|
+
}, additionalParameters: ACKNOWLEDGE_PARAMETERS) => Promise<AUTHENTICATION_DATA & {
|
|
61
|
+
redirectURI: string;
|
|
62
|
+
[name: string]: unknown;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
authenticator?: {
|
|
66
|
+
grantType: string;
|
|
67
|
+
authenticate: (grantParameters: GRANT_PARAMETERS, authenticationData: AUTHENTICATION_DATA) => Promise<AUTHENTICATION_DATA>;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export declare type OAuth2Options = {
|
|
71
|
+
authenticateURL: string;
|
|
72
|
+
defaultToClientScope?: boolean;
|
|
73
|
+
};
|
|
74
|
+
export declare type OAuth2Config = {
|
|
75
|
+
OAUTH2: OAuth2Options;
|
|
76
|
+
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
77
|
+
};
|
|
78
|
+
declare const _default: import("knifecycle").ServiceInitializer<unknown, any[]>;
|
|
79
|
+
export default _default;
|