@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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { describe, test, beforeEach, jest, expect } from '@jest/globals';
|
|
2
|
+
import { YError } from 'yerror';
|
|
3
|
+
import initPostOAuth2Revoke from './postOAuth2Revoke.js';
|
|
4
|
+
import { type WhookOAuth2RevokeTokenService } from './postOAuth2Revoke.js';
|
|
5
|
+
import { type LogService } from 'common-services';
|
|
6
|
+
|
|
7
|
+
describe('postOAuth2Revoke', () => {
|
|
8
|
+
const oAuth2RevokeToken = {
|
|
9
|
+
revoke: jest.fn<WhookOAuth2RevokeTokenService['revoke']>(),
|
|
10
|
+
};
|
|
11
|
+
const log = jest.fn<LogService>();
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
oAuth2RevokeToken.revoke.mockReset();
|
|
15
|
+
log.mockReset();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('should revoke a token', async () => {
|
|
19
|
+
oAuth2RevokeToken.revoke.mockResolvedValueOnce();
|
|
20
|
+
|
|
21
|
+
const postOAuth2Revoke = await initPostOAuth2Revoke({
|
|
22
|
+
oAuth2RevokeToken,
|
|
23
|
+
log,
|
|
24
|
+
});
|
|
25
|
+
const response = await postOAuth2Revoke({
|
|
26
|
+
body: {
|
|
27
|
+
token: 'a_token',
|
|
28
|
+
token_type_hint: 'refresh_token',
|
|
29
|
+
},
|
|
30
|
+
authenticationData: {
|
|
31
|
+
clientId: 'a_client',
|
|
32
|
+
userId: 'a_user',
|
|
33
|
+
scopes: ['oauth'],
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect({
|
|
38
|
+
response,
|
|
39
|
+
oAuth2RevokeTokenRevokeCalls: oAuth2RevokeToken.revoke.mock.calls,
|
|
40
|
+
logCalls: log.mock.calls,
|
|
41
|
+
}).toMatchInlineSnapshot(`
|
|
42
|
+
{
|
|
43
|
+
"logCalls": [],
|
|
44
|
+
"oAuth2RevokeTokenRevokeCalls": [
|
|
45
|
+
[
|
|
46
|
+
"refresh_token",
|
|
47
|
+
"a_token",
|
|
48
|
+
{
|
|
49
|
+
"clientId": "a_client",
|
|
50
|
+
"scopes": [
|
|
51
|
+
"oauth",
|
|
52
|
+
],
|
|
53
|
+
"userId": "a_user",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
],
|
|
57
|
+
"response": {
|
|
58
|
+
"status": 200,
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
`);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('should revoke a token with no type provided', async () => {
|
|
65
|
+
oAuth2RevokeToken.revoke.mockResolvedValueOnce();
|
|
66
|
+
|
|
67
|
+
const postOAuth2Revoke = await initPostOAuth2Revoke({
|
|
68
|
+
oAuth2RevokeToken,
|
|
69
|
+
log,
|
|
70
|
+
});
|
|
71
|
+
const response = await postOAuth2Revoke({
|
|
72
|
+
body: {
|
|
73
|
+
token: 'a_token',
|
|
74
|
+
},
|
|
75
|
+
authenticationData: {
|
|
76
|
+
clientId: 'a_client',
|
|
77
|
+
userId: 'a_user',
|
|
78
|
+
scopes: ['oauth'],
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect({
|
|
83
|
+
response,
|
|
84
|
+
oAuth2RevokeTokenRevokeCalls: oAuth2RevokeToken.revoke.mock.calls,
|
|
85
|
+
logCalls: log.mock.calls,
|
|
86
|
+
}).toMatchInlineSnapshot(`
|
|
87
|
+
{
|
|
88
|
+
"logCalls": [],
|
|
89
|
+
"oAuth2RevokeTokenRevokeCalls": [
|
|
90
|
+
[
|
|
91
|
+
"access_token",
|
|
92
|
+
"a_token",
|
|
93
|
+
{
|
|
94
|
+
"clientId": "a_client",
|
|
95
|
+
"scopes": [
|
|
96
|
+
"oauth",
|
|
97
|
+
],
|
|
98
|
+
"userId": "a_user",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"refresh_token",
|
|
103
|
+
"a_token",
|
|
104
|
+
{
|
|
105
|
+
"clientId": "a_client",
|
|
106
|
+
"scopes": [
|
|
107
|
+
"oauth",
|
|
108
|
+
],
|
|
109
|
+
"userId": "a_user",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
],
|
|
113
|
+
"response": {
|
|
114
|
+
"status": 200,
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('should ignore already invalid tokens', async () => {
|
|
121
|
+
oAuth2RevokeToken.revoke.mockRejectedValueOnce(new YError('E_BAD_TOKEN'));
|
|
122
|
+
|
|
123
|
+
const postOAuth2Revoke = await initPostOAuth2Revoke({
|
|
124
|
+
oAuth2RevokeToken,
|
|
125
|
+
log,
|
|
126
|
+
});
|
|
127
|
+
const response = await postOAuth2Revoke({
|
|
128
|
+
body: {
|
|
129
|
+
token: 'already_invalid',
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect({
|
|
134
|
+
response,
|
|
135
|
+
oAuth2RevokeTokenRevokeCalls: oAuth2RevokeToken.revoke.mock.calls,
|
|
136
|
+
logCalls: log.mock.calls,
|
|
137
|
+
}).toMatchInlineSnapshot(`
|
|
138
|
+
{
|
|
139
|
+
"logCalls": [],
|
|
140
|
+
"oAuth2RevokeTokenRevokeCalls": [
|
|
141
|
+
[
|
|
142
|
+
"access_token",
|
|
143
|
+
"already_invalid",
|
|
144
|
+
undefined,
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
"refresh_token",
|
|
148
|
+
"already_invalid",
|
|
149
|
+
undefined,
|
|
150
|
+
],
|
|
151
|
+
],
|
|
152
|
+
"response": {
|
|
153
|
+
"status": 200,
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
`);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('should bubble up unexpected errors', async () => {
|
|
160
|
+
oAuth2RevokeToken.revoke.mockRejectedValueOnce(
|
|
161
|
+
new YError('E_OAUTH2_UNEXPECTED_ERROR'),
|
|
162
|
+
);
|
|
163
|
+
const postOAuth2Revoke = await initPostOAuth2Revoke({
|
|
164
|
+
oAuth2RevokeToken,
|
|
165
|
+
log,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
await expect(
|
|
169
|
+
postOAuth2Revoke({
|
|
170
|
+
body: {
|
|
171
|
+
token: 'a_token',
|
|
172
|
+
},
|
|
173
|
+
}),
|
|
174
|
+
).rejects.toMatchObject({
|
|
175
|
+
code: 'E_OAUTH2_UNEXPECTED_ERROR',
|
|
176
|
+
});
|
|
177
|
+
expect(log.mock.calls.length).toBe(2);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { autoService, location } from 'knifecycle';
|
|
2
|
+
import {
|
|
3
|
+
noop,
|
|
4
|
+
refersTo,
|
|
5
|
+
type WhookRouteDefinition,
|
|
6
|
+
type WhookAPISchemaDefinition,
|
|
7
|
+
} from '@whook/whook';
|
|
8
|
+
import { type LogService } from 'common-services';
|
|
9
|
+
import { pickYErrorWithCode, YError, printStackTrace } from 'yerror';
|
|
10
|
+
import { type WhookAuthenticationData } from '@whook/authorization';
|
|
11
|
+
|
|
12
|
+
export const REVOCATION_TOKEN_TYPE_HINT = [
|
|
13
|
+
'access_token',
|
|
14
|
+
'refresh_token',
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export type WhookOAuth2RevocationTokenTypeHint =
|
|
18
|
+
(typeof REVOCATION_TOKEN_TYPE_HINT)[number];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A service to revoke tokens. Must check that the
|
|
22
|
+
* token is owned by the client when authentication
|
|
23
|
+
* data are provided.
|
|
24
|
+
*/
|
|
25
|
+
export interface WhookOAuth2RevokeTokenService {
|
|
26
|
+
revoke: (
|
|
27
|
+
tokenTypeHint: WhookOAuth2RevocationTokenTypeHint,
|
|
28
|
+
token: string,
|
|
29
|
+
optionalAuthenticationData?: WhookAuthenticationData,
|
|
30
|
+
) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const tokenTypeHintSchema = {
|
|
34
|
+
name: 'TokenTypeHint',
|
|
35
|
+
schema: {
|
|
36
|
+
description:
|
|
37
|
+
'OAuth2 revocation token type hint as defined in RFC7009 section 2.1.',
|
|
38
|
+
type: 'string',
|
|
39
|
+
enum: REVOCATION_TOKEN_TYPE_HINT.concat(),
|
|
40
|
+
},
|
|
41
|
+
} as const satisfies WhookAPISchemaDefinition;
|
|
42
|
+
|
|
43
|
+
export const revokeTokenRequestBodySchema = {
|
|
44
|
+
name: 'RevokeTokenRequestBody',
|
|
45
|
+
schema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
description: 'Token revocation request as defined in RFC7009 section 2.1.',
|
|
48
|
+
required: ['token'],
|
|
49
|
+
properties: {
|
|
50
|
+
token: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
},
|
|
53
|
+
token_type_hint: refersTo(tokenTypeHintSchema),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
} as const satisfies WhookAPISchemaDefinition;
|
|
57
|
+
|
|
58
|
+
export const definition = {
|
|
59
|
+
method: 'post',
|
|
60
|
+
path: '/oauth2/revoke',
|
|
61
|
+
config: {
|
|
62
|
+
environments: [],
|
|
63
|
+
},
|
|
64
|
+
operation: {
|
|
65
|
+
operationId: 'postOAuth2Revoke',
|
|
66
|
+
summary: `Implements the [Token Revocation Endpoint](https://datatracker.ietf.org/doc/html/rfc7009#section-2)
|
|
67
|
+
as defined per RFC7009.`,
|
|
68
|
+
tags: ['oauth2'],
|
|
69
|
+
parameters: [],
|
|
70
|
+
requestBody: {
|
|
71
|
+
required: true,
|
|
72
|
+
content: {
|
|
73
|
+
'application/x-www-form-urlencoded': {
|
|
74
|
+
schema: refersTo(revokeTokenRequestBodySchema),
|
|
75
|
+
},
|
|
76
|
+
'application/json': {
|
|
77
|
+
schema: refersTo(revokeTokenRequestBodySchema),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
responses: {
|
|
82
|
+
'200': {
|
|
83
|
+
description:
|
|
84
|
+
'Token successfully revoked or unknown token (RFC7009 section 2.2).',
|
|
85
|
+
},
|
|
86
|
+
'400': {
|
|
87
|
+
description: 'Token revocation error response.',
|
|
88
|
+
content: {
|
|
89
|
+
'application/json': {
|
|
90
|
+
schema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
required: ['error'],
|
|
93
|
+
properties: {
|
|
94
|
+
error: {
|
|
95
|
+
type: 'string',
|
|
96
|
+
enum: ['invalid_request', 'unsupported_token_type'],
|
|
97
|
+
},
|
|
98
|
+
error_description: { type: 'string' },
|
|
99
|
+
error_uri: { type: 'string' },
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
} as const satisfies WhookRouteDefinition;
|
|
108
|
+
|
|
109
|
+
async function initPostOAuth2Revoke({
|
|
110
|
+
oAuth2RevokeToken,
|
|
111
|
+
log = noop,
|
|
112
|
+
}: {
|
|
113
|
+
oAuth2RevokeToken: WhookOAuth2RevokeTokenService;
|
|
114
|
+
log?: LogService;
|
|
115
|
+
}) {
|
|
116
|
+
return async ({
|
|
117
|
+
body: { token, token_type_hint: tokenTypeHint },
|
|
118
|
+
authenticationData: optionalAuthenticationData,
|
|
119
|
+
}: {
|
|
120
|
+
body: {
|
|
121
|
+
token: string;
|
|
122
|
+
token_type_hint?: WhookOAuth2RevocationTokenTypeHint;
|
|
123
|
+
};
|
|
124
|
+
authenticationData?: WhookAuthenticationData;
|
|
125
|
+
}) => {
|
|
126
|
+
for (const currentTokenTypeHint of tokenTypeHint
|
|
127
|
+
? [tokenTypeHint]
|
|
128
|
+
: REVOCATION_TOKEN_TYPE_HINT) {
|
|
129
|
+
try {
|
|
130
|
+
await oAuth2RevokeToken.revoke(
|
|
131
|
+
currentTokenTypeHint,
|
|
132
|
+
token,
|
|
133
|
+
optionalAuthenticationData,
|
|
134
|
+
);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
const castedErr = pickYErrorWithCode(err as Error, 'E_BAD_TOKEN');
|
|
137
|
+
|
|
138
|
+
if (!castedErr) {
|
|
139
|
+
log(
|
|
140
|
+
'debug',
|
|
141
|
+
'👫 - OAuth2 token revocation error',
|
|
142
|
+
(err as YError).code,
|
|
143
|
+
);
|
|
144
|
+
log('debug-stack', printStackTrace(err));
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
status: 200,
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default location(autoService(initPostOAuth2Revoke), import.meta.url);
|