@whook/oauth2 25.2.1 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -98
- package/dist/index.d.ts +30 -11
- package/dist/index.js +15 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1258 -399
- package/dist/index.test.js.map +1 -1
- package/dist/libs/clients.d.ts +2 -0
- package/dist/libs/clients.js +13 -0
- package/dist/libs/clients.js.map +1 -0
- package/dist/libs/errors.d.ts +113 -0
- package/dist/libs/errors.js +178 -0
- package/dist/libs/errors.js.map +1 -0
- package/dist/libs/grants.d.ts +2 -0
- package/dist/libs/grants.js +10 -0
- package/dist/libs/grants.js.map +1 -0
- package/dist/libs/redirectURI.d.ts +7 -0
- package/dist/libs/redirectURI.js +78 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +23 -0
- package/dist/libs/schemas.js +25 -0
- package/dist/libs/schemas.js.map +1 -0
- package/dist/libs/scopes.d.ts +16 -0
- package/dist/libs/scopes.js +37 -0
- package/dist/libs/scopes.js.map +1 -1
- package/dist/libs/utils.d.ts +2 -0
- package/dist/libs/utils.js +17 -0
- package/dist/libs/utils.js.map +1 -0
- package/dist/libs/verifier.d.ts +7 -0
- package/dist/libs/verifier.js +37 -0
- package/dist/libs/verifier.js.map +1 -0
- package/dist/libs/verifier.test.js +21 -0
- package/dist/libs/verifier.test.js.map +1 -0
- package/dist/routes/getOAuth2Authorize.d.ts +13 -50
- package/dist/routes/getOAuth2Authorize.js +60 -86
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +147 -68
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js +15 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +37 -37
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +3 -6
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
- package/dist/routes/postAuthLogin.d.ts +14 -9
- package/dist/routes/postAuthLogin.js +10 -5
- package/dist/routes/postAuthLogin.js.map +1 -1
- package/dist/routes/postAuthLogin.test.js +79 -55
- package/dist/routes/postAuthLogin.test.js.map +1 -1
- package/dist/routes/postAuthLogout.d.ts +5 -2
- package/dist/routes/postAuthLogout.js +12 -7
- package/dist/routes/postAuthLogout.js.map +1 -1
- package/dist/routes/postAuthLogout.test.js +35 -17
- package/dist/routes/postAuthLogout.test.js.map +1 -1
- package/dist/routes/postAuthRefresh.d.ts +14 -9
- package/dist/routes/postAuthRefresh.js +10 -6
- package/dist/routes/postAuthRefresh.js.map +1 -1
- package/dist/routes/postAuthRefresh.test.js +90 -59
- package/dist/routes/postAuthRefresh.test.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.d.ts +11 -10
- package/dist/routes/postOAuth2Acknowledge.js +43 -37
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +135 -70
- package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/routes/postOAuth2Revoke.d.ts +99 -0
- package/dist/routes/postOAuth2Revoke.js +102 -0
- package/dist/routes/postOAuth2Revoke.js.map +1 -0
- package/dist/routes/postOAuth2Revoke.test.d.ts +1 -0
- package/dist/routes/postOAuth2Revoke.test.js +161 -0
- package/dist/routes/postOAuth2Revoke.test.js.map +1 -0
- package/dist/routes/postOAuth2Token.d.ts +35 -108
- package/dist/routes/postOAuth2Token.js +53 -114
- package/dist/routes/postOAuth2Token.js.map +1 -1
- package/dist/routes/postOAuth2Token.test.js +493 -61
- package/dist/routes/postOAuth2Token.test.js.map +1 -1
- package/dist/services/authCookies.d.ts +9 -13
- package/dist/services/authCookies.js +1 -1
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +129 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +221 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +474 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +28 -12
- package/dist/services/oAuth2ClientCredentialsGranter.js +39 -21
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js +265 -0
- package/dist/services/oAuth2ClientCredentialsGranter.test.js.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +81 -86
- package/dist/services/oAuth2Granters.js +2 -67
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2ImplicitGranter.d.ts +38 -0
- package/dist/services/oAuth2ImplicitGranter.js +72 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +727 -0
- package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +43 -10
- package/dist/services/oAuth2PasswordGranter.js +53 -18
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.test.d.ts +1 -0
- package/dist/services/oAuth2PasswordGranter.test.js +455 -0
- package/dist/services/oAuth2PasswordGranter.test.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +42 -9
- package/dist/services/oAuth2RefreshTokenGranter.js +60 -21
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.test.d.ts +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js +403 -0
- package/dist/services/oAuth2RefreshTokenGranter.test.js.map +1 -0
- package/package.json +11 -11
- package/src/index.test.ts +1314 -404
- package/src/index.ts +46 -53
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +325 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +120 -0
- package/src/libs/schemas.ts +27 -0
- package/src/libs/scopes.ts +49 -0
- package/src/libs/utils.ts +24 -0
- package/src/libs/verifier.test.ts +37 -0
- package/src/libs/verifier.ts +57 -0
- package/src/routes/getOAuth2Authorize.test.ts +179 -96
- package/src/routes/getOAuth2Authorize.ts +97 -124
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +57 -60
- package/src/routes/getOAuth2WellKnownMetadata.ts +21 -10
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +4 -6
- package/src/routes/postAuthLogin.test.ts +86 -57
- package/src/routes/postAuthLogin.ts +24 -14
- package/src/routes/postAuthLogout.test.ts +42 -18
- package/src/routes/postAuthLogout.ts +22 -8
- package/src/routes/postAuthRefresh.test.ts +98 -61
- package/src/routes/postAuthRefresh.ts +25 -13
- package/src/routes/postOAuth2Acknowledge.test.ts +167 -108
- package/src/routes/postOAuth2Acknowledge.ts +90 -64
- package/src/routes/postOAuth2Revoke.test.ts +179 -0
- package/src/routes/postOAuth2Revoke.ts +156 -0
- package/src/routes/postOAuth2Token.test.ts +570 -108
- package/src/routes/postOAuth2Token.ts +92 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +16 -18
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +564 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +388 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +101 -195
- package/src/services/oAuth2ImplicitGranter.test.ts +811 -0
- package/src/services/oAuth2ImplicitGranter.ts +163 -0
- package/src/services/oAuth2PasswordGranter.test.ts +493 -0
- package/src/services/oAuth2PasswordGranter.ts +116 -40
- package/src/services/oAuth2RefreshTokenGranter.test.ts +441 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +118 -51
- package/src/types.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +0 -41
- package/dist/services/oAuth2CodeGranter.js +0 -105
- package/dist/services/oAuth2CodeGranter.js.map +0 -1
- package/dist/services/oAuth2CodeGranter.test.js +0 -123
- package/dist/services/oAuth2CodeGranter.test.js.map +0 -1
- package/dist/services/oAuth2TokenGranter.d.ts +0 -22
- package/dist/services/oAuth2TokenGranter.js +0 -64
- package/dist/services/oAuth2TokenGranter.js.map +0 -1
- package/src/__snapshots__/index.test.ts.snap +0 -401
- package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -37
- package/src/routes/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -61
- package/src/routes/__snapshots__/postOAuth2Token.test.ts.snap +0 -52
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +0 -52
- package/src/services/oAuth2CodeGranter.test.ts +0 -176
- package/src/services/oAuth2CodeGranter.ts +0 -210
- package/src/services/oAuth2TokenGranter.ts +0 -119
- /package/dist/{services/oAuth2CodeGranter.test.d.ts → libs/verifier.test.d.ts} +0 -0
package/dist/libs/scopes.js
CHANGED
|
@@ -1,4 +1,41 @@
|
|
|
1
|
+
import { identity } from '@whook/whook';
|
|
1
2
|
import { PATH_ITEM_METHODS } from 'ya-open-api-types';
|
|
3
|
+
import { YError } from 'yerror';
|
|
4
|
+
const OAUTH2_SCOPES_SEPARATOR = ' ';
|
|
5
|
+
/**
|
|
6
|
+
* Splits a scope into its scope tokens
|
|
7
|
+
*/
|
|
8
|
+
export function parseOAuth2Scope(oAuth2Scope) {
|
|
9
|
+
const scopes = [
|
|
10
|
+
...new Set(oAuth2Scope.split(OAUTH2_SCOPES_SEPARATOR).filter(identity)),
|
|
11
|
+
];
|
|
12
|
+
return scopes;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Join scopes into scope tokens
|
|
16
|
+
*/
|
|
17
|
+
export function stringifyScopes(scopes) {
|
|
18
|
+
return scopes.join(OAUTH2_SCOPES_SEPARATOR);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Filter scopes tokens to become valid ones
|
|
22
|
+
*/
|
|
23
|
+
export function filterScopes(scopes, allowedScopes, strict) {
|
|
24
|
+
const filteredScopes = [];
|
|
25
|
+
for (const scope of scopes) {
|
|
26
|
+
if (allowedScopes.includes(scope)) {
|
|
27
|
+
filteredScopes.push(scope);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (strict) {
|
|
31
|
+
throw new YError('E_OAUTH2_BAD_SCOPE', [scope]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return filteredScopes;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Collects all scopes tokens from an Open API
|
|
38
|
+
*/
|
|
2
39
|
export function collectScopesFromAPI(API) {
|
|
3
40
|
const scopes = [];
|
|
4
41
|
if (API?.security) {
|
package/dist/libs/scopes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/libs/scopes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../src/libs/scopes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;GAEG;AACH,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MAAM,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAClD,KAAK,MAAM,MAAM,IAAI,iBAAiB,EAAE,CAAC;gBACvC,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;gBAErC,IAAI,SAAS,EAAE,QAAQ,EAAE,CAAC;oBACxB,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;wBAC7C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;4BACvC,MAAM,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;wBACnC,CAAC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import camelCase from 'camelcase';
|
|
2
|
+
// The OAuth2 standard uses snake case names so we are
|
|
3
|
+
// converting them to the project standards asap
|
|
4
|
+
export function camelCaseObjectProperties(object) {
|
|
5
|
+
return Object.keys(object).reduce((camelCasedObject, key) => {
|
|
6
|
+
const newKey = key === 'redirect_uri' ? 'redirectURI' : camelCase(key);
|
|
7
|
+
camelCasedObject[newKey] = object[key];
|
|
8
|
+
return camelCasedObject;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
export function snakeCase(s) {
|
|
12
|
+
return s
|
|
13
|
+
.split(/(?=(?<![A-Z])[A-Z])|[^a-zA-Z]+/)
|
|
14
|
+
.map((s) => s.toLowerCase())
|
|
15
|
+
.join('_');
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/libs/utils.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,sDAAsD;AACtD,gDAAgD;AAChD,MAAM,UAAU,yBAAyB,CACvC,MAAyB;IAEzB,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAC/B,CAAC,gBAAgB,EAAE,GAAG,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEvE,gBAAgB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,gBAAgB,CAAC;IAC1B,CAAC,EACD,EAAuB,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,CAAC;SACL,KAAK,CAAC,gCAAgC,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type CodeChallengeMethod = (typeof CODE_CHALLENGE_METHODS)[number];
|
|
2
|
+
export declare const PLAIN_CODE_CHALLENGE_METHOD = "plain";
|
|
3
|
+
export declare const S256_CODE_CHALLENGE_METHOD = "S256";
|
|
4
|
+
export declare const CODE_CHALLENGE_METHODS: readonly ["plain", "S256"];
|
|
5
|
+
export declare function base64UrlEncode(buf: Buffer): string;
|
|
6
|
+
export declare function computeCodeChallenge(codeChallengeMethod: CodeChallengeMethod, codeVerifier: string): string;
|
|
7
|
+
export declare function checkCodeChallenge(codeChallengeMethod: CodeChallengeMethod, codeChallenge: string, codeVerifier: string): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { YError } from 'yerror';
|
|
3
|
+
export const PLAIN_CODE_CHALLENGE_METHOD = 'plain';
|
|
4
|
+
export const S256_CODE_CHALLENGE_METHOD = 'S256';
|
|
5
|
+
export const CODE_CHALLENGE_METHODS = [
|
|
6
|
+
PLAIN_CODE_CHALLENGE_METHOD,
|
|
7
|
+
S256_CODE_CHALLENGE_METHOD,
|
|
8
|
+
];
|
|
9
|
+
// See https://tools.ietf.org/html/rfc7636#appendix-A
|
|
10
|
+
export function base64UrlEncode(buf) {
|
|
11
|
+
let s = buf.toString('base64');
|
|
12
|
+
s = s.split('=')[0];
|
|
13
|
+
s = s.replaceAll('+', '-');
|
|
14
|
+
s = s.replaceAll('/', '_');
|
|
15
|
+
return s;
|
|
16
|
+
}
|
|
17
|
+
export function computeCodeChallenge(codeChallengeMethod, codeVerifier) {
|
|
18
|
+
if (PLAIN_CODE_CHALLENGE_METHOD === codeChallengeMethod) {
|
|
19
|
+
return codeVerifier;
|
|
20
|
+
}
|
|
21
|
+
if (S256_CODE_CHALLENGE_METHOD === codeChallengeMethod) {
|
|
22
|
+
return base64UrlEncode(createHash('sha256').update(Buffer.from(codeVerifier)).digest());
|
|
23
|
+
}
|
|
24
|
+
throw new YError('E_OAUTH2_UNSUPPORTED_CODE_CHALLENGE_METHOD', [
|
|
25
|
+
codeChallengeMethod,
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
export function checkCodeChallenge(codeChallengeMethod, codeChallenge, codeVerifier) {
|
|
29
|
+
const computedCodeChallenge = computeCodeChallenge(codeChallengeMethod, codeVerifier);
|
|
30
|
+
if (computedCodeChallenge !== codeChallenge) {
|
|
31
|
+
throw new YError('E_OAUTH2_BAD_CODE_VERIFIER', [
|
|
32
|
+
codeChallenge,
|
|
33
|
+
computedCodeChallenge,
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=verifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../src/libs/verifier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,CACb,CAAC;IAEF,IAAI,qBAAqB,KAAK,aAAa,EAAE,CAAC;QAC5C,MAAM,IAAI,MAAM,CAAC,4BAA4B,EAAE;YAC7C,aAAa;YACb,qBAAqB;SACtB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, test, expect } from '@jest/globals';
|
|
2
|
+
import { base64UrlEncode, computeCodeChallenge } from './verifier.js';
|
|
3
|
+
describe('base64UrlEncode()', () => {
|
|
4
|
+
test('should work like here https://tools.ietf.org/html/rfc7636#appendix-A', () => {
|
|
5
|
+
expect(base64UrlEncode(Buffer.from([
|
|
6
|
+
116, 24, 223, 180, 151, 153, 224, 37, 79, 250, 96, 125, 216, 173, 187,
|
|
7
|
+
186, 22, 212, 37, 77, 105, 214, 191, 240, 91, 88, 5, 88, 83, 132, 141,
|
|
8
|
+
121,
|
|
9
|
+
]))).toEqual('dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk');
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
describe('computeCodeChallenge()', () => {
|
|
13
|
+
test('should work with plain method', () => {
|
|
14
|
+
expect(computeCodeChallenge('plain', 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk')).toEqual('dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk');
|
|
15
|
+
});
|
|
16
|
+
// See https://tools.ietf.org/html/rfc7636#appendix-A
|
|
17
|
+
test('should work like for the spec example', () => {
|
|
18
|
+
expect(computeCodeChallenge('S256', 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk')).toEqual('E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM');
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=verifier.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifier.test.js","sourceRoot":"","sources":["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"}
|
|
@@ -1,42 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import { type OAuth2Options, type OAuth2GranterService } from '../services/oAuth2Granters.js';
|
|
1
|
+
import { type WhookErrorsDescriptors } from '@whook/whook';
|
|
2
|
+
import { type WhookOAuth2Options, type WhookOAuth2GranterService, type WhookOAuth2GranterDefinitions } from '../services/oAuth2Granters.js';
|
|
4
3
|
import { type LogService } from 'common-services';
|
|
5
|
-
import { CodeChallengeMethod } from '../
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
readonly type: "string";
|
|
10
|
-
readonly minLength: 43;
|
|
11
|
-
readonly maxLength: 128;
|
|
12
|
-
readonly pattern: "^[A-Za-z0-9\\-._~]{43,128}$";
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export declare const codeChallengeParameter: {
|
|
16
|
-
readonly name: "code_challenge";
|
|
17
|
-
readonly parameter: {
|
|
18
|
-
readonly in: "query";
|
|
19
|
-
readonly name: "code_challenge";
|
|
20
|
-
readonly required: false;
|
|
21
|
-
readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare const codeChallengeMethodSchema: {
|
|
25
|
-
readonly name: "CodeChallengeMethod";
|
|
26
|
-
readonly schema: {
|
|
27
|
-
readonly type: "string";
|
|
28
|
-
readonly enum: ("plain" | "S256")[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export declare const codeChallengeMethodParameter: {
|
|
32
|
-
readonly name: "code_challenge_method";
|
|
33
|
-
readonly parameter: {
|
|
34
|
-
readonly in: "query";
|
|
35
|
-
readonly name: "code_challenge_method";
|
|
36
|
-
readonly required: false;
|
|
37
|
-
readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
4
|
+
import { type CodeChallengeMethod } from '../libs/verifier.js';
|
|
5
|
+
import { scopeSchema } from '../libs/schemas.js';
|
|
6
|
+
import { codeChallengeMethodSchema, codeChallengeMethodParameter, codeChallengeSchema, codeChallengeParameter } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
7
|
+
export { scopeSchema, codeChallengeMethodSchema, codeChallengeMethodParameter, codeChallengeSchema, codeChallengeParameter, };
|
|
40
8
|
export declare const responseTypeParameter: {
|
|
41
9
|
readonly name: "responseType";
|
|
42
10
|
readonly parameter: {
|
|
@@ -78,11 +46,8 @@ export declare const scopeParameter: {
|
|
|
78
46
|
readonly parameter: {
|
|
79
47
|
readonly in: "query";
|
|
80
48
|
readonly name: "scope";
|
|
81
|
-
readonly description: "See https://tools.ietf.org/html/rfc6749#section-3.3";
|
|
82
49
|
readonly required: false;
|
|
83
|
-
readonly schema:
|
|
84
|
-
readonly type: "string";
|
|
85
|
-
};
|
|
50
|
+
readonly schema: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
86
51
|
};
|
|
87
52
|
};
|
|
88
53
|
export declare const stateParameter: {
|
|
@@ -90,7 +55,7 @@ export declare const stateParameter: {
|
|
|
90
55
|
readonly parameter: {
|
|
91
56
|
readonly in: "query";
|
|
92
57
|
readonly name: "state";
|
|
93
|
-
readonly required:
|
|
58
|
+
readonly required: false;
|
|
94
59
|
readonly schema: {
|
|
95
60
|
readonly type: "string";
|
|
96
61
|
};
|
|
@@ -101,7 +66,7 @@ export declare const definition: {
|
|
|
101
66
|
readonly path: "/oauth2/authorize";
|
|
102
67
|
readonly operation: {
|
|
103
68
|
readonly operationId: "getOAuth2Authorize";
|
|
104
|
-
readonly summary: "Implements the [Authorization Endpoint](https://
|
|
69
|
+
readonly summary: "Implements the [Authorization Endpoint](https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-15.html#section-3.1)\n as defined per the OAuth2.1 RFC.";
|
|
105
70
|
readonly tags: ["oauth2"];
|
|
106
71
|
readonly parameters: [import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>, import("ya-open-api-types").OpenAPIReference<import("ya-open-api-types").OpenAPIParameter<import("ya-json-schema-types").ExpressiveJSONSchema, import("ya-open-api-types").OpenAPIExtension>>];
|
|
107
72
|
readonly responses: {
|
|
@@ -111,14 +76,12 @@ export declare const definition: {
|
|
|
111
76
|
};
|
|
112
77
|
};
|
|
113
78
|
};
|
|
114
|
-
export declare function camelCaseObjectProperties<T>(object: Record<string, T>): Record<string, T>;
|
|
115
|
-
export declare function setURLError(url: URL, err: YError | Error, oAuth2Error: WhookErrorDescriptor): void;
|
|
116
79
|
declare const _default: import("knifecycle").ServiceInitializer<{
|
|
117
|
-
OAUTH2:
|
|
80
|
+
OAUTH2: WhookOAuth2Options;
|
|
118
81
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
119
|
-
oAuth2Granters:
|
|
82
|
+
oAuth2Granters: WhookOAuth2GranterService<WhookOAuth2GranterDefinitions>[];
|
|
120
83
|
log: LogService;
|
|
121
|
-
}, ({ query: { response_type: responseType, client_id:
|
|
84
|
+
}, ({ query: { response_type: responseType, client_id: givenClientId, redirect_uri: demandedRedirectURI, scope: demandedScope, state, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod, ...authorizeParameters }, }: {
|
|
122
85
|
query: {
|
|
123
86
|
response_type: string;
|
|
124
87
|
client_id: string;
|
|
@@ -127,7 +90,7 @@ declare const _default: import("knifecycle").ServiceInitializer<{
|
|
|
127
90
|
state: string;
|
|
128
91
|
code_challenge?: string;
|
|
129
92
|
code_challenge_method?: CodeChallengeMethod;
|
|
130
|
-
} & Record<string,
|
|
93
|
+
} & Record<string, string>;
|
|
131
94
|
}) => Promise<{
|
|
132
95
|
status: number;
|
|
133
96
|
headers: {
|
|
@@ -1,47 +1,21 @@
|
|
|
1
1
|
import { autoService, location } from 'knifecycle';
|
|
2
|
-
import camelCase from 'camelcase';
|
|
3
2
|
import { YError, printStackTrace } from 'yerror';
|
|
4
3
|
import { refersTo, } from '@whook/whook';
|
|
5
|
-
import {
|
|
4
|
+
import { filterScopes, parseOAuth2Scope, stringifyScopes, } from '../libs/scopes.js';
|
|
5
|
+
import { PLAIN_CODE_CHALLENGE_METHOD, } from '../libs/verifier.js';
|
|
6
|
+
import { scopeSchema } from '../libs/schemas.js';
|
|
7
|
+
import { AUTHORIZATION_CODE_RESPONSE_TYPE, codeChallengeMethodSchema, codeChallengeMethodParameter, codeChallengeSchema, codeChallengeParameter, } from '../services/oAuth2AuthorizationCodeGranter.js';
|
|
8
|
+
import { IMPLICIT_RESPONSE_TYPE } from '../services/oAuth2ImplicitGranter.js';
|
|
9
|
+
import { camelCaseObjectProperties } from '../libs/utils.js';
|
|
10
|
+
import { addParamsToURL, buildParamsFromError } from '../libs/redirectURI.js';
|
|
11
|
+
export { scopeSchema, codeChallengeMethodSchema, codeChallengeMethodParameter, codeChallengeSchema, codeChallengeParameter, };
|
|
6
12
|
/* Architecture Note #1: OAuth2 authorize
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
|
|
14
|
+
This endpoint simply redirects the user to the authentication
|
|
15
|
+
server page and checks the application details are
|
|
9
16
|
fine.
|
|
17
|
+
|
|
10
18
|
*/
|
|
11
|
-
export const codeChallengeSchema = {
|
|
12
|
-
name: 'CodeChallenge',
|
|
13
|
-
schema: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
minLength: 43,
|
|
16
|
-
maxLength: 128,
|
|
17
|
-
pattern: '^[A-Za-z0-9\\-._~]{43,128}$',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
export const codeChallengeParameter = {
|
|
21
|
-
name: 'code_challenge',
|
|
22
|
-
parameter: {
|
|
23
|
-
in: 'query',
|
|
24
|
-
name: 'code_challenge',
|
|
25
|
-
required: false,
|
|
26
|
-
schema: refersTo(codeChallengeSchema),
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
export const codeChallengeMethodSchema = {
|
|
30
|
-
name: 'CodeChallengeMethod',
|
|
31
|
-
schema: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
enum: CODE_CHALLENGE_METHODS.concat(),
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
export const codeChallengeMethodParameter = {
|
|
37
|
-
name: 'code_challenge_method',
|
|
38
|
-
parameter: {
|
|
39
|
-
in: 'query',
|
|
40
|
-
name: 'code_challenge_method',
|
|
41
|
-
required: false,
|
|
42
|
-
schema: refersTo(codeChallengeMethodSchema),
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
19
|
export const responseTypeParameter = {
|
|
46
20
|
name: 'responseType',
|
|
47
21
|
parameter: {
|
|
@@ -50,7 +24,7 @@ export const responseTypeParameter = {
|
|
|
50
24
|
required: true,
|
|
51
25
|
schema: {
|
|
52
26
|
type: 'string',
|
|
53
|
-
enum: [
|
|
27
|
+
enum: [AUTHORIZATION_CODE_RESPONSE_TYPE, IMPLICIT_RESPONSE_TYPE],
|
|
54
28
|
},
|
|
55
29
|
},
|
|
56
30
|
};
|
|
@@ -83,11 +57,8 @@ export const scopeParameter = {
|
|
|
83
57
|
parameter: {
|
|
84
58
|
in: 'query',
|
|
85
59
|
name: 'scope',
|
|
86
|
-
description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',
|
|
87
60
|
required: false,
|
|
88
|
-
schema:
|
|
89
|
-
type: 'string',
|
|
90
|
-
},
|
|
61
|
+
schema: refersTo(scopeSchema),
|
|
91
62
|
},
|
|
92
63
|
};
|
|
93
64
|
export const stateParameter = {
|
|
@@ -95,7 +66,7 @@ export const stateParameter = {
|
|
|
95
66
|
parameter: {
|
|
96
67
|
in: 'query',
|
|
97
68
|
name: 'state',
|
|
98
|
-
required:
|
|
69
|
+
required: false,
|
|
99
70
|
schema: {
|
|
100
71
|
type: 'string',
|
|
101
72
|
},
|
|
@@ -106,8 +77,8 @@ export const definition = {
|
|
|
106
77
|
path: '/oauth2/authorize',
|
|
107
78
|
operation: {
|
|
108
79
|
operationId: 'getOAuth2Authorize',
|
|
109
|
-
summary: `Implements the [Authorization Endpoint](https://
|
|
110
|
-
as defined per the OAuth2 RFC.`,
|
|
80
|
+
summary: `Implements the [Authorization Endpoint](https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-15.html#section-3.1)
|
|
81
|
+
as defined per the OAuth2.1 RFC.`,
|
|
111
82
|
tags: ['oauth2'],
|
|
112
83
|
parameters: [
|
|
113
84
|
refersTo(responseTypeParameter),
|
|
@@ -125,64 +96,67 @@ export const definition = {
|
|
|
125
96
|
},
|
|
126
97
|
},
|
|
127
98
|
};
|
|
128
|
-
// The OAuth2 standard uses snake case names so we are
|
|
129
|
-
// converting them to the project standards asap
|
|
130
|
-
export function camelCaseObjectProperties(object) {
|
|
131
|
-
return Object.keys(object).reduce((camelCasedObject, key) => {
|
|
132
|
-
const newKey = key === 'redirect_uri' ? 'redirectURI' : camelCase(key);
|
|
133
|
-
camelCasedObject[newKey] = object[key];
|
|
134
|
-
return camelCasedObject;
|
|
135
|
-
}, {});
|
|
136
|
-
}
|
|
137
|
-
export function setURLError(url, err, oAuth2Error) {
|
|
138
|
-
url.searchParams.set('error', oAuth2Error.code);
|
|
139
|
-
if (oAuth2Error.description) {
|
|
140
|
-
url.searchParams.set('error_description', oAuth2Error.description.replace(/\$([0-9]+)/g, (_, paramIndex) => {
|
|
141
|
-
return (err.debug || [])[parseInt(paramIndex, 10)];
|
|
142
|
-
}));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
99
|
async function initGetOAuth2Authorize({ OAUTH2, ERRORS_DESCRIPTORS, oAuth2Granters, log, }) {
|
|
146
|
-
return async ({ query: { response_type: responseType, client_id:
|
|
147
|
-
|
|
100
|
+
return async ({ query: { response_type: responseType, client_id: givenClientId, redirect_uri: demandedRedirectURI = '', scope: demandedScope = '', state, code_challenge: codeChallenge, code_challenge_method: codeChallengeMethod, ...authorizeParameters }, }) => {
|
|
101
|
+
// If everything goes well we proxy the request
|
|
102
|
+
// to the authentication server for acknowledgment
|
|
103
|
+
let url = new URL(OAUTH2.authenticateURL);
|
|
148
104
|
try {
|
|
149
|
-
const granter = oAuth2Granters.find((granter) => granter.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
throw new YError('E_UNKNOWN_AUTHORIZER_TYPE', [responseType]);
|
|
105
|
+
const granter = oAuth2Granters.find((granter) => granter.responseType === responseType);
|
|
106
|
+
if (!granter?.authorize) {
|
|
107
|
+
throw new YError('E_OAUTH2_UNKNOWN_RESPONSE_TYPE', [responseType]);
|
|
153
108
|
}
|
|
154
109
|
if (responseType === 'code') {
|
|
155
110
|
if (!codeChallenge) {
|
|
156
111
|
if (OAUTH2.forcePKCE) {
|
|
157
|
-
throw new YError('
|
|
112
|
+
throw new YError('E_OAUTH2_PKCE_REQUIRED', [responseType]);
|
|
158
113
|
}
|
|
159
114
|
}
|
|
160
115
|
}
|
|
161
116
|
else if (codeChallenge) {
|
|
162
|
-
throw new YError('
|
|
117
|
+
throw new YError('E_OAUTH2_PKCE_NOT_SUPPORTED', [responseType]);
|
|
163
118
|
}
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
119
|
+
const demandedScopes = filterScopes(parseOAuth2Scope(demandedScope), OAUTH2.allowedScopes, !!OAUTH2.strictScopesChecks);
|
|
120
|
+
const { clientId, redirectURI, scopes } = await granter.authorize({
|
|
121
|
+
clientId: givenClientId,
|
|
122
|
+
demandedRedirectURI,
|
|
123
|
+
demandedScopes,
|
|
168
124
|
}, camelCaseObjectProperties(authorizeParameters));
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
125
|
+
const paramsHash = {
|
|
126
|
+
type: responseType,
|
|
127
|
+
redirect_uri: redirectURI,
|
|
128
|
+
scope: stringifyScopes(scopes),
|
|
129
|
+
client_id: clientId,
|
|
130
|
+
};
|
|
173
131
|
if (responseType === 'code' && codeChallenge) {
|
|
174
|
-
|
|
175
|
-
|
|
132
|
+
paramsHash.code_challenge = codeChallenge;
|
|
133
|
+
paramsHash.code_challenge_method =
|
|
134
|
+
codeChallengeMethod || PLAIN_CODE_CHALLENGE_METHOD;
|
|
135
|
+
}
|
|
136
|
+
if (state) {
|
|
137
|
+
paramsHash.state = state;
|
|
176
138
|
}
|
|
139
|
+
addParamsToURL(url, paramsHash, 'query');
|
|
177
140
|
}
|
|
178
141
|
catch (err) {
|
|
179
142
|
log('debug', '👫 - OAuth2 authorize error.');
|
|
180
143
|
log('error-stack', printStackTrace(err));
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
144
|
+
// If errors happen we try to directly redirect
|
|
145
|
+
// to the demanded redirect URI
|
|
146
|
+
try {
|
|
147
|
+
url = new URL(demandedRedirectURI);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
log('debug', `💥 - Could not redirect to demanded uri.`);
|
|
151
|
+
log('debug-stack', printStackTrace(err));
|
|
152
|
+
url = new URL(OAUTH2.authenticateURL);
|
|
153
|
+
}
|
|
154
|
+
const paramsHash = buildParamsFromError(err, ERRORS_DESCRIPTORS[err.code] ||
|
|
155
|
+
ERRORS_DESCRIPTORS.E_OAUTH2_UNEXPECTED_ERROR);
|
|
156
|
+
if (state) {
|
|
157
|
+
paramsHash.state = state;
|
|
158
|
+
}
|
|
159
|
+
addParamsToURL(url, paramsHash, responseType === 'token' ? 'fragment' : 'query');
|
|
186
160
|
}
|
|
187
161
|
return {
|
|
188
162
|
status: 302,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getOAuth2Authorize.js","sourceRoot":"","sources":["../../src/routes/getOAuth2Authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"getOAuth2Authorize.js","sourceRoot":"","sources":["../../src/routes/getOAuth2Authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,QAAQ,GAIT,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,gCAAgC,EAChC,yBAAyB,EACzB,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EACL,WAAW,EACX,yBAAyB,EACzB,4BAA4B,EAC5B,mBAAmB,EACnB,sBAAsB,GACvB,CAAC;AAEF;;;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