@whook/oauth2 25.1.0 → 25.2.1
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/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +5 -5
- package/dist/index.test.js.map +1 -1
- package/dist/libs/scopes.d.ts +2 -0
- package/dist/libs/scopes.js +27 -0
- package/dist/libs/scopes.js.map +1 -0
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +8 -1
- package/dist/routes/getOAuth2WellKnownMetadata.js +14 -8
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +40 -2
- package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +79 -0
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +86 -0
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -0
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.test.d.ts +1 -0
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.test.js +44 -0
- package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.test.js.map +1 -0
- package/dist/routes/postOAuth2Acknowledge.d.ts +9 -0
- package/dist/routes/postOAuth2Acknowledge.js +12 -2
- package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
- package/dist/routes/postOAuth2Acknowledge.test.js +2 -2
- package/dist/services/authCookies.d.ts +2 -1
- package/dist/services/authCookies.js.map +1 -1
- package/package.json +4 -4
- package/src/index.test.ts +5 -5
- package/src/index.ts +11 -0
- package/src/libs/scopes.ts +31 -0
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +41 -2
- package/src/routes/getOAuth2WellKnownMetadata.ts +19 -12
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.test.ts +49 -0
- package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +115 -0
- package/src/routes/postOAuth2Acknowledge.test.ts +2 -2
- package/src/routes/postOAuth2Acknowledge.ts +16 -2
- package/src/services/authCookies.ts +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
2
|
+
import initGetOAuth2WellKnownProtectedResourceMetadata from './getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
3
|
+
describe('getOAuth2WellKnownProtectedResourceMetadata', () => {
|
|
4
|
+
const log = jest.fn();
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
log.mockReset();
|
|
7
|
+
});
|
|
8
|
+
test('should return OAuth2 protected resource metadata', async () => {
|
|
9
|
+
const getOAuth2WellKnownProtectedResourceMetadata = await initGetOAuth2WellKnownProtectedResourceMetadata({
|
|
10
|
+
BASE_URL: 'https://server.example.com',
|
|
11
|
+
API: {
|
|
12
|
+
openapi: '3.2',
|
|
13
|
+
info: {
|
|
14
|
+
title: 'Test',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
log,
|
|
19
|
+
});
|
|
20
|
+
const response = await getOAuth2WellKnownProtectedResourceMetadata();
|
|
21
|
+
expect({
|
|
22
|
+
response,
|
|
23
|
+
logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),
|
|
24
|
+
}).toMatchInlineSnapshot(`
|
|
25
|
+
{
|
|
26
|
+
"logCalls": [],
|
|
27
|
+
"response": {
|
|
28
|
+
"body": {
|
|
29
|
+
"authorization_servers": [
|
|
30
|
+
"https://server.example.com",
|
|
31
|
+
],
|
|
32
|
+
"bearer_methods_supported": [
|
|
33
|
+
"header",
|
|
34
|
+
],
|
|
35
|
+
"resource": "https://server.example.com",
|
|
36
|
+
"scopes_supported": [],
|
|
37
|
+
},
|
|
38
|
+
"status": 200,
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=getOAuth2WellKnownProtectedResourceMetadata.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOAuth2WellKnownProtectedResourceMetadata.test.js","sourceRoot":"","sources":["../../src/routes/getOAuth2WellKnownProtectedResourceMetadata.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,+CAA+C,MAAM,kDAAkD,CAAC;AAG/G,QAAQ,CAAC,6CAA6C,EAAE,GAAG,EAAE;IAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,EAAc,CAAC;IAElC,UAAU,CAAC,GAAG,EAAE;QACd,GAAG,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,MAAM,2CAA2C,GAC/C,MAAM,+CAA+C,CAAC;YACpD,QAAQ,EAAE,4BAA4B;YACtC,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK;gBACd,IAAI,EAAE;oBACJ,KAAK,EAAE,MAAM;oBACb,OAAO,EAAE,OAAO;iBACjB;aACF;YACD,GAAG;SACJ,CAAC,CAAC;QACL,MAAM,QAAQ,GAAG,MAAM,2CAA2C,EAAE,CAAC;QAErE,MAAM,CAAC;YACL,QAAQ;YACR,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;SACrE,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;KAiBxB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -42,6 +42,8 @@ export declare const definition: {
|
|
|
42
42
|
readonly type: "boolean";
|
|
43
43
|
readonly description: "Wether the user acknowledged the delegation or not.";
|
|
44
44
|
};
|
|
45
|
+
readonly codeChallenge: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
46
|
+
readonly codeChallengeMethod: import("ya-json-schema-types").ExpressiveJSONSchema;
|
|
45
47
|
};
|
|
46
48
|
};
|
|
47
49
|
};
|
|
@@ -50,6 +52,13 @@ export declare const definition: {
|
|
|
50
52
|
readonly responses: {
|
|
51
53
|
readonly '201': {
|
|
52
54
|
readonly description: "Redirection endpoint URI computed.";
|
|
55
|
+
readonly headers: {
|
|
56
|
+
readonly location: {
|
|
57
|
+
readonly schema: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
};
|
|
53
62
|
readonly content: {
|
|
54
63
|
readonly 'application/json': {
|
|
55
64
|
readonly schema: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { autoService, location } from 'knifecycle';
|
|
2
2
|
import { printStackTrace, YError } from 'yerror';
|
|
3
|
-
import { setURLError } from './getOAuth2Authorize.js';
|
|
3
|
+
import { codeChallengeMethodSchema, codeChallengeSchema, setURLError, } from './getOAuth2Authorize.js';
|
|
4
|
+
import { refersTo, } from '@whook/whook';
|
|
4
5
|
/* Architecture Note #2: OAuth2 acknowledge
|
|
5
6
|
This endpoint is to be used by the authentication SSR frontend
|
|
6
7
|
to acknowledge that the user accepted the client request in it.
|
|
@@ -53,6 +54,8 @@ export const definition = {
|
|
|
53
54
|
type: 'boolean',
|
|
54
55
|
description: 'Wether the user acknowledged the delegation or not.',
|
|
55
56
|
},
|
|
57
|
+
codeChallenge: refersTo(codeChallengeSchema),
|
|
58
|
+
codeChallengeMethod: refersTo(codeChallengeMethodSchema),
|
|
56
59
|
},
|
|
57
60
|
},
|
|
58
61
|
},
|
|
@@ -61,6 +64,13 @@ export const definition = {
|
|
|
61
64
|
responses: {
|
|
62
65
|
'201': {
|
|
63
66
|
description: 'Redirection endpoint URI computed.',
|
|
67
|
+
headers: {
|
|
68
|
+
location: {
|
|
69
|
+
schema: {
|
|
70
|
+
type: 'string',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
64
74
|
content: {
|
|
65
75
|
'application/json': {
|
|
66
76
|
schema: {
|
|
@@ -121,7 +131,7 @@ async function initPostOAuth2Acknowledge({ ERRORS_DESCRIPTORS, oAuth2Granters, c
|
|
|
121
131
|
setURLError(url, err, ERRORS_DESCRIPTORS[err.code] || ERRORS_DESCRIPTORS.E_OAUTH2);
|
|
122
132
|
}
|
|
123
133
|
return {
|
|
124
|
-
status:
|
|
134
|
+
status: 201,
|
|
125
135
|
headers: {
|
|
126
136
|
location: url.href,
|
|
127
137
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postOAuth2Acknowledge.js","sourceRoot":"","sources":["../../src/routes/postOAuth2Acknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.js","sourceRoot":"","sources":["../../src/routes/postOAuth2Acknowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACjD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,QAAQ,GACT,MAAM,cAAc,CAAC;AAQtB;;;EAGE;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,qBAAqB;IAC3B,MAAM,EAAE;QACN,OAAO,EAAE,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CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,CAAS;IAC1B,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"}
|
|
@@ -98,7 +98,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
98
98
|
"headers": {
|
|
99
99
|
"location": "https://www.example.com/?my_custom_parameter=a_custom_value&client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&code=a_valid_code",
|
|
100
100
|
},
|
|
101
|
-
"status":
|
|
101
|
+
"status": 201,
|
|
102
102
|
},
|
|
103
103
|
}
|
|
104
104
|
`);
|
|
@@ -149,7 +149,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
149
149
|
"headers": {
|
|
150
150
|
"location": "https://www.example.com/?error=unsupported_response_type&error_description=Type+%22yolo%22+not+supported.",
|
|
151
151
|
},
|
|
152
|
-
"status":
|
|
152
|
+
"status": 201,
|
|
153
153
|
},
|
|
154
154
|
}
|
|
155
155
|
`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type SerializeOptions } from 'cookie';
|
|
2
2
|
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
3
3
|
import { type Jsonify } from 'type-fest';
|
|
4
|
+
import { type WhookRouteDefinitionBasePath } from '@whook/whook';
|
|
4
5
|
export declare const AUTH_API_PREFIX = "/auth";
|
|
5
6
|
export interface AuthHandlersConfig {
|
|
6
7
|
ROOT_AUTHENTICATION_DATA: WhookAuthenticationData;
|
|
@@ -8,7 +9,7 @@ export interface AuthHandlersConfig {
|
|
|
8
9
|
export type AuthCookiesOptions = Jsonify<Omit<SerializeOptions, 'maxAge' | 'path' | 'expires'>>;
|
|
9
10
|
export interface AuthCookiesConfig {
|
|
10
11
|
COOKIES: AuthCookiesOptions;
|
|
11
|
-
BASE_PATH?:
|
|
12
|
+
BASE_PATH?: WhookRouteDefinitionBasePath;
|
|
12
13
|
}
|
|
13
14
|
export type AuthCookiesDependencies = AuthCookiesConfig;
|
|
14
15
|
export interface AuthCookiesData {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authCookies.js","sourceRoot":"","sources":["../../src/services/authCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,MAAiC,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"authCookies.js","sourceRoot":"","sources":["../../src/services/authCookies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,MAAiC,MAAM,QAAQ,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKnD,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AA8BvC,eAAe,QAAQ,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEvE,KAAK,UAAU,eAAe,CAAC,EAC7B,OAAO,EACP,SAAS,GAAG,EAAE,GACU;IACxB,SAAS,KAAK,CAAC,OAAiC,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,EAAE;QACzE,OAAO;YACL,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,YAAY,IAAI,EAAE,EAAE;gBACxD,IAAI,EAAE,SAAS,GAAG,eAAe;gBACjC,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,IAAI;gBACZ,GAAG,OAAO;gBACV,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;aAC5C,CAAC;YACF,MAAM,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,aAAa,IAAI,EAAE,EAAE;gBAC1D,IAAI,EAAE,SAAS,GAAG,eAAe;gBACjC,QAAQ,EAAE,IAAI;gBACd,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,IAAI;gBACZ,GAAG,OAAO;gBACV,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;aAC9D,CAAC;SACH,CAAC;IACJ,CAAC;IAED,SAAS,KAAK,CAAC,YAAoB;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAExC,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC5C,OAAO;gBACL,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;aAClC,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO;QACL,KAAK;QACL,KAAK;KACN,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"name": "@whook/oauth2",
|
|
26
|
-
"version": "25.1
|
|
26
|
+
"version": "25.2.1",
|
|
27
27
|
"description": "OAuth2 implementation for Whook servers",
|
|
28
28
|
"type": "module",
|
|
29
29
|
"publishConfig": {
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/nfroidure/whook",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@whook/authorization": "^25.1
|
|
50
|
-
"@whook/whook": "^25.
|
|
49
|
+
"@whook/authorization": "^25.2.1",
|
|
50
|
+
"@whook/whook": "^25.2.0",
|
|
51
51
|
"camelcase": "^9.0.0",
|
|
52
52
|
"common-services": "^20.0.0",
|
|
53
53
|
"cookie": "^1.1.1",
|
|
@@ -135,7 +135,7 @@
|
|
|
135
135
|
"rebuild": "swc ./src -s -d dist -C jsc.target=es2022",
|
|
136
136
|
"test": "node --run jest"
|
|
137
137
|
},
|
|
138
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "4eef31d0363f2a117f4acdbdb5d565a78092481e",
|
|
139
139
|
"funding": {
|
|
140
140
|
"type": "individual",
|
|
141
141
|
"url": "https://github.com/sponsors/nfroidure"
|
package/src/index.test.ts
CHANGED
|
@@ -88,11 +88,11 @@ describe('OAuth2 server', () => {
|
|
|
88
88
|
description: 'A sample OpenAPI file for testing purpose.',
|
|
89
89
|
},
|
|
90
90
|
paths: {
|
|
91
|
-
[getOAuth2AuthorizeDefinition.path]: {
|
|
91
|
+
[`${BASE_PATH}${getOAuth2AuthorizeDefinition.path}`]: {
|
|
92
92
|
[getOAuth2AuthorizeDefinition.method]:
|
|
93
93
|
getOAuth2AuthorizeDefinition.operation,
|
|
94
94
|
},
|
|
95
|
-
[postOAuth2AcknowledgeDefinition.path]: {
|
|
95
|
+
[`${BASE_PATH}${postOAuth2AcknowledgeDefinition.path}`]: {
|
|
96
96
|
[postOAuth2AcknowledgeDefinition.method]: {
|
|
97
97
|
...postOAuth2AcknowledgeDefinition.operation,
|
|
98
98
|
security: [
|
|
@@ -102,7 +102,7 @@ describe('OAuth2 server', () => {
|
|
|
102
102
|
],
|
|
103
103
|
},
|
|
104
104
|
},
|
|
105
|
-
[postOAuth2TokenDefinition.path]: {
|
|
105
|
+
[`${BASE_PATH}${postOAuth2TokenDefinition.path}`]: {
|
|
106
106
|
[postOAuth2TokenDefinition.method]: {
|
|
107
107
|
...postOAuth2TokenDefinition.operation,
|
|
108
108
|
security: [
|
|
@@ -759,7 +759,7 @@ describe('OAuth2 server', () => {
|
|
|
759
759
|
"transfer-encoding": "chunked",
|
|
760
760
|
"x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
|
|
761
761
|
},
|
|
762
|
-
"status":
|
|
762
|
+
"status": 201,
|
|
763
763
|
}
|
|
764
764
|
`);
|
|
765
765
|
expect({
|
|
@@ -1038,7 +1038,7 @@ describe('OAuth2 server', () => {
|
|
|
1038
1038
|
"transfer-encoding": "chunked",
|
|
1039
1039
|
"x-authenticated": "{"applicationId":"acdc41ce-acdc-41ce-acdc-41ceacdc41ce","scope":"user,oauth","userId":"2"}",
|
|
1040
1040
|
},
|
|
1041
|
-
"status":
|
|
1041
|
+
"status": 201,
|
|
1042
1042
|
}
|
|
1043
1043
|
`);
|
|
1044
1044
|
expect({
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,11 @@ import initGetOAuth2WellKnown, {
|
|
|
30
30
|
httpsProtocolURISchema as getOAuth2WellKnownHTTPSProtocolURISchema,
|
|
31
31
|
oAuth2MetadataSchema as getOAuth2WellKnownOAuth2MetadataSchema,
|
|
32
32
|
} from './routes/getOAuth2WellKnownMetadata.js';
|
|
33
|
+
import initGetOAuth2WellKnownProtectedResource, {
|
|
34
|
+
definition as getOAuth2WellKnownProtectedResourceDefinition,
|
|
35
|
+
bearerMethodSchema as getOAuth2WellKnownProtectedResourceBearerMethodSchema,
|
|
36
|
+
oAuth2ProtectedResourceMetadataSchema as getOAuth2WellKnownProtectedResourceSchema,
|
|
37
|
+
} from './routes/getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
33
38
|
import initOAuth2Granters, {
|
|
34
39
|
type OAuth2YErrorRegistry,
|
|
35
40
|
OAUTH2_ERRORS_DESCRIPTORS,
|
|
@@ -72,6 +77,7 @@ import initOAuth2CodeGranter, {
|
|
|
72
77
|
type CodeChallengeMethod,
|
|
73
78
|
type OAuth2CodeService,
|
|
74
79
|
} from './services/oAuth2CodeGranter.js';
|
|
80
|
+
import { collectScopesFromAPI } from './libs/scopes.js';
|
|
75
81
|
|
|
76
82
|
declare module 'yerror' {
|
|
77
83
|
interface YErrorRegistry extends OAuth2YErrorRegistry {
|
|
@@ -114,6 +120,10 @@ export {
|
|
|
114
120
|
getOAuth2WellKnownJsonWebEncryptionsSchema,
|
|
115
121
|
getOAuth2WellKnownHTTPSProtocolURISchema,
|
|
116
122
|
getOAuth2WellKnownOAuth2MetadataSchema,
|
|
123
|
+
initGetOAuth2WellKnownProtectedResource,
|
|
124
|
+
getOAuth2WellKnownProtectedResourceDefinition,
|
|
125
|
+
getOAuth2WellKnownProtectedResourceBearerMethodSchema,
|
|
126
|
+
getOAuth2WellKnownProtectedResourceSchema,
|
|
117
127
|
base64UrlEncode,
|
|
118
128
|
hashCodeVerifier,
|
|
119
129
|
initPostOAuth2Acknowledge,
|
|
@@ -142,4 +152,5 @@ export {
|
|
|
142
152
|
initPostAuthRefresh,
|
|
143
153
|
postAuthRefreshDefinition,
|
|
144
154
|
initAuthCookiesService,
|
|
155
|
+
collectScopesFromAPI,
|
|
145
156
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type OpenAPI, PATH_ITEM_METHODS } from 'ya-open-api-types';
|
|
2
|
+
|
|
3
|
+
export function collectScopesFromAPI(API: OpenAPI) {
|
|
4
|
+
const scopes: string[] = [];
|
|
5
|
+
|
|
6
|
+
if (API?.security) {
|
|
7
|
+
for (const requirement of API.security) {
|
|
8
|
+
Object.keys(requirement).forEach((key) => {
|
|
9
|
+
scopes.push(...requirement[key]);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (API.paths) {
|
|
15
|
+
for (const pathObject of Object.values(API.paths)) {
|
|
16
|
+
for (const method of PATH_ITEM_METHODS) {
|
|
17
|
+
const operation = pathObject[method];
|
|
18
|
+
|
|
19
|
+
if (operation?.security) {
|
|
20
|
+
for (const requirement of operation.security) {
|
|
21
|
+
Object.keys(requirement).forEach((key) => {
|
|
22
|
+
scopes.push(...requirement[key]);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [...new Set(scopes)];
|
|
31
|
+
}
|
|
@@ -6,6 +6,7 @@ import { type OAuth2CodeGranterService } from '../services/oAuth2CodeGranter.js'
|
|
|
6
6
|
import { type OAuth2TokenGranterService } from '../services/oAuth2TokenGranter.js';
|
|
7
7
|
import { type LogService } from 'common-services';
|
|
8
8
|
import { type OAuth2GranterService } from '../index.js';
|
|
9
|
+
import { type WhookRoutesDefinitionsService } from '@whook/whook';
|
|
9
10
|
|
|
10
11
|
describe('getOAuth2WellKnown', () => {
|
|
11
12
|
const log = jest.fn<LogService>();
|
|
@@ -81,7 +82,40 @@ describe('getOAuth2WellKnown', () => {
|
|
|
81
82
|
|
|
82
83
|
const getOAuth2WellKnown = await initGetOAuth2WellKnown({
|
|
83
84
|
BASE_URL: 'https://server.example.com',
|
|
84
|
-
|
|
85
|
+
ROUTES_DEFINITIONS: {
|
|
86
|
+
getOAuth2Authorize: {
|
|
87
|
+
module: {
|
|
88
|
+
definition: {
|
|
89
|
+
path: '/v0/oauth2/authorize',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
postOAuth2Token: {
|
|
94
|
+
module: {
|
|
95
|
+
definition: {
|
|
96
|
+
path: '/v0/oauth2/token',
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
} as unknown as WhookRoutesDefinitionsService,
|
|
101
|
+
API: {
|
|
102
|
+
openapi: '3.2',
|
|
103
|
+
info: {
|
|
104
|
+
title: 'Test',
|
|
105
|
+
version: '1.0.0',
|
|
106
|
+
},
|
|
107
|
+
paths: {
|
|
108
|
+
'/test': {
|
|
109
|
+
get: {
|
|
110
|
+
security: [
|
|
111
|
+
{
|
|
112
|
+
token: ['user', 'admin'],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
85
119
|
oAuth2Granters,
|
|
86
120
|
log,
|
|
87
121
|
});
|
|
@@ -112,14 +146,19 @@ describe('getOAuth2WellKnown', () => {
|
|
|
112
146
|
"grant_types_supported": [
|
|
113
147
|
"authorization_code",
|
|
114
148
|
],
|
|
115
|
-
"issuer": "https://server.example.com
|
|
149
|
+
"issuer": "https://server.example.com",
|
|
116
150
|
"response_types_supported": [
|
|
117
151
|
"code",
|
|
118
152
|
"token",
|
|
119
153
|
],
|
|
154
|
+
"scopes_supported": [
|
|
155
|
+
"user",
|
|
156
|
+
"admin",
|
|
157
|
+
],
|
|
120
158
|
"token_endpoint": "https://server.example.com/v0/oauth2/token",
|
|
121
159
|
"token_endpoint_auth_methods_supported": [
|
|
122
160
|
"client_secret_basic",
|
|
161
|
+
"client_secret_post",
|
|
123
162
|
],
|
|
124
163
|
},
|
|
125
164
|
"status": 200,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
identity,
|
|
3
3
|
refersTo,
|
|
4
|
+
type WhookRoutesDefinitionsService,
|
|
4
5
|
type WhookAPISchemaDefinition,
|
|
5
6
|
type WhookRouteDefinition,
|
|
6
7
|
} from '@whook/whook';
|
|
@@ -8,6 +9,8 @@ import { autoService, location } from 'knifecycle';
|
|
|
8
9
|
import { type OAuth2GranterService } from '../services/oAuth2Granters.js';
|
|
9
10
|
import { codeChallengeMethodSchema } from './getOAuth2Authorize.js';
|
|
10
11
|
import { type LogService } from 'common-services';
|
|
12
|
+
import { type OpenAPI } from 'ya-open-api-types';
|
|
13
|
+
import { collectScopesFromAPI } from '../libs/scopes.js';
|
|
11
14
|
|
|
12
15
|
// OAuth Token Endpoint Authentication Methods
|
|
13
16
|
export const endpointAuthenticationMethodsSchema = {
|
|
@@ -261,6 +264,9 @@ export const oAuth2MetadataSchema = {
|
|
|
261
264
|
export const definition = {
|
|
262
265
|
method: 'get',
|
|
263
266
|
path: '/.well-known/oauth-authorization-server',
|
|
267
|
+
config: {
|
|
268
|
+
global: true,
|
|
269
|
+
},
|
|
264
270
|
operation: {
|
|
265
271
|
operationId: 'getOAuth2WellKnownMetadata',
|
|
266
272
|
summary: `Provide the [OAuth 2.0 Authorization Server Metadata](https://datatracker.ietf.org/doc/html/rfc8414).`,
|
|
@@ -280,31 +286,31 @@ export const definition = {
|
|
|
280
286
|
} as const satisfies WhookRouteDefinition;
|
|
281
287
|
|
|
282
288
|
async function initGetOAuth2WellKnownMetadata({
|
|
289
|
+
API,
|
|
283
290
|
BASE_URL,
|
|
284
|
-
|
|
291
|
+
ROUTES_DEFINITIONS,
|
|
285
292
|
oAuth2Granters,
|
|
286
293
|
log,
|
|
287
294
|
}: {
|
|
295
|
+
API: OpenAPI;
|
|
288
296
|
BASE_URL: string;
|
|
289
|
-
|
|
297
|
+
ROUTES_DEFINITIONS: WhookRoutesDefinitionsService;
|
|
290
298
|
oAuth2Granters: OAuth2GranterService[];
|
|
291
299
|
log: LogService;
|
|
292
300
|
}) {
|
|
293
|
-
if (BASE_PATH) {
|
|
294
|
-
log(
|
|
295
|
-
'warning',
|
|
296
|
-
`⚠️ - Using a base path (${BASE_PATH}) breaks the well known URI discovery.`,
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
301
|
if (!BASE_URL.startsWith('https')) {
|
|
300
302
|
log('warning', `⚠️ - OAuth2 issuer must start with HTTPS (${BASE_URL}).`);
|
|
301
303
|
}
|
|
302
304
|
|
|
303
305
|
const body = {
|
|
304
|
-
issuer: `${BASE_URL}
|
|
305
|
-
authorization_endpoint: `${BASE_URL}${
|
|
306
|
-
token_endpoint: `${BASE_URL}${
|
|
307
|
-
|
|
306
|
+
issuer: `${BASE_URL}`,
|
|
307
|
+
authorization_endpoint: `${BASE_URL}${ROUTES_DEFINITIONS['getOAuth2Authorize']?.module.definition.path || '/oauth2/authorize'}`,
|
|
308
|
+
token_endpoint: `${BASE_URL}${ROUTES_DEFINITIONS['postOAuth2Token']?.module.definition.path || '/oauth2/token'}`,
|
|
309
|
+
// TODO: Put it behind options (allow none)
|
|
310
|
+
token_endpoint_auth_methods_supported: [
|
|
311
|
+
'client_secret_basic',
|
|
312
|
+
'client_secret_post',
|
|
313
|
+
],
|
|
308
314
|
grant_types_supported: [
|
|
309
315
|
...new Set(
|
|
310
316
|
oAuth2Granters
|
|
@@ -319,6 +325,7 @@ async function initGetOAuth2WellKnownMetadata({
|
|
|
319
325
|
.filter(identity),
|
|
320
326
|
),
|
|
321
327
|
],
|
|
328
|
+
scopes_supported: collectScopesFromAPI(API),
|
|
322
329
|
};
|
|
323
330
|
|
|
324
331
|
return async () => {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
2
|
+
import initGetOAuth2WellKnownProtectedResourceMetadata from './getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
3
|
+
import { type LogService } from 'common-services';
|
|
4
|
+
|
|
5
|
+
describe('getOAuth2WellKnownProtectedResourceMetadata', () => {
|
|
6
|
+
const log = jest.fn<LogService>();
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
log.mockReset();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('should return OAuth2 protected resource metadata', async () => {
|
|
13
|
+
const getOAuth2WellKnownProtectedResourceMetadata =
|
|
14
|
+
await initGetOAuth2WellKnownProtectedResourceMetadata({
|
|
15
|
+
BASE_URL: 'https://server.example.com',
|
|
16
|
+
API: {
|
|
17
|
+
openapi: '3.2',
|
|
18
|
+
info: {
|
|
19
|
+
title: 'Test',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
log,
|
|
24
|
+
});
|
|
25
|
+
const response = await getOAuth2WellKnownProtectedResourceMetadata();
|
|
26
|
+
|
|
27
|
+
expect({
|
|
28
|
+
response,
|
|
29
|
+
logCalls: log.mock.calls.filter((args) => args[0].endsWith('stack')),
|
|
30
|
+
}).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"logCalls": [],
|
|
33
|
+
"response": {
|
|
34
|
+
"body": {
|
|
35
|
+
"authorization_servers": [
|
|
36
|
+
"https://server.example.com",
|
|
37
|
+
],
|
|
38
|
+
"bearer_methods_supported": [
|
|
39
|
+
"header",
|
|
40
|
+
],
|
|
41
|
+
"resource": "https://server.example.com",
|
|
42
|
+
"scopes_supported": [],
|
|
43
|
+
},
|
|
44
|
+
"status": 200,
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type WhookAPISchemaDefinition,
|
|
3
|
+
type WhookRouteDefinition,
|
|
4
|
+
refersTo,
|
|
5
|
+
} from '@whook/whook';
|
|
6
|
+
import { autoService, location } from 'knifecycle';
|
|
7
|
+
import {
|
|
8
|
+
httpsProtocolURISchema,
|
|
9
|
+
jsonWebAlgorithmsSchema,
|
|
10
|
+
} from './getOAuth2WellKnownMetadata.js';
|
|
11
|
+
import { type LogService } from 'common-services';
|
|
12
|
+
import { type OpenAPI } from 'ya-open-api-types';
|
|
13
|
+
import { collectScopesFromAPI } from '../libs/scopes.js';
|
|
14
|
+
|
|
15
|
+
export const bearerMethodSchema = {
|
|
16
|
+
name: 'OAuth2BearerMethod',
|
|
17
|
+
schema: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
enum: ['body', 'header', 'query'],
|
|
20
|
+
},
|
|
21
|
+
} as const satisfies WhookAPISchemaDefinition;
|
|
22
|
+
|
|
23
|
+
export const oAuth2ProtectedResourceMetadataSchema = {
|
|
24
|
+
name: 'OAuth2ProtectedResourceMetadataSchema',
|
|
25
|
+
schema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['resource'],
|
|
28
|
+
properties: {
|
|
29
|
+
resource: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
format: 'uri',
|
|
32
|
+
},
|
|
33
|
+
authorization_servers: {
|
|
34
|
+
type: 'array',
|
|
35
|
+
items: refersTo(httpsProtocolURISchema),
|
|
36
|
+
},
|
|
37
|
+
jwks_uri: refersTo(httpsProtocolURISchema),
|
|
38
|
+
scopes_supported: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
items: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
bearer_methods_supported: {
|
|
45
|
+
type: 'array',
|
|
46
|
+
items: refersTo(bearerMethodSchema),
|
|
47
|
+
},
|
|
48
|
+
resource_signing_alg_values_supported: {
|
|
49
|
+
type: 'array',
|
|
50
|
+
items: refersTo(jsonWebAlgorithmsSchema),
|
|
51
|
+
},
|
|
52
|
+
resource_documentation: refersTo(httpsProtocolURISchema),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
} as const satisfies WhookAPISchemaDefinition;
|
|
56
|
+
|
|
57
|
+
export const definition = {
|
|
58
|
+
method: 'get',
|
|
59
|
+
path: '/.well-known/oauth-protected-resource',
|
|
60
|
+
config: {
|
|
61
|
+
global: true,
|
|
62
|
+
},
|
|
63
|
+
operation: {
|
|
64
|
+
operationId: 'getOAuth2WellKnownProtectedResourceMetadata',
|
|
65
|
+
summary: `Provide the [OAuth 2.0 Protected Resource Metadata](https://datatracker.ietf.org/doc/html/rfc9728).`,
|
|
66
|
+
tags: ['oauth2'],
|
|
67
|
+
parameters: [],
|
|
68
|
+
responses: {
|
|
69
|
+
'200': {
|
|
70
|
+
description: 'Well known OAuth2 protected resource metadata found.',
|
|
71
|
+
content: {
|
|
72
|
+
'application/json': {
|
|
73
|
+
schema: refersTo(oAuth2ProtectedResourceMetadataSchema),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
} as const satisfies WhookRouteDefinition;
|
|
80
|
+
|
|
81
|
+
async function initGetOAuth2WellKnownProtectedResourceMetadata({
|
|
82
|
+
BASE_URL,
|
|
83
|
+
API,
|
|
84
|
+
log,
|
|
85
|
+
}: {
|
|
86
|
+
BASE_URL: string;
|
|
87
|
+
API: OpenAPI;
|
|
88
|
+
log: LogService;
|
|
89
|
+
}) {
|
|
90
|
+
if (!BASE_URL.startsWith('https')) {
|
|
91
|
+
log(
|
|
92
|
+
'warning',
|
|
93
|
+
`⚠️ - OAuth2 protected resource metadata must use an HTTPS BASE_URL (${BASE_URL}).`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const body = {
|
|
98
|
+
resource: `${BASE_URL}`,
|
|
99
|
+
authorization_servers: [`${BASE_URL}`],
|
|
100
|
+
bearer_methods_supported: ['header'] as const,
|
|
101
|
+
scopes_supported: collectScopesFromAPI(API),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return async () => {
|
|
105
|
+
return {
|
|
106
|
+
status: 200,
|
|
107
|
+
body,
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default location(
|
|
113
|
+
autoService(initGetOAuth2WellKnownProtectedResourceMetadata),
|
|
114
|
+
import.meta.url,
|
|
115
|
+
);
|
|
@@ -130,7 +130,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
130
130
|
"headers": {
|
|
131
131
|
"location": "https://www.example.com/?my_custom_parameter=a_custom_value&client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&code=a_valid_code",
|
|
132
132
|
},
|
|
133
|
-
"status":
|
|
133
|
+
"status": 201,
|
|
134
134
|
},
|
|
135
135
|
}
|
|
136
136
|
`);
|
|
@@ -190,7 +190,7 @@ describe('postOAuth2Acknowledge', () => {
|
|
|
190
190
|
"headers": {
|
|
191
191
|
"location": "https://www.example.com/?error=unsupported_response_type&error_description=Type+%22yolo%22+not+supported.",
|
|
192
192
|
},
|
|
193
|
-
"status":
|
|
193
|
+
"status": 201,
|
|
194
194
|
},
|
|
195
195
|
}
|
|
196
196
|
`);
|