-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
395 lines (327 loc) · 18.5 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package oauth2
import (
"context"
"hash"
"html/template"
"net/url"
"time"
"github.com/hashicorp/go-retryablehttp"
"authelia.com/provider/oauth2/i18n"
"authelia.com/provider/oauth2/token/jwt"
)
// AuthorizeCodeLifespanProvider returns the provider for configuring the authorization code lifespan.
type AuthorizeCodeLifespanProvider interface {
// GetAuthorizeCodeLifespan returns the authorization code lifespan.
GetAuthorizeCodeLifespan(ctx context.Context) time.Duration
}
// RefreshTokenLifespanProvider returns the provider for configuring the refresh token lifespan.
type RefreshTokenLifespanProvider interface {
// GetRefreshTokenLifespan returns the refresh token lifespan.
GetRefreshTokenLifespan(ctx context.Context) time.Duration
}
// AccessTokenLifespanProvider returns the provider for configuring the access token lifespan.
type AccessTokenLifespanProvider interface {
// GetAccessTokenLifespan returns the access token lifespan.
GetAccessTokenLifespan(ctx context.Context) time.Duration
}
// VerifiableCredentialsNonceLifespanProvider returns the provider for configuring the access token lifespan.
type VerifiableCredentialsNonceLifespanProvider interface {
// GetVerifiableCredentialsNonceLifespan returns the nonce lifespan.
GetVerifiableCredentialsNonceLifespan(ctx context.Context) time.Duration
}
// IDTokenLifespanProvider returns the provider for configuring the ID token lifespan.
type IDTokenLifespanProvider interface {
// GetIDTokenLifespan returns the ID token lifespan.
GetIDTokenLifespan(ctx context.Context) time.Duration
}
// ScopeStrategyProvider returns the provider for configuring the scope strategy.
type ScopeStrategyProvider interface {
// GetScopeStrategy returns the scope strategy.
GetScopeStrategy(ctx context.Context) ScopeStrategy
}
// AudienceStrategyProvider returns the provider for configuring the audience strategy.
type AudienceStrategyProvider interface {
// GetAudienceStrategy returns the audience strategy.
GetAudienceStrategy(ctx context.Context) AudienceMatchingStrategy
}
// ClientCredentialsImplicitProvider describes the provider of the Client Credentials Flow Implicit actions.
type ClientCredentialsImplicitProvider interface {
// GetClientCredentialsFlowImplicitGrantRequested returns true if the PopulateTokenEndpointResponse portion of the
// oauth2.ClientCredentialsGrantHandler should implicitly grant all requested and validated scopes and audiences.
GetClientCredentialsFlowImplicitGrantRequested(ctx context.Context) (implicit bool)
}
// RedirectSecureCheckerProvider returns the provider for configuring the redirect URL security validator.
type RedirectSecureCheckerProvider interface {
// GetRedirectSecureChecker returns the redirect URL security validator.
GetRedirectSecureChecker(ctx context.Context) func(context.Context, *url.URL) bool
}
// RefreshTokenScopesProvider returns the provider for configuring the refresh token scopes.
type RefreshTokenScopesProvider interface {
// GetRefreshTokenScopes returns the refresh token scopes.
GetRefreshTokenScopes(ctx context.Context) []string
}
// DisableRefreshTokenValidationProvider returns the provider for configuring the refresh token validation.
type DisableRefreshTokenValidationProvider interface {
// GetDisableRefreshTokenValidation returns the disable refresh token validation flag.
GetDisableRefreshTokenValidation(ctx context.Context) bool
}
// AccessTokenIssuerProvider returns the provider for configuring the JWT issuer.
type AccessTokenIssuerProvider interface {
// GetAccessTokenIssuer returns the access token issuer.
GetAccessTokenIssuer(ctx context.Context) (issuer string)
}
// IDTokenIssuerProvider returns the provider for configuring the ID token issuer.
type IDTokenIssuerProvider interface {
// GetIDTokenIssuer returns the ID token issuer.
GetIDTokenIssuer(ctx context.Context) (issuer string)
}
// IntrospectionIssuerProvider returns the provider for configuring the Introspection issuer.
type IntrospectionIssuerProvider interface {
// GetIntrospectionIssuer returns the Introspection token issuer.
GetIntrospectionIssuer(ctx context.Context) (issuer string)
}
// IntrospectionJWTResponseSignerProvider returns the provider for configuring the Introspection signer.
type IntrospectionJWTResponseSignerProvider interface {
// GetIntrospectionJWTResponseSigner returns the Introspection JWT signer.
GetIntrospectionJWTResponseSigner(ctx context.Context) jwt.Signer
}
// AuthorizationServerIssuerIdentificationProvider provides OAuth 2.0 Authorization Server Issuer Identification related methods.
type AuthorizationServerIssuerIdentificationProvider interface {
GetAuthorizationServerIdentificationIssuer(ctx context.Context) (issuer string)
}
// JWTScopeFieldProvider returns the provider for configuring the JWT scope field.
type JWTScopeFieldProvider interface {
// GetJWTScopeField returns the JWT scope field.
GetJWTScopeField(ctx context.Context) jwt.JWTScopeFieldEnum
}
// JWTSecuredAuthorizeResponseModeIssuerProvider returns the provider for configuring the JARM issuer.
type JWTSecuredAuthorizeResponseModeIssuerProvider interface {
// GetJWTSecuredAuthorizeResponseModeIssuer returns the JARM issuer.
GetJWTSecuredAuthorizeResponseModeIssuer(ctx context.Context) string
}
// JWTSecuredAuthorizeResponseModeSignerProvider returns the provider for configuring the JARM signer.
type JWTSecuredAuthorizeResponseModeSignerProvider interface {
// GetJWTSecuredAuthorizeResponseModeSigner returns the JARM signer.
GetJWTSecuredAuthorizeResponseModeSigner(ctx context.Context) jwt.Signer
}
// JWTSecuredAuthorizeResponseModeLifespanProvider returns the provider for configuring the JWT Secured Authorize Response Mode token lifespan.
type JWTSecuredAuthorizeResponseModeLifespanProvider interface {
GetJWTSecuredAuthorizeResponseModeLifespan(ctx context.Context) time.Duration
}
// JWTProfileAccessTokensProvider provides configuration options to the JWT Profile strategies.
type JWTProfileAccessTokensProvider interface {
// GetEnforceJWTProfileAccessTokens when returning true will disregard the registered client capabilities for
// Access Token generation and produce only JWT Profile Access Tokens.
GetEnforceJWTProfileAccessTokens(ctx context.Context) (enable bool)
}
// AllowedPromptsProvider returns the provider for configuring the allowed prompts.
type AllowedPromptsProvider interface {
// GetAllowedPrompts returns the allowed prompts.
GetAllowedPrompts(ctx context.Context) (prompts []string)
}
// MinParameterEntropyProvider returns the provider for configuring the minimum parameter entropy.
type MinParameterEntropyProvider interface {
// GetMinParameterEntropy returns the minimum parameter entropy.
GetMinParameterEntropy(_ context.Context) (min int)
}
// SanitationAllowedProvider returns the provider for configuring the sanitation white list.
type SanitationAllowedProvider interface {
// GetSanitationWhiteList is a whitelist of form values that are required by the token endpoint. These values
// are safe for storage in a database (cleartext).
GetSanitationWhiteList(ctx context.Context) (whitelist []string)
}
// OmitRedirectScopeParamProvider returns the provider for configuring the omit redirect scope param.
type OmitRedirectScopeParamProvider interface {
// GetOmitRedirectScopeParam must be set to true if the scope query param is to be omitted
// in the authorization's redirect URI
GetOmitRedirectScopeParam(ctx context.Context) (omit bool)
}
// EnforcePKCEProvider returns the provider for configuring the enforcement of PKCE.
type EnforcePKCEProvider interface {
// GetEnforcePKCE returns the enforcement of PKCE.
GetEnforcePKCE(ctx context.Context) (enforce bool)
}
// EnforcePKCEForPublicClientsProvider returns the provider for configuring the enforcement of PKCE for public clients.
type EnforcePKCEForPublicClientsProvider interface {
// GetEnforcePKCEForPublicClients returns the enforcement of PKCE for public clients.
GetEnforcePKCEForPublicClients(ctx context.Context) (enforce bool)
}
// EnablePKCEPlainChallengeMethodProvider returns the provider for configuring the enable PKCE plain challenge method.
type EnablePKCEPlainChallengeMethodProvider interface {
// GetEnablePKCEPlainChallengeMethod returns the enable PKCE plain challenge method.
GetEnablePKCEPlainChallengeMethod(ctx context.Context) (enable bool)
}
// GrantTypeJWTBearerCanSkipClientAuthProvider returns the provider for configuring the grant type JWT bearer can skip client auth.
type GrantTypeJWTBearerCanSkipClientAuthProvider interface {
// GetGrantTypeJWTBearerCanSkipClientAuth returns the grant type JWT bearer can skip client auth.
GetGrantTypeJWTBearerCanSkipClientAuth(ctx context.Context) (permitted bool)
}
// GrantTypeJWTBearerIDOptionalProvider returns the provider for configuring the grant type JWT bearer ID optional.
type GrantTypeJWTBearerIDOptionalProvider interface {
// GetGrantTypeJWTBearerIDOptional returns the grant type JWT bearer ID optional.
GetGrantTypeJWTBearerIDOptional(ctx context.Context) (optional bool)
}
// GrantTypeJWTBearerIssuedDateOptionalProvider returns the provider for configuring the grant type JWT bearer issued date optional.
type GrantTypeJWTBearerIssuedDateOptionalProvider interface {
// GetGrantTypeJWTBearerIssuedDateOptional returns the grant type JWT bearer issued date optional.
GetGrantTypeJWTBearerIssuedDateOptional(ctx context.Context) (optional bool)
}
// GetJWTMaxDurationProvider returns the provider for configuring the JWT max duration.
type GetJWTMaxDurationProvider interface {
// GetJWTMaxDuration returns the JWT max duration.
GetJWTMaxDuration(ctx context.Context) (max time.Duration)
}
// TokenEntropyProvider returns the provider for configuring the token entropy.
type TokenEntropyProvider interface {
// GetTokenEntropy returns the token entropy.
GetTokenEntropy(ctx context.Context) (entropy int)
}
// GlobalSecretProvider returns the provider for configuring the global secret.
type GlobalSecretProvider interface {
// GetGlobalSecret returns the global secret.
GetGlobalSecret(ctx context.Context) (secret []byte, err error)
}
// RotatedGlobalSecretsProvider returns the provider for configuring the rotated global secrets.
type RotatedGlobalSecretsProvider interface {
// GetRotatedGlobalSecrets returns the rotated global secrets.
GetRotatedGlobalSecrets(ctx context.Context) (secrets [][]byte, err error)
}
// HMACHashingProvider returns the provider for configuring the hash function.
type HMACHashingProvider interface {
// GetHMACHasher returns the hash function.
GetHMACHasher(ctx context.Context) func() (hasher hash.Hash)
}
// SendDebugMessagesToClientsProvider returns the provider for configuring the send debug messages to clients.
type SendDebugMessagesToClientsProvider interface {
// GetSendDebugMessagesToClients returns the send debug messages to clients.
GetSendDebugMessagesToClients(ctx context.Context) (send bool)
}
// RevokeRefreshTokensExplicitlyProvider returns the provider for configuring the Refresh Token Explicit Revocation policy.
type RevokeRefreshTokensExplicitlyProvider interface {
// GetRevokeRefreshTokensExplicit returns true if a refresh token should only be revoked explicitly.
GetRevokeRefreshTokensExplicit(ctx context.Context) (explicit bool)
// GetEnforceRevokeFlowRevokeRefreshTokensExplicitClient returns true if a
// RevokeFlowRevokeRefreshTokensExplicitClient returning false should be enforced.
GetEnforceRevokeFlowRevokeRefreshTokensExplicitClient(ctx context.Context) (explicit bool)
}
// JWKSFetcherStrategyProvider returns the provider for configuring the JWKS fetcher strategy.
type JWKSFetcherStrategyProvider interface {
// GetJWKSFetcherStrategy returns the JWKS fetcher strategy.
GetJWKSFetcherStrategy(ctx context.Context) (strategy JWKSFetcherStrategy)
}
// HTTPClientProvider returns the provider for configuring the HTTP client.
type HTTPClientProvider interface {
// GetHTTPClient returns the HTTP client provider.
GetHTTPClient(ctx context.Context) (client *retryablehttp.Client)
}
// ClientAuthenticationStrategyProvider returns the provider for configuring the client authentication strategy.
type ClientAuthenticationStrategyProvider interface {
// GetClientAuthenticationStrategy returns the client authentication strategy.
GetClientAuthenticationStrategy(ctx context.Context) (strategy ClientAuthenticationStrategy)
}
// ResponseModeHandlerProvider returns the provider for configuring the response mode handlers.
type ResponseModeHandlerProvider interface {
// GetResponseModeHandlers returns the response mode handlers in order of execution.
GetResponseModeHandlers(ctx context.Context) (handlers ResponseModeHandlers)
}
// ResponseModeParameterHandlerProvider returns the providers for configuring additional parameters in the response
// mode phase of an Authorization Request which may not be possible to determine until the final response mode is known.
type ResponseModeParameterHandlerProvider interface {
// GetResponseModeParameterHandlers returns the ResponseModeParameterHandler's to process.
GetResponseModeParameterHandlers(ctx context.Context) (handlers ResponseModeParameterHandlers)
}
// MessageCatalogProvider returns the provider for configuring the message catalog.
type MessageCatalogProvider interface {
// GetMessageCatalog returns the message catalog.
GetMessageCatalog(ctx context.Context) (catalog i18n.MessageCatalog)
}
// FormPostHTMLTemplateProvider returns the provider for configuring the form post HTML template.
type FormPostHTMLTemplateProvider interface {
// GetFormPostHTMLTemplate returns the form post HTML template.
GetFormPostHTMLTemplate(ctx context.Context) (tmpl *template.Template)
}
// FormPostResponseProvider provides a writer interface for writing the form post responses.
type FormPostResponseProvider interface {
// GetFormPostResponseWriter returns a FormPostResponseWriter which should be utilized for writing the
// form post response type.
GetFormPostResponseWriter(ctx context.Context) FormPostResponseWriter
}
// AllowedJWTAssertionAudiencesProvider is a provider used in contexts where the permitted audiences for a JWT assertion
// is required to validate a request.
type AllowedJWTAssertionAudiencesProvider interface {
// GetAllowedJWTAssertionAudiences returns the permitted audience list for JWT Assertions.
GetAllowedJWTAssertionAudiences(ctx context.Context) (audiences []string)
}
// AuthorizeEndpointHandlersProvider returns the provider for configuring the authorize endpoint handlers.
type AuthorizeEndpointHandlersProvider interface {
// GetAuthorizeEndpointHandlers returns the authorize endpoint handlers.
GetAuthorizeEndpointHandlers(ctx context.Context) (handlers AuthorizeEndpointHandlers)
}
// TokenEndpointHandlersProvider returns the provider for configuring the token endpoint handlers.
type TokenEndpointHandlersProvider interface {
// GetTokenEndpointHandlers returns the token endpoint handlers.
GetTokenEndpointHandlers(ctx context.Context) (handlers TokenEndpointHandlers)
}
// TokenIntrospectionHandlersProvider returns the provider for configuring the token introspection handlers.
type TokenIntrospectionHandlersProvider interface {
// GetTokenIntrospectionHandlers returns the token introspection handlers.
GetTokenIntrospectionHandlers(ctx context.Context) (handlers TokenIntrospectionHandlers)
}
// RevocationHandlersProvider returns the provider for configuring the revocation handlers.
type RevocationHandlersProvider interface {
// GetRevocationHandlers returns the revocation handlers.
GetRevocationHandlers(ctx context.Context) (handlers RevocationHandlers)
}
// PushedAuthorizeRequestHandlersProvider returns the provider for configuring the PAR handlers.
type PushedAuthorizeRequestHandlersProvider interface {
// GetPushedAuthorizeEndpointHandlers returns the handlers.
GetPushedAuthorizeEndpointHandlers(ctx context.Context) (handlers PushedAuthorizeEndpointHandlers)
}
// RFC9628DeviceAuthorizeConfigProvider returns the provider for configuring the device authorization response.
//
// See: https://www.rfc-editor.org/rfc/rfc8628#section-3.2
type RFC9628DeviceAuthorizeConfigProvider interface {
// GetRFC8628CodeLifespan returns the device and user code lifespan.
GetRFC8628CodeLifespan(ctx context.Context) (lifespan time.Duration)
GetRFC8628UserVerificationURL(ctx context.Context) (url string)
GetRFC8628TokenPollingInterval(ctx context.Context) (interval time.Duration)
}
// RFC8628DeviceAuthorizeEndpointHandlersProvider returns the provider for setting up the Device authorization handlers.
type RFC8628DeviceAuthorizeEndpointHandlersProvider interface {
// GetRFC8628DeviceAuthorizeEndpointHandlers returns the handlers.
GetRFC8628DeviceAuthorizeEndpointHandlers(ctx context.Context) (handlers RFC8628DeviceAuthorizeEndpointHandlers)
}
// RFC8628UserAuthorizeEndpointHandlersProvider returns the provider for setting up the Device grant user interaction handlers.
type RFC8628UserAuthorizeEndpointHandlersProvider interface {
// GetRFC8628UserAuthorizeEndpointHandlers returns the handlers.
GetRFC8628UserAuthorizeEndpointHandlers(ctx context.Context) (handlers RFC8628UserAuthorizeEndpointHandlers)
}
// RFC8693ConfigProvider is the configuration provider for RFC8693 Token Exchange.
type RFC8693ConfigProvider interface {
GetRFC8693TokenTypes(ctx context.Context) (types map[string]RFC8693TokenType)
GetDefaultRFC8693RequestedTokenType(ctx context.Context) (tokenType string)
}
// UseLegacyErrorFormatProvider returns the provider for configuring whether to use the legacy error format.
//
// Deprecated: Do not use this flag anymore.
type UseLegacyErrorFormatProvider interface {
// GetUseLegacyErrorFormat returns whether to use the legacy error format.
//
// Deprecated: Do not use this flag anymore.
GetUseLegacyErrorFormat(ctx context.Context) (use bool)
}
// PushedAuthorizeRequestConfigProvider is the configuration provider for pushed
// authorization request.
type PushedAuthorizeRequestConfigProvider interface {
// GetPushedAuthorizeRequestURIPrefix is the request URI prefix. This is
// usually 'urn:ietf:params:oauth:request_uri:'.
GetPushedAuthorizeRequestURIPrefix(ctx context.Context) (prefix string)
// GetPushedAuthorizeContextLifespan is the lifespan of the short-lived PAR context.
GetPushedAuthorizeContextLifespan(ctx context.Context) (lifespan time.Duration)
// GetRequirePushedAuthorizationRequests indicates if the use of Pushed Authorization Requests is gobally required.
// In this mode, a client cannot pass authorize parameters at the 'authorize' endpoint. The 'authorize' endpoint
// must contain the PAR request_uri.
GetRequirePushedAuthorizationRequests(ctx context.Context) (enforce bool)
}