@whook/oauth2 25.2.1 → 26.0.2
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 +34 -11
- package/dist/index.js +18 -8
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +1671 -393
- package/dist/index.test.js.map +1 -1
- package/dist/libs/authorizationRequests.d.ts +6 -0
- package/dist/libs/authorizationRequests.js +22 -0
- package/dist/libs/authorizationRequests.js.map +1 -0
- package/dist/libs/authorizationRequests.test.js +24 -0
- package/dist/libs/authorizationRequests.test.js.map +1 -0
- 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 +143 -0
- package/dist/libs/errors.js +227 -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 +8 -0
- package/dist/libs/redirectURI.js +94 -0
- package/dist/libs/redirectURI.js.map +1 -0
- package/dist/libs/schemas.d.ts +31 -0
- package/dist/libs/schemas.js +33 -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 +10 -0
- package/dist/libs/verifier.js +51 -0
- package/dist/libs/verifier.js.map +1 -0
- package/dist/libs/verifier.test.d.ts +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 +38 -59
- package/dist/routes/getOAuth2Authorize.js +129 -93
- package/dist/routes/getOAuth2Authorize.js.map +1 -1
- package/dist/routes/getOAuth2Authorize.test.js +959 -73
- package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.d.ts +18 -11
- package/dist/routes/getOAuth2WellKnownMetadata.js +43 -11
- package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
- package/dist/routes/getOAuth2WellKnownMetadata.test.js +51 -49
- 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/postOAuth2PushedAuthorizationRequest.d.ts +137 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js +187 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.d.ts +1 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +554 -0
- package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -0
- 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 +47 -108
- package/dist/routes/postOAuth2Token.js +65 -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 +9 -5
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +124 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js +204 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js +345 -0
- package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2AuthorizationRequests.d.ts +41 -0
- package/dist/services/oAuth2AuthorizationRequests.js +61 -0
- package/dist/services/oAuth2AuthorizationRequests.js.map +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.d.ts +1 -0
- package/dist/services/oAuth2AuthorizationRequests.test.js +249 -0
- package/dist/services/oAuth2AuthorizationRequests.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 +79 -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 +61 -0
- package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
- package/dist/services/oAuth2ImplicitGranter.test.js +589 -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 +14 -13
- package/src/index.test.ts +1773 -407
- package/src/index.ts +63 -53
- package/src/libs/authorizationRequests.test.ts +40 -0
- package/src/libs/authorizationRequests.ts +42 -0
- package/src/libs/clients.ts +22 -0
- package/src/libs/errors.ts +411 -0
- package/src/libs/grants.ts +15 -0
- package/src/libs/redirectURI.ts +142 -0
- package/src/libs/schemas.ts +37 -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 +75 -0
- package/src/routes/getOAuth2Authorize.test.ts +1102 -102
- package/src/routes/getOAuth2Authorize.ts +243 -151
- package/src/routes/getOAuth2WellKnownMetadata.test.ts +73 -74
- package/src/routes/getOAuth2WellKnownMetadata.ts +63 -16
- 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/postOAuth2PushedAuthorizationRequest.test.ts +681 -0
- package/src/routes/postOAuth2PushedAuthorizationRequest.ts +292 -0
- 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 +104 -136
- package/src/services/authCookies.test.ts +5 -5
- package/src/services/authCookies.ts +24 -22
- package/src/services/oAuth2AuthorizationCodeGranter.test.ts +407 -0
- package/src/services/oAuth2AuthorizationCodeGranter.ts +365 -0
- package/src/services/oAuth2AuthorizationRequests.test.ts +282 -0
- package/src/services/oAuth2AuthorizationRequests.ts +141 -0
- package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
- package/src/services/oAuth2Granters.ts +100 -196
- package/src/services/oAuth2ImplicitGranter.test.ts +650 -0
- package/src/services/oAuth2ImplicitGranter.ts +147 -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/authorizationRequests.test.d.ts} +0 -0
package/src/index.ts
CHANGED
|
@@ -5,10 +5,13 @@ import initGetOAuth2Authorize, {
|
|
|
5
5
|
redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,
|
|
6
6
|
scopeParameter as getOAuth2AuthorizeScopeParameter,
|
|
7
7
|
stateParameter as getOAuth2AuthorizeStateParameter,
|
|
8
|
+
requestURIParameter as getOAuth2AuthorizeRequestURIParameter,
|
|
8
9
|
codeChallengeSchema as getOAuth2AuthorizeCodeChallengeSchema,
|
|
9
10
|
codeChallengeParameter as getOAuth2AuthorizeCodeChallengeParameter,
|
|
10
11
|
codeChallengeMethodSchema as getOAuth2AuthorizeCodeChallengeMethodSchema,
|
|
11
12
|
codeChallengeMethodParameter as getOAuth2AuthorizeCodeChallengeMethodParameter,
|
|
13
|
+
requestURISchema as getOAuth2AuthorizeRequestURISchema,
|
|
14
|
+
scopeSchema as getOAuth2AuthorizeScopeSchema,
|
|
12
15
|
} from './routes/getOAuth2Authorize.js';
|
|
13
16
|
import initPostOAuth2Acknowledge, {
|
|
14
17
|
definition as postOAuth2AcknowledgeDefinition,
|
|
@@ -22,6 +25,11 @@ import initPostOAuth2Token, {
|
|
|
22
25
|
refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
23
26
|
tokenBodySchema as postOAuth2TokenTokenBodySchema,
|
|
24
27
|
} from './routes/postOAuth2Token.js';
|
|
28
|
+
import initPostOAuth2PushedAuthorizationRequest, {
|
|
29
|
+
definition as postOAuth2PushedAuthorizationRequestDefinition,
|
|
30
|
+
pushedAuthorizationRequestBodySchema as postOAuth2PushedAuthorizationRequestBodySchema,
|
|
31
|
+
requestURISchema as postOAuth2PushedAuthorizationRequestRequestURISchema,
|
|
32
|
+
} from './routes/postOAuth2PushedAuthorizationRequest.js';
|
|
25
33
|
import initGetOAuth2WellKnown, {
|
|
26
34
|
definition as getOAuth2WellKnownDefinition,
|
|
27
35
|
endpointAuthenticationMethodsSchema as getOAuth2WellKnownEndpointAuthenticationMethodsSchema,
|
|
@@ -29,29 +37,34 @@ import initGetOAuth2WellKnown, {
|
|
|
29
37
|
jsonWebEncryptionsSchema as getOAuth2WellKnownJsonWebEncryptionsSchema,
|
|
30
38
|
httpsProtocolURISchema as getOAuth2WellKnownHTTPSProtocolURISchema,
|
|
31
39
|
oAuth2MetadataSchema as getOAuth2WellKnownOAuth2MetadataSchema,
|
|
40
|
+
scopeTokenSchema as getOAuth2WellKnownScopeTokenSchema,
|
|
41
|
+
scopeTokensSchema as getOAuth2WellKnownScopeTokensSchema,
|
|
32
42
|
} from './routes/getOAuth2WellKnownMetadata.js';
|
|
33
43
|
import initGetOAuth2WellKnownProtectedResource, {
|
|
34
44
|
definition as getOAuth2WellKnownProtectedResourceDefinition,
|
|
35
45
|
bearerMethodSchema as getOAuth2WellKnownProtectedResourceBearerMethodSchema,
|
|
36
46
|
oAuth2ProtectedResourceMetadataSchema as getOAuth2WellKnownProtectedResourceSchema,
|
|
37
47
|
} from './routes/getOAuth2WellKnownProtectedResourceMetadata.js';
|
|
38
|
-
import
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
import initPostOAuth2Revoke, {
|
|
49
|
+
definition as postOAuth2RevokeDefinition,
|
|
50
|
+
tokenTypeHintSchema as postOAuth2RevokeTokenTypeHintSchema,
|
|
51
|
+
revokeTokenRequestBodySchema as postOAuth2RevokeTokenRequestBodySchema,
|
|
52
|
+
} from './routes/postOAuth2Revoke.js';
|
|
53
|
+
export type * from './routes/postOAuth2Revoke.js';
|
|
54
|
+
|
|
55
|
+
import initOAuth2Granters from './services/oAuth2Granters.js';
|
|
56
|
+
export type * from './services/oAuth2Granters.js';
|
|
42
57
|
import initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter.js';
|
|
58
|
+
export type * from './services/oAuth2ClientCredentialsGranter.js';
|
|
43
59
|
import initOAuth2PasswordGranter from './services/oAuth2PasswordGranter.js';
|
|
60
|
+
export type * from './services/oAuth2PasswordGranter.js';
|
|
44
61
|
import initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter.js';
|
|
45
|
-
|
|
46
|
-
import
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
type OAuth2GranterService,
|
|
52
|
-
type OAuth2Options,
|
|
53
|
-
type OAuth2Config,
|
|
54
|
-
} from './services/oAuth2Granters.js';
|
|
62
|
+
export type * from './services/oAuth2RefreshTokenGranter.js';
|
|
63
|
+
import initOAuth2ImplicitGranter from './services/oAuth2ImplicitGranter.js';
|
|
64
|
+
export type * from './services/oAuth2ImplicitGranter.js';
|
|
65
|
+
import initOAuth2AuthorizationCodeGranter from './services/oAuth2AuthorizationCodeGranter.js';
|
|
66
|
+
export type * from './services/oAuth2AuthorizationCodeGranter.js';
|
|
67
|
+
|
|
55
68
|
import initPostAuthLogin, {
|
|
56
69
|
definition as postAuthLoginDefinition,
|
|
57
70
|
} from './routes/postAuthLogin.js';
|
|
@@ -62,22 +75,26 @@ import initPostAuthRefresh, {
|
|
|
62
75
|
authCookieHeaderParameter,
|
|
63
76
|
definition as postAuthRefreshDefinition,
|
|
64
77
|
} from './routes/postAuthRefresh.js';
|
|
65
|
-
import initAuthCookiesService
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
import initAuthCookiesService from './services/authCookies.js';
|
|
79
|
+
import { type OAuth2YErrorRegistry } from './libs/errors.js';
|
|
80
|
+
export * from './services/authCookies.js';
|
|
81
|
+
export type * from './services/authCookies.js';
|
|
82
|
+
import initOAuth2AuthorizationRequests from './services/oAuth2AuthorizationRequests.js';
|
|
83
|
+
export * from './services/oAuth2AuthorizationRequests.js';
|
|
84
|
+
export type * from './services/oAuth2AuthorizationRequests.js';
|
|
85
|
+
|
|
86
|
+
export * from './libs/schemas.js';
|
|
87
|
+
export type * from './libs/schemas.js';
|
|
88
|
+
export * from './libs/errors.js';
|
|
89
|
+
export type * from './libs/errors.js';
|
|
90
|
+
export * from './libs/scopes.js';
|
|
91
|
+
export type * from './libs/scopes.js';
|
|
92
|
+
export * from './libs/grants.js';
|
|
93
|
+
export type * from './libs/grants.js';
|
|
94
|
+
export * from './libs/redirectURI.js';
|
|
95
|
+
export type * from './libs/redirectURI.js';
|
|
96
|
+
export * from './libs/verifier.js';
|
|
97
|
+
export type * from './libs/verifier.js';
|
|
81
98
|
|
|
82
99
|
declare module 'yerror' {
|
|
83
100
|
interface YErrorRegistry extends OAuth2YErrorRegistry {
|
|
@@ -85,22 +102,6 @@ declare module 'yerror' {
|
|
|
85
102
|
}
|
|
86
103
|
}
|
|
87
104
|
|
|
88
|
-
export type {
|
|
89
|
-
OAuth2YErrorRegistry,
|
|
90
|
-
CodeChallengeMethod,
|
|
91
|
-
OAuth2CodeService,
|
|
92
|
-
OAuth2PasswordService,
|
|
93
|
-
OAuth2AccessTokenService,
|
|
94
|
-
OAuth2RefreshTokenService,
|
|
95
|
-
CheckApplicationService,
|
|
96
|
-
OAuth2GranterService,
|
|
97
|
-
OAuth2Options,
|
|
98
|
-
OAuth2Config,
|
|
99
|
-
AuthCookiesConfig,
|
|
100
|
-
AuthCookiesService,
|
|
101
|
-
AuthCookiesData,
|
|
102
|
-
AuthHandlersConfig,
|
|
103
|
-
};
|
|
104
105
|
export {
|
|
105
106
|
initGetOAuth2Authorize,
|
|
106
107
|
getOAuth2AuthorizeDefinition,
|
|
@@ -109,10 +110,13 @@ export {
|
|
|
109
110
|
getOAuth2AuthorizeRedirectURIParameter,
|
|
110
111
|
getOAuth2AuthorizeScopeParameter,
|
|
111
112
|
getOAuth2AuthorizeStateParameter,
|
|
113
|
+
getOAuth2AuthorizeRequestURIParameter,
|
|
114
|
+
getOAuth2AuthorizeScopeSchema,
|
|
112
115
|
getOAuth2AuthorizeCodeChallengeSchema,
|
|
113
116
|
getOAuth2AuthorizeCodeChallengeMethodSchema,
|
|
114
117
|
getOAuth2AuthorizeCodeChallengeParameter,
|
|
115
118
|
getOAuth2AuthorizeCodeChallengeMethodParameter,
|
|
119
|
+
getOAuth2AuthorizeRequestURISchema,
|
|
116
120
|
initGetOAuth2WellKnown,
|
|
117
121
|
getOAuth2WellKnownDefinition,
|
|
118
122
|
getOAuth2WellKnownEndpointAuthenticationMethodsSchema,
|
|
@@ -120,12 +124,16 @@ export {
|
|
|
120
124
|
getOAuth2WellKnownJsonWebEncryptionsSchema,
|
|
121
125
|
getOAuth2WellKnownHTTPSProtocolURISchema,
|
|
122
126
|
getOAuth2WellKnownOAuth2MetadataSchema,
|
|
127
|
+
getOAuth2WellKnownScopeTokenSchema,
|
|
128
|
+
getOAuth2WellKnownScopeTokensSchema,
|
|
123
129
|
initGetOAuth2WellKnownProtectedResource,
|
|
124
130
|
getOAuth2WellKnownProtectedResourceDefinition,
|
|
125
131
|
getOAuth2WellKnownProtectedResourceBearerMethodSchema,
|
|
126
132
|
getOAuth2WellKnownProtectedResourceSchema,
|
|
127
|
-
|
|
128
|
-
|
|
133
|
+
initPostOAuth2Revoke,
|
|
134
|
+
postOAuth2RevokeDefinition,
|
|
135
|
+
postOAuth2RevokeTokenTypeHintSchema,
|
|
136
|
+
postOAuth2RevokeTokenRequestBodySchema,
|
|
129
137
|
initPostOAuth2Acknowledge,
|
|
130
138
|
postOAuth2AcknowledgeDefinition,
|
|
131
139
|
initPostOAuth2Token,
|
|
@@ -136,14 +144,16 @@ export {
|
|
|
136
144
|
postOAuth2TokenClientCredentialsTokenRequestBodySchema,
|
|
137
145
|
postOAuth2TokenRefreshTokenRequestBodySchema,
|
|
138
146
|
postOAuth2TokenTokenBodySchema,
|
|
139
|
-
|
|
147
|
+
initPostOAuth2PushedAuthorizationRequest,
|
|
148
|
+
postOAuth2PushedAuthorizationRequestDefinition,
|
|
149
|
+
postOAuth2PushedAuthorizationRequestBodySchema,
|
|
150
|
+
postOAuth2PushedAuthorizationRequestRequestURISchema,
|
|
140
151
|
initOAuth2Granters,
|
|
141
152
|
initOAuth2ClientCredentialsGranter,
|
|
142
|
-
|
|
153
|
+
initOAuth2AuthorizationCodeGranter,
|
|
143
154
|
initOAuth2PasswordGranter,
|
|
144
155
|
initOAuth2RefreshTokenGranter,
|
|
145
|
-
|
|
146
|
-
AUTH_API_PREFIX,
|
|
156
|
+
initOAuth2ImplicitGranter,
|
|
147
157
|
authCookieHeaderParameter,
|
|
148
158
|
initPostAuthLogin,
|
|
149
159
|
postAuthLoginDefinition,
|
|
@@ -152,5 +162,5 @@ export {
|
|
|
152
162
|
initPostAuthRefresh,
|
|
153
163
|
postAuthRefreshDefinition,
|
|
154
164
|
initAuthCookiesService,
|
|
155
|
-
|
|
165
|
+
initOAuth2AuthorizationRequests,
|
|
156
166
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, test, expect } from '@jest/globals';
|
|
2
|
+
import {
|
|
3
|
+
buildRequestURI,
|
|
4
|
+
isRequestURI,
|
|
5
|
+
readRequestURI,
|
|
6
|
+
} from './authorizationRequests.js';
|
|
7
|
+
|
|
8
|
+
describe('buildRequestURI', () => {
|
|
9
|
+
test('should build URIs', () => {
|
|
10
|
+
expect(buildRequestURI('a_id')).toMatchInlineSnapshot(
|
|
11
|
+
`"urn:ietf:params:oauth:request_uri:a_id"`,
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('isRequestURI', () => {
|
|
17
|
+
test('should cast URIs', () => {
|
|
18
|
+
expect(
|
|
19
|
+
isRequestURI('urn:ietf:params:oauth:request_uri:a_id'),
|
|
20
|
+
).toMatchInlineSnapshot(`true`);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('should fail with bad URIs', () => {
|
|
24
|
+
expect(() => isRequestURI('a_id')).toThrow('E_OAUTH2_BAD_REQUEST_URI');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('should fail with empty id', () => {
|
|
28
|
+
expect(() => isRequestURI('urn:ietf:params:oauth:request_uri:')).toThrow(
|
|
29
|
+
'E_OAUTH2_BAD_REQUEST_URI',
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('read', () => {
|
|
35
|
+
test('should read URIs', () => {
|
|
36
|
+
expect(
|
|
37
|
+
readRequestURI('urn:ietf:params:oauth:request_uri:a_id'),
|
|
38
|
+
).toMatchInlineSnapshot(`"a_id"`);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { YError } from 'yerror';
|
|
2
|
+
|
|
3
|
+
export const PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX =
|
|
4
|
+
'urn:ietf:params:oauth:request_uri:';
|
|
5
|
+
|
|
6
|
+
export type WhookOAuth2AuthorizationRequestURI =
|
|
7
|
+
`${typeof PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX}${string}`;
|
|
8
|
+
export type WhookOAuth2AuthorizationRequestId = string;
|
|
9
|
+
|
|
10
|
+
export function buildRequestURI(
|
|
11
|
+
requestId: WhookOAuth2AuthorizationRequestId,
|
|
12
|
+
): WhookOAuth2AuthorizationRequestURI {
|
|
13
|
+
return `${PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX}${requestId}`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isRequestURI(
|
|
17
|
+
requestURI: string | undefined,
|
|
18
|
+
): requestURI is WhookOAuth2AuthorizationRequestURI {
|
|
19
|
+
if (
|
|
20
|
+
!requestURI ||
|
|
21
|
+
!requestURI.startsWith(PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX) ||
|
|
22
|
+
requestURI === PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX
|
|
23
|
+
) {
|
|
24
|
+
throw new YError('E_OAUTH2_BAD_REQUEST_URI', [
|
|
25
|
+
requestURI,
|
|
26
|
+
undefined,
|
|
27
|
+
undefined,
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readRequestURI(
|
|
35
|
+
requestURI: WhookOAuth2AuthorizationRequestURI,
|
|
36
|
+
): WhookOAuth2AuthorizationRequestId {
|
|
37
|
+
const requestId = requestURI.slice(
|
|
38
|
+
PUSHED_AUTHORIZATION_REQUEST_URI_PREFIX.length,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return requestId;
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { identity } from '@whook/whook';
|
|
2
|
+
import { type WhookOAuth2ClientId } from '../services/oAuth2Granters.js';
|
|
3
|
+
import { YError } from 'yerror';
|
|
4
|
+
|
|
5
|
+
export function toUsableClientId(
|
|
6
|
+
clientsIds: (WhookOAuth2ClientId | undefined)[],
|
|
7
|
+
): WhookOAuth2ClientId {
|
|
8
|
+
const usableClientId = clientsIds.find(identity);
|
|
9
|
+
|
|
10
|
+
if (!usableClientId) {
|
|
11
|
+
throw new YError('E_OAUTH2_EMPTY_CLIENT', []);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (clientsIds.some((clientId) => clientId && clientId !== usableClientId)) {
|
|
15
|
+
throw new YError(
|
|
16
|
+
'E_OAUTH2_CLIENT_MISMATCH',
|
|
17
|
+
clientsIds.filter((clientId) => typeof clientId !== 'undefined'),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return usableClientId;
|
|
22
|
+
}
|