@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.
Files changed (197) hide show
  1. package/README.md +147 -98
  2. package/dist/index.d.ts +34 -11
  3. package/dist/index.js +18 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.test.js +1671 -393
  6. package/dist/index.test.js.map +1 -1
  7. package/dist/libs/authorizationRequests.d.ts +6 -0
  8. package/dist/libs/authorizationRequests.js +22 -0
  9. package/dist/libs/authorizationRequests.js.map +1 -0
  10. package/dist/libs/authorizationRequests.test.js +24 -0
  11. package/dist/libs/authorizationRequests.test.js.map +1 -0
  12. package/dist/libs/clients.d.ts +2 -0
  13. package/dist/libs/clients.js +13 -0
  14. package/dist/libs/clients.js.map +1 -0
  15. package/dist/libs/errors.d.ts +143 -0
  16. package/dist/libs/errors.js +227 -0
  17. package/dist/libs/errors.js.map +1 -0
  18. package/dist/libs/grants.d.ts +2 -0
  19. package/dist/libs/grants.js +10 -0
  20. package/dist/libs/grants.js.map +1 -0
  21. package/dist/libs/redirectURI.d.ts +8 -0
  22. package/dist/libs/redirectURI.js +94 -0
  23. package/dist/libs/redirectURI.js.map +1 -0
  24. package/dist/libs/schemas.d.ts +31 -0
  25. package/dist/libs/schemas.js +33 -0
  26. package/dist/libs/schemas.js.map +1 -0
  27. package/dist/libs/scopes.d.ts +16 -0
  28. package/dist/libs/scopes.js +37 -0
  29. package/dist/libs/scopes.js.map +1 -1
  30. package/dist/libs/utils.d.ts +2 -0
  31. package/dist/libs/utils.js +17 -0
  32. package/dist/libs/utils.js.map +1 -0
  33. package/dist/libs/verifier.d.ts +10 -0
  34. package/dist/libs/verifier.js +51 -0
  35. package/dist/libs/verifier.js.map +1 -0
  36. package/dist/libs/verifier.test.d.ts +1 -0
  37. package/dist/libs/verifier.test.js +21 -0
  38. package/dist/libs/verifier.test.js.map +1 -0
  39. package/dist/routes/getOAuth2Authorize.d.ts +38 -59
  40. package/dist/routes/getOAuth2Authorize.js +129 -93
  41. package/dist/routes/getOAuth2Authorize.js.map +1 -1
  42. package/dist/routes/getOAuth2Authorize.test.js +959 -73
  43. package/dist/routes/getOAuth2Authorize.test.js.map +1 -1
  44. package/dist/routes/getOAuth2WellKnownMetadata.d.ts +18 -11
  45. package/dist/routes/getOAuth2WellKnownMetadata.js +43 -11
  46. package/dist/routes/getOAuth2WellKnownMetadata.js.map +1 -1
  47. package/dist/routes/getOAuth2WellKnownMetadata.test.js +51 -49
  48. package/dist/routes/getOAuth2WellKnownMetadata.test.js.map +1 -1
  49. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.d.ts +3 -6
  50. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js +3 -6
  51. package/dist/routes/getOAuth2WellKnownProtectedResourceMetadata.js.map +1 -1
  52. package/dist/routes/postAuthLogin.d.ts +14 -9
  53. package/dist/routes/postAuthLogin.js +10 -5
  54. package/dist/routes/postAuthLogin.js.map +1 -1
  55. package/dist/routes/postAuthLogin.test.js +79 -55
  56. package/dist/routes/postAuthLogin.test.js.map +1 -1
  57. package/dist/routes/postAuthLogout.d.ts +5 -2
  58. package/dist/routes/postAuthLogout.js +12 -7
  59. package/dist/routes/postAuthLogout.js.map +1 -1
  60. package/dist/routes/postAuthLogout.test.js +35 -17
  61. package/dist/routes/postAuthLogout.test.js.map +1 -1
  62. package/dist/routes/postAuthRefresh.d.ts +14 -9
  63. package/dist/routes/postAuthRefresh.js +10 -6
  64. package/dist/routes/postAuthRefresh.js.map +1 -1
  65. package/dist/routes/postAuthRefresh.test.js +90 -59
  66. package/dist/routes/postAuthRefresh.test.js.map +1 -1
  67. package/dist/routes/postOAuth2Acknowledge.d.ts +11 -10
  68. package/dist/routes/postOAuth2Acknowledge.js +43 -37
  69. package/dist/routes/postOAuth2Acknowledge.js.map +1 -1
  70. package/dist/routes/postOAuth2Acknowledge.test.js +135 -70
  71. package/dist/routes/postOAuth2Acknowledge.test.js.map +1 -1
  72. package/dist/routes/postOAuth2PushedAuthorizationRequest.d.ts +137 -0
  73. package/dist/routes/postOAuth2PushedAuthorizationRequest.js +187 -0
  74. package/dist/routes/postOAuth2PushedAuthorizationRequest.js.map +1 -0
  75. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.d.ts +1 -0
  76. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js +554 -0
  77. package/dist/routes/postOAuth2PushedAuthorizationRequest.test.js.map +1 -0
  78. package/dist/routes/postOAuth2Revoke.d.ts +99 -0
  79. package/dist/routes/postOAuth2Revoke.js +102 -0
  80. package/dist/routes/postOAuth2Revoke.js.map +1 -0
  81. package/dist/routes/postOAuth2Revoke.test.d.ts +1 -0
  82. package/dist/routes/postOAuth2Revoke.test.js +161 -0
  83. package/dist/routes/postOAuth2Revoke.test.js.map +1 -0
  84. package/dist/routes/postOAuth2Token.d.ts +47 -108
  85. package/dist/routes/postOAuth2Token.js +65 -114
  86. package/dist/routes/postOAuth2Token.js.map +1 -1
  87. package/dist/routes/postOAuth2Token.test.js +493 -61
  88. package/dist/routes/postOAuth2Token.test.js.map +1 -1
  89. package/dist/services/authCookies.d.ts +9 -13
  90. package/dist/services/authCookies.js +9 -5
  91. package/dist/services/authCookies.js.map +1 -1
  92. package/dist/services/authCookies.test.js.map +1 -1
  93. package/dist/services/oAuth2AuthorizationCodeGranter.d.ts +124 -0
  94. package/dist/services/oAuth2AuthorizationCodeGranter.js +204 -0
  95. package/dist/services/oAuth2AuthorizationCodeGranter.js.map +1 -0
  96. package/dist/services/oAuth2AuthorizationCodeGranter.test.d.ts +1 -0
  97. package/dist/services/oAuth2AuthorizationCodeGranter.test.js +345 -0
  98. package/dist/services/oAuth2AuthorizationCodeGranter.test.js.map +1 -0
  99. package/dist/services/oAuth2AuthorizationRequests.d.ts +41 -0
  100. package/dist/services/oAuth2AuthorizationRequests.js +61 -0
  101. package/dist/services/oAuth2AuthorizationRequests.js.map +1 -0
  102. package/dist/services/oAuth2AuthorizationRequests.test.d.ts +1 -0
  103. package/dist/services/oAuth2AuthorizationRequests.test.js +249 -0
  104. package/dist/services/oAuth2AuthorizationRequests.test.js.map +1 -0
  105. package/dist/services/oAuth2ClientCredentialsGranter.d.ts +28 -12
  106. package/dist/services/oAuth2ClientCredentialsGranter.js +39 -21
  107. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  108. package/dist/services/oAuth2ClientCredentialsGranter.test.d.ts +1 -0
  109. package/dist/services/oAuth2ClientCredentialsGranter.test.js +265 -0
  110. package/dist/services/oAuth2ClientCredentialsGranter.test.js.map +1 -0
  111. package/dist/services/oAuth2Granters.d.ts +79 -86
  112. package/dist/services/oAuth2Granters.js +2 -67
  113. package/dist/services/oAuth2Granters.js.map +1 -1
  114. package/dist/services/oAuth2ImplicitGranter.d.ts +38 -0
  115. package/dist/services/oAuth2ImplicitGranter.js +61 -0
  116. package/dist/services/oAuth2ImplicitGranter.js.map +1 -0
  117. package/dist/services/oAuth2ImplicitGranter.test.d.ts +1 -0
  118. package/dist/services/oAuth2ImplicitGranter.test.js +589 -0
  119. package/dist/services/oAuth2ImplicitGranter.test.js.map +1 -0
  120. package/dist/services/oAuth2PasswordGranter.d.ts +43 -10
  121. package/dist/services/oAuth2PasswordGranter.js +53 -18
  122. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  123. package/dist/services/oAuth2PasswordGranter.test.d.ts +1 -0
  124. package/dist/services/oAuth2PasswordGranter.test.js +455 -0
  125. package/dist/services/oAuth2PasswordGranter.test.js.map +1 -0
  126. package/dist/services/oAuth2RefreshTokenGranter.d.ts +42 -9
  127. package/dist/services/oAuth2RefreshTokenGranter.js +60 -21
  128. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  129. package/dist/services/oAuth2RefreshTokenGranter.test.d.ts +1 -0
  130. package/dist/services/oAuth2RefreshTokenGranter.test.js +403 -0
  131. package/dist/services/oAuth2RefreshTokenGranter.test.js.map +1 -0
  132. package/package.json +14 -13
  133. package/src/index.test.ts +1773 -407
  134. package/src/index.ts +63 -53
  135. package/src/libs/authorizationRequests.test.ts +40 -0
  136. package/src/libs/authorizationRequests.ts +42 -0
  137. package/src/libs/clients.ts +22 -0
  138. package/src/libs/errors.ts +411 -0
  139. package/src/libs/grants.ts +15 -0
  140. package/src/libs/redirectURI.ts +142 -0
  141. package/src/libs/schemas.ts +37 -0
  142. package/src/libs/scopes.ts +49 -0
  143. package/src/libs/utils.ts +24 -0
  144. package/src/libs/verifier.test.ts +37 -0
  145. package/src/libs/verifier.ts +75 -0
  146. package/src/routes/getOAuth2Authorize.test.ts +1102 -102
  147. package/src/routes/getOAuth2Authorize.ts +243 -151
  148. package/src/routes/getOAuth2WellKnownMetadata.test.ts +73 -74
  149. package/src/routes/getOAuth2WellKnownMetadata.ts +63 -16
  150. package/src/routes/getOAuth2WellKnownProtectedResourceMetadata.ts +4 -6
  151. package/src/routes/postAuthLogin.test.ts +86 -57
  152. package/src/routes/postAuthLogin.ts +24 -14
  153. package/src/routes/postAuthLogout.test.ts +42 -18
  154. package/src/routes/postAuthLogout.ts +22 -8
  155. package/src/routes/postAuthRefresh.test.ts +98 -61
  156. package/src/routes/postAuthRefresh.ts +25 -13
  157. package/src/routes/postOAuth2Acknowledge.test.ts +167 -108
  158. package/src/routes/postOAuth2Acknowledge.ts +90 -64
  159. package/src/routes/postOAuth2PushedAuthorizationRequest.test.ts +681 -0
  160. package/src/routes/postOAuth2PushedAuthorizationRequest.ts +292 -0
  161. package/src/routes/postOAuth2Revoke.test.ts +179 -0
  162. package/src/routes/postOAuth2Revoke.ts +156 -0
  163. package/src/routes/postOAuth2Token.test.ts +570 -108
  164. package/src/routes/postOAuth2Token.ts +104 -136
  165. package/src/services/authCookies.test.ts +5 -5
  166. package/src/services/authCookies.ts +24 -22
  167. package/src/services/oAuth2AuthorizationCodeGranter.test.ts +407 -0
  168. package/src/services/oAuth2AuthorizationCodeGranter.ts +365 -0
  169. package/src/services/oAuth2AuthorizationRequests.test.ts +282 -0
  170. package/src/services/oAuth2AuthorizationRequests.ts +141 -0
  171. package/src/services/oAuth2ClientCredentialsGranter.test.ts +303 -0
  172. package/src/services/oAuth2ClientCredentialsGranter.ts +68 -43
  173. package/src/services/oAuth2Granters.ts +100 -196
  174. package/src/services/oAuth2ImplicitGranter.test.ts +650 -0
  175. package/src/services/oAuth2ImplicitGranter.ts +147 -0
  176. package/src/services/oAuth2PasswordGranter.test.ts +493 -0
  177. package/src/services/oAuth2PasswordGranter.ts +116 -40
  178. package/src/services/oAuth2RefreshTokenGranter.test.ts +441 -0
  179. package/src/services/oAuth2RefreshTokenGranter.ts +118 -51
  180. package/src/types.d.ts +1 -0
  181. package/dist/services/oAuth2CodeGranter.d.ts +0 -41
  182. package/dist/services/oAuth2CodeGranter.js +0 -105
  183. package/dist/services/oAuth2CodeGranter.js.map +0 -1
  184. package/dist/services/oAuth2CodeGranter.test.js +0 -123
  185. package/dist/services/oAuth2CodeGranter.test.js.map +0 -1
  186. package/dist/services/oAuth2TokenGranter.d.ts +0 -22
  187. package/dist/services/oAuth2TokenGranter.js +0 -64
  188. package/dist/services/oAuth2TokenGranter.js.map +0 -1
  189. package/src/__snapshots__/index.test.ts.snap +0 -401
  190. package/src/routes/__snapshots__/getOAuth2Authorize.test.ts.snap +0 -37
  191. package/src/routes/__snapshots__/postOAuth2Acknowledge.test.ts.snap +0 -61
  192. package/src/routes/__snapshots__/postOAuth2Token.test.ts.snap +0 -52
  193. package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +0 -52
  194. package/src/services/oAuth2CodeGranter.test.ts +0 -176
  195. package/src/services/oAuth2CodeGranter.ts +0 -210
  196. package/src/services/oAuth2TokenGranter.ts +0 -119
  197. /package/dist/{services/oAuth2CodeGranter.test.d.ts → libs/authorizationRequests.test.d.ts} +0 -0
@@ -1,225 +1,129 @@
1
1
  import { type Dependencies, initializer, location } from 'knifecycle';
2
+ import { type WhookErrorsDescriptors } from '@whook/whook';
2
3
  import {
3
- DEFAULT_ERROR_URI,
4
- DEFAULT_HELP_URI,
5
- type WhookErrorsDescriptors,
6
- } from '@whook/whook';
7
- import { type WhookAuthenticationData } from '@whook/authorization';
4
+ type WhookAuthenticationScope,
5
+ type WhookAuthenticationData,
6
+ type WhookBaseAuthenticationData,
7
+ } from '@whook/authorization';
8
8
 
9
- export interface OAuth2YErrorRegistry {
10
- E_UNKNOWN_AUTHORIZER_TYPE: [responseType: string];
11
- E_UNKNOWN_ACKNOWLEDGER_TYPE: [responseType: string];
12
- E_APPLICATION_ID_MISMATCH: [
13
- clientApplicationId: string,
14
- authenticationApplicationId: string,
15
- ];
16
-
17
- /**
18
- * Thrown when the refresh token is expired/invalid
19
- */
20
- E_BAD_REFRESH_TOKEN: [];
21
-
22
- /**
23
- * Thrown when application has no access allowed
24
- */
25
- E_ACCESS_DENIED: [clientId: string];
26
-
27
- /**
28
- * Thrown when the OAuth2 server had unexpected errors
29
- */
30
- E_OAUTH2: [];
31
-
32
- /**
33
- * Thrown when refresh_token cookie is absent and required
34
- */
35
- E_REFRESH_COOKIE: [cookie: string];
36
-
37
- /**
38
- * Thrown when server requires PKCE
39
- */
40
- E_PKCE_REQUIRED: [responseType: string];
41
-
42
- /**
43
- * Thrown when server does not support PKCE
44
- */
45
- E_PKCE_NOT_SUPPORTED: [responseType: string];
9
+ export interface WhookOAuth2Types {
10
+ clientId: string;
46
11
  }
47
12
 
48
- export const OAUTH2_ERRORS_DESCRIPTORS: Record<
49
- keyof OAuth2YErrorRegistry,
50
- WhookErrorsDescriptors[string]
51
- > = {
52
- E_UNKNOWN_AUTHORIZER_TYPE: {
53
- code: 'unsupported_response_type',
54
- status: 400,
55
- description: `The type "$0" is not supported.`,
56
- uri: DEFAULT_ERROR_URI,
57
- help: DEFAULT_HELP_URI,
58
- },
59
- E_APPLICATION_ID_MISMATCH: {
60
- code: 'unauthorized_client',
61
- status: 400,
62
- description: `The clients ids "$0"/"$1" are inconsistent.`,
63
- uri: DEFAULT_ERROR_URI,
64
- help: DEFAULT_HELP_URI,
65
- },
66
- E_BAD_REFRESH_TOKEN: {
67
- code: 'invalid_request',
68
- status: 400,
69
- description: 'The refresh token is expired/invalid.',
70
- uri: DEFAULT_ERROR_URI,
71
- help: DEFAULT_HELP_URI,
72
- },
73
- E_UNKNOWN_ACKNOWLEDGER_TYPE: {
74
- code: 'unsupported_response_type',
75
- status: 400,
76
- description: `Type "$0" not supported.`,
77
- uri: DEFAULT_ERROR_URI,
78
- help: DEFAULT_HELP_URI,
79
- },
80
- E_ACCESS_DENIED: {
81
- code: 'access_denied',
82
- status: 403,
83
- description: 'The user denied access to your application (id: "$0").',
84
- uri: DEFAULT_ERROR_URI,
85
- help: DEFAULT_HELP_URI,
86
- },
87
- E_OAUTH2: {
88
- code: 'server_error',
89
- status: 500,
90
- uri: DEFAULT_ERROR_URI,
91
- help: DEFAULT_HELP_URI,
92
- },
93
- E_REFRESH_COOKIE: {
94
- code: 'invalid_request',
95
- status: 400,
96
- description: `Could not find any refresh_token value in the cookie header ($0).`,
97
- uri: DEFAULT_ERROR_URI,
98
- help: DEFAULT_HELP_URI,
99
- },
100
- E_PKCE_REQUIRED: {
101
- code: 'invalid_request',
102
- status: 400,
103
- description: 'Code challenge required for this response type ($0)',
104
- uri: DEFAULT_ERROR_URI,
105
- help: DEFAULT_HELP_URI,
106
- },
107
- E_PKCE_NOT_SUPPORTED: {
108
- code: 'invalid_request',
109
- status: 400,
110
- description: 'Code challenge not supported for this response type ($0)',
111
- uri: DEFAULT_ERROR_URI,
112
- help: DEFAULT_HELP_URI,
113
- },
114
- };
13
+ export type WhookOAuth2ClientId = WhookOAuth2Types['clientId'];
115
14
 
116
- export interface OAuth2PasswordService<
117
- USERNAME extends string = string,
118
- PASSWORD extends string = string,
119
- > {
120
- check: (
121
- authenticationData: WhookAuthenticationData,
122
- username: USERNAME,
123
- password: PASSWORD,
124
- demandedScope: WhookAuthenticationData['scope'],
125
- ) => Promise<WhookAuthenticationData>;
15
+ declare module '@whook/authorization' {
16
+ export interface WhookAuthenticationData extends WhookBaseAuthenticationData {
17
+ clientId: WhookOAuth2ClientId;
18
+ }
126
19
  }
127
20
 
128
- export interface OAuth2AccessTokenService<TOKEN extends string = string> {
129
- create: (
130
- authenticationData: WhookAuthenticationData,
131
- tokenAuthenticationData: WhookAuthenticationData,
132
- additionalParameters?: Record<string, unknown>,
133
- ) => Promise<{
134
- token: TOKEN;
135
- expiresAt: number;
136
- }>;
137
- check: (
138
- authenticationData: WhookAuthenticationData,
139
- token: TOKEN,
140
- scope?: WhookAuthenticationData['scope'],
141
- ) => Promise<WhookAuthenticationData>;
21
+ export interface WhookOAuth2ClientGrants {
22
+ /** Grant types the client can be used with */
23
+ allowedGrantTypes: string[];
24
+ /** Scopes the client can delegate */
25
+ allowedScopes: WhookAuthenticationScope[];
26
+ /** Redirect URIS the client can be used with */
27
+ allowedRedirectURIS: string[];
28
+ /** Authentication data of the client */
29
+ authenticationData: WhookAuthenticationData;
30
+ /** Whether the client is public or private */
31
+ isPublicClient: boolean;
32
+ /** Whether the client can acknowledge for a user */
33
+ canAcknowledge?: boolean;
142
34
  }
143
35
 
144
- export type OAuth2RefreshTokenService<TOKEN extends string = string> =
145
- OAuth2AccessTokenService<TOKEN>;
146
-
147
- export type CheckApplicationService = (context: {
148
- applicationId: string;
149
- type: string;
150
- scope: string;
151
- redirectURI?: string;
152
- }) => Promise<{
153
- applicationId: string;
154
- type: string;
155
- scope: string;
156
- redirectURI: string;
157
- }>;
158
-
159
- export type OAuth2GranterAuthorize<P extends object> = (
160
- context: {
161
- clientId: WhookAuthenticationData['applicationId'];
162
- redirectURI: string;
163
- scope: WhookAuthenticationData['scope'];
36
+ /**
37
+ * A service that returns acknowledgments for a given client
38
+ */
39
+ export type WhookOAuth2ReadClientGrantsService = (
40
+ clientId: WhookOAuth2ClientId,
41
+ ) => Promise<WhookOAuth2ClientGrants>;
42
+
43
+ /**
44
+ * A function handling the OAuth2 authorize step
45
+ */
46
+ export type WhookOAuth2GranterAuthorize = (
47
+ authorizeParameters: {
48
+ clientId: WhookOAuth2ClientId;
49
+ clientGrants: WhookOAuth2ClientGrants;
50
+ demandedScopes: WhookAuthenticationScope[];
164
51
  },
165
- authorizeParameters: P,
166
52
  ) => Promise<{
167
- applicationId: WhookAuthenticationData['applicationId'];
168
- redirectURI: string;
169
- scope: WhookAuthenticationData['scope'];
53
+ scopes: WhookAuthenticationScope[];
170
54
  }>;
171
55
 
172
- export type Oauth2GranterAuthenticate<P extends object> = (
173
- authenticateParameters: P,
174
- authenticationData: WhookAuthenticationData,
175
- ) => Promise<WhookAuthenticationData>;
176
-
177
- export type OAuth2GranterAcknowledge<
178
- A extends object,
179
- P extends object = Record<string, unknown>,
56
+ /**
57
+ * A function handling the Whook specific acknowledge
58
+ * step allowing to build a front end over it (for users
59
+ * to actually authorize clients to act on their behalf)
60
+ */
61
+ export type WhookOAuth2GranterAcknowledge<
62
+ T extends object,
63
+ U extends object,
180
64
  > = (
181
- authenticationData: WhookAuthenticationData,
65
+ /** The acknowledging user authentication data */
66
+ userAuthenticationData: WhookAuthenticationData,
182
67
  acknowledgeParameters: {
183
- clientId: WhookAuthenticationData['applicationId'];
184
- redirectURI: string;
185
- scope: WhookAuthenticationData['scope'];
68
+ clientId: WhookOAuth2ClientId;
69
+ demandedRedirectURI: string;
70
+ demandedScopes: WhookAuthenticationScope[];
186
71
  },
187
- additionalParameters: P,
72
+ acknowledgeData: T,
188
73
  ) => Promise<{
189
- authenticationData: WhookAuthenticationData;
190
- redirectURI: string;
191
- acknowledgedData: A;
74
+ acknowledgedAuthenticationData: WhookAuthenticationData;
75
+ acknowledgedRedirectURI: string;
76
+ acknowledgedScopes: WhookAuthenticationScope[];
77
+ acknowledgedData: U;
192
78
  }>;
193
79
 
194
- export interface OAuth2GranterService<
195
- T extends object = Record<string, unknown>,
196
- U extends object = Record<string, unknown>,
197
- V extends object = Record<string, unknown>,
198
- W extends object = Record<string, unknown>,
80
+ /**
81
+ * A function handling the authenticate step
82
+ */
83
+ export type WhookOAuth2GranterAuthenticate<T extends object> = (
84
+ authenticateParameters: T,
85
+ optionalAuthenticationData?: WhookAuthenticationData | undefined,
86
+ ) => Promise<WhookAuthenticationData>;
87
+
88
+ export interface WhookOAuth2GranterDefinitions {
89
+ grantType?: string;
90
+ responseType?: string;
91
+ acknowledgeParameters: Record<string, unknown>;
92
+ acknowledgedData: Record<string, unknown>;
93
+ authenticateParameters: Record<string, unknown>;
94
+ }
95
+
96
+ export interface WhookOAuth2GranterService<
97
+ T extends WhookOAuth2GranterDefinitions,
199
98
  > {
200
- type: string;
201
- authorizer?: {
202
- responseType: string;
203
- authorize: OAuth2GranterAuthorize<T>;
204
- };
205
- acknowledger?: {
206
- acknowledgmentType: string;
207
- acknowledge: OAuth2GranterAcknowledge<U, V>;
208
- };
209
- authenticator?: {
210
- grantType: string;
211
- authenticate: Oauth2GranterAuthenticate<W>;
212
- };
99
+ grantType: T['grantType'];
100
+ responseType?: T['responseType'];
101
+ issuesRefreshToken: boolean;
102
+ authorize?: WhookOAuth2GranterAuthorize;
103
+ acknowledge?: WhookOAuth2GranterAcknowledge<
104
+ T['acknowledgeParameters'],
105
+ T['acknowledgedData']
106
+ >;
107
+ authenticate?: WhookOAuth2GranterAuthenticate<T['authenticateParameters']>;
213
108
  }
214
109
 
215
- export interface OAuth2Options {
110
+ export interface WhookOAuth2Options {
111
+ /** Id of the root application */
112
+ rootClientId: WhookOAuth2ClientId;
113
+ /** Where client authenticate */
216
114
  authenticateURL: string;
115
+ /** The available scopes of the whole application */
116
+ allowedScopes: WhookAuthenticationScope[];
117
+ /** Whether the client scope should be used as the default scope */
217
118
  defaultToClientScope?: boolean;
119
+ /** Whether PKCE should be forced or not */
218
120
  forcePKCE?: boolean;
121
+ /** Whether scopes should not only be filtered but strictly checked */
122
+ strictScopesChecks?: boolean;
219
123
  }
220
124
 
221
- export interface OAuth2Config {
222
- OAUTH2: OAuth2Options;
125
+ export interface WhookOAuth2Config {
126
+ OAUTH2: WhookOAuth2Options;
223
127
  ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
224
128
  }
225
129
 
@@ -230,10 +134,10 @@ export default location(
230
134
  type: 'service',
231
135
  inject: [
232
136
  'oAuth2ClientCredentialsGranter',
233
- 'oAuth2CodeGranter',
137
+ 'oAuth2AuthorizationCodeGranter',
234
138
  'oAuth2PasswordGranter',
235
139
  'oAuth2RefreshTokenGranter',
236
- 'oAuth2TokenGranter',
140
+ 'oAuth2ImplicitGranter',
237
141
  ],
238
142
  },
239
143
  async (services: Dependencies) =>