-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient_authentication_strategy.go
463 lines (389 loc) · 25.7 KB
/
client_authentication_strategy.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
package oauth2
import (
"context"
"crypto/subtle"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
"time"
"authelia.com/provider/oauth2/internal/consts"
"authelia.com/provider/oauth2/token/jwt"
"authelia.com/provider/oauth2/x/errorsx"
)
type DefaultClientAuthenticationStrategy struct {
Store interface {
ClientManager
}
Config interface {
JWTStrategyProvider
JWKSFetcherStrategyProvider
AllowedJWTAssertionAudiencesProvider
}
}
func (s *DefaultClientAuthenticationStrategy) AuthenticateClient(ctx context.Context, r *http.Request, form url.Values, handler EndpointClientAuthHandler) (client Client, method string, err error) {
var (
id, secret string
idBasic, secretBasic string
assertionValue, assertionType string
hasPost, hasBasic, hasAssertion bool
)
idBasic, secretBasic, hasBasic, err = getClientCredentialsSecretBasic(r)
if err != nil {
return nil, "", errorsx.WithStack(ErrInvalidRequest.WithHint("The client credentials in the HTTP authorization header could not be parsed. Either the scheme was missing, the scheme was invalid, or the value had malformed data.").WithWrap(err).WithDebugError(err))
}
id, secret, hasPost = s.getClientCredentialsSecretPost(form)
assertionValue, assertionType, hasAssertion = getClientCredentialsClientAssertion(form)
var assertion *ClientAssertion
if hasAssertion {
if assertion, err = NewClientAssertion(ctx, s.Config.GetJWTStrategy(ctx), s.Store, assertionValue, assertionType, handler); err != nil {
return nil, "", err
}
}
if id, err = getClientCredentialsClientIDValid(id, idBasic, assertion); err != nil {
return nil, "", err
}
// Allow simplification of client authentication.
if !hasPost && hasBasic {
secret = secretBasic
}
hasNone := !hasPost && !hasBasic && assertion == nil && len(id) != 0
return s.authenticate(ctx, id, secret, assertion, hasBasic, hasPost, hasNone, handler)
}
func (s *DefaultClientAuthenticationStrategy) authenticate(ctx context.Context, id, secret string, assertion *ClientAssertion, hasBasic, hasPost, hasNone bool, handler EndpointClientAuthHandler) (client Client, method string, err error) {
var methods []string
if hasBasic {
methods = append(methods, consts.ClientAuthMethodClientSecretBasic)
}
if hasPost {
methods = append(methods, consts.ClientAuthMethodClientSecretPost)
}
if hasNone {
methods = append(methods, consts.ClientAuthMethodNone)
}
if assertion != nil {
methods = append(methods, fmt.Sprintf("%s (i.e. %s or %s)", consts.ClientAssertionTypeJWTBearer, consts.ClientAuthMethodPrivateKeyJWT, consts.ClientAuthMethodClientSecretJWT))
if assertion.Client != nil {
client = assertion.Client
}
}
if client == nil {
if client, err = s.Store.GetClient(ctx, id); err != nil {
return nil, "", errorsx.WithStack(ErrInvalidClient.WithWrap(err).WithDebugError(err))
}
}
switch len(methods) {
case 0:
// The 0 case means no authentication information at all exists even if the client is a public client. This
// likely only occurs on requests where the client_id is not known.
return nil, "", errorsx.WithStack(ErrInvalidRequest.WithHint("Client Authentication failed with no known authentication method."))
case 1:
// Proper authentication has occurred.
break
default:
// The default case handles the situation where a client has leveraged multiple client authentication methods
// within a request per https://datatracker.ietf.org/doc/html/rfc6749#section-2.3 clients MUST NOT use more than
// one, however some bad clients use a shotgun approach to authentication. This allows developing a personal
// policy around these bad clients on a per-client basis.
if capc, ok := client.(ClientAuthenticationPolicyClient); ok && capc.GetAllowMultipleAuthenticationMethods() {
break
}
return nil, "", errorsx.WithStack(ErrInvalidRequest.
WithHintf("Client Authentication failed with more than one known authentication method included in the request which is not permitted.").
WithDebugf("The registered client with id '%s' and the authorization server policy does not permit this malformed request. The `%s_endpoint_auth_method` methods determined to be used were '%s'.", client.GetID(), handler.Name(), strings.Join(methods, "', '")))
}
switch {
case assertion != nil:
method, err = s.doAuthenticateAssertionJWTBearer(ctx, client, assertion, handler)
case hasBasic, hasPost:
method, err = s.doAuthenticateClientSecret(ctx, client, secret, hasBasic, hasPost, handler)
default:
method, err = s.doAuthenticateNone(ctx, client, handler)
}
if err != nil {
return nil, "", err
}
return client, method, nil
}
// NewClientAssertion converts a raw assertion string into a *ClientAssertion.
func NewClientAssertion(ctx context.Context, strategy jwt.Strategy, store ClientManager, assertion, assertionType string, handler EndpointClientAuthHandler) (a *ClientAssertion, err error) {
var (
token *jwt.Token
id, method string
client Client
)
switch assertionType {
case consts.ClientAssertionTypeJWTBearer:
if len(assertion) == 0 {
return &ClientAssertion{Assertion: assertion, Type: assertionType}, errorsx.WithStack(ErrInvalidRequest.WithHintf("The request parameter 'client_assertion' must be set when using 'client_assertion_type' of '%s'.", consts.ClientAssertionTypeJWTBearer))
}
default:
return &ClientAssertion{Assertion: assertion, Type: assertionType}, errorsx.WithStack(ErrInvalidRequest.WithHintf("Unknown client_assertion_type '%s'.", assertionType))
}
if token, err = strategy.Decode(ctx, assertion, jwt.WithAllowUnverified(), jwt.WithSigAlgorithm(jwt.SignatureAlgorithmsNone...)); err != nil {
return &ClientAssertion{Assertion: assertion, Type: assertionType}, resolveJWTErrorToRFCError(err)
}
if id, err = token.Claims.GetSubject(); err != nil || len(id) == 0 {
if id, err = token.Claims.GetIssuer(); err != nil || len(id) == 0 {
return &ClientAssertion{Assertion: assertion, Type: assertionType}, nil
}
}
if client, err = store.GetClient(ctx, id); err != nil {
return &ClientAssertion{Assertion: assertion, Type: assertionType, ID: id}, nil
}
method = consts.ClientAuthMethodPrivateKeyJWT
if jwt.IsSignedJWTClientSecretAlg(token.SignatureAlgorithm) {
method = consts.ClientAuthMethodClientSecretJWT
}
return &ClientAssertion{
Assertion: assertion,
Type: assertionType,
Parsed: true,
ID: id,
Method: method,
Algorithm: string(token.SignatureAlgorithm),
Client: client,
}, nil
}
// ClientAssertion represents a client assertion.
type ClientAssertion struct {
Assertion, Type string
Parsed bool
ID, Method, Algorithm string
Client Client
}
func (s *DefaultClientAuthenticationStrategy) doAuthenticateNone(ctx context.Context, client Client, handler EndpointClientAuthHandler) (method string, err error) {
if c, ok := client.(AuthenticationMethodClient); ok {
if method = handler.GetAuthMethod(c); method != consts.ClientAuthMethodNone {
return "", errorsx.WithStack(
ErrInvalidClient.
WithHintf("The request was determined to be using '%s_endpoint_auth_method' method '%s', however the OAuth 2.0 client registration does not allow this method.", handler.Name(), consts.ClientAuthMethodNone).
WithDebugf("The registered client with id '%s' is configured to only support '%s_endpoint_auth_method' method '%s'. Either the Authorization Server client registration will need to have the '%s_endpoint_auth_method' updated to '%s' or the Relying Party will need to be configured to use '%s'.", client.GetID(), handler.Name(), method, handler.Name(), consts.ClientAuthMethodNone, method))
}
}
if !client.IsPublic() {
return "", errorsx.WithStack(
ErrInvalidClient.
WithHintf("The request was determined to be using '%s_endpoint_auth_method' method '%s', however the OAuth 2.0 client registration does not allow this method.", consts.ClientAuthMethodNone, handler.Name()).
WithDebugf("The registered client with id '%s' is configured with a confidential client type but only client registrations with a public client type can use this '%s_endpoint_auth_method'.", client.GetID(), handler.Name()))
}
return consts.ClientAuthMethodNone, nil
}
func (s *DefaultClientAuthenticationStrategy) doAuthenticateClientSecret(ctx context.Context, client Client, rawSecret string, hasBasic, hasPost bool, handler EndpointClientAuthHandler) (method string, err error) {
method = consts.ClientAuthMethodClientSecretBasic
if !hasBasic && hasPost {
method = consts.ClientAuthMethodClientSecretPost
}
if c, ok := client.(AuthenticationMethodClient); ok {
switch cmethod := handler.GetAuthMethod(c); {
case cmethod == "" && handler.AllowAuthMethodAny():
break
case cmethod != method:
return "", errorsx.WithStack(
ErrInvalidClient.
WithHintf("The request was determined to be using '%s_endpoint_auth_method' method '%s', however the OAuth 2.0 client registration does not allow this method.", handler.Name(), method).
WithDebugf("The registered client with id '%s' is configured to only support '%s_endpoint_auth_method' method '%s'. Either the Authorization Server client registration will need to have the '%s_endpoint_auth_method' updated to '%s'x or the Relying Party will need to be configured to use '%s'.", client.GetID(), handler.Name(), cmethod, handler.Name(), method, cmethod))
}
}
switch err = CompareClientSecret(ctx, client, []byte(rawSecret)); {
case err == nil:
return method, nil
case errors.Is(err, ErrClientSecretNotRegistered):
return "", errorsx.WithStack(
ErrInvalidClient.
WithHintf("The request was determined to be using '%s_endpoint_auth_method' method '%s', however the OAuth 2.0 client registration does not allow this method.", handler.Name(), method).
WithDebugf("The registered client with id '%s' has no 'client_secret' however this is required to process the particular request.", client.GetID()),
)
default:
return "", errorsx.WithStack(ErrInvalidClient.WithWrap(err).WithDebugError(err))
}
}
func (s *DefaultClientAuthenticationStrategy) doAuthenticateAssertionJWTBearer(ctx context.Context, client Client, assertion *ClientAssertion, handler EndpointClientAuthHandler) (method string, err error) {
var (
token *jwt.Token
c AuthenticationMethodClient
ok bool
)
if c, ok = client.(AuthenticationMethodClient); !ok {
return "", errorsx.WithStack(ErrInvalidRequest.WithHint("The registered client does not support OAuth 2.0 JWT Profile Client Authentication RFC7523 or OpenID Connect 1.0 specific authentication methods."))
}
if !assertion.Parsed {
}
if method, _, _, token, err = s.doAuthenticateAssertionParseAssertionJWTBearer(ctx, c, assertion, handler); err != nil {
return "", err
}
if token == nil {
return "", errorsx.WithStack(ErrInvalidClient.WithDebug("The client assertion did not result in a parsed token."))
}
clientID := []byte(client.GetID())
claims := &jwt.JWTClaims{}
claims.FromMapClaims(token.Claims.ToMapClaims())
switch {
case subtle.ConstantTimeCompare([]byte(claims.Issuer), clientID) == 0:
return "", errorsx.WithStack(ErrInvalidClient.WithHint("The client assertion had invalid claims.").WithDebug("Claim 'iss' from 'client_assertion' must match the 'client_id' of the OAuth 2.0 Client."))
case subtle.ConstantTimeCompare([]byte(claims.Subject), clientID) == 0:
return "", errorsx.WithStack(ErrInvalidClient.WithHint("The client assertion had invalid claims.").WithDebug("Claim 'sub' from 'client_assertion' must match the 'client_id' of the OAuth 2.0 Client."))
case claims.JTI == "":
return "", errorsx.WithStack(ErrInvalidClient.WithHint("The client assertion had invalid claims.").WithDebug("Claim 'jti' from 'client_assertion' must be set but is not."))
default:
switch cmethod := handler.GetAuthMethod(c); {
case cmethod == "" && handler.AllowAuthMethodAny():
break
case cmethod != method:
return "", errorsx.WithStack(
ErrInvalidClient.
WithHintf("The request was determined to be using '%s_endpoint_auth_method' method '%s', however the OAuth 2.0 client registration does not allow this method.", handler.Name(), method).
WithDebugf("The registered client with id '%s' is configured to only support '%s_endpoint_auth_method' method '%s'. Either the Authorization Server client registration will need to have the '%s_endpoint_auth_method' updated to '%s' or the Relying Party will need to be configured to use '%s'.", client.GetID(), handler.Name(), cmethod, handler.Name(), method, cmethod))
}
if !assertion.Parsed {
return "", errorsx.WithStack(ErrInvalidClient.WithDebug("The client assertion was not able to be parsed."))
}
if err = s.Store.ClientAssertionJWTValid(ctx, claims.JTI); err != nil {
return "", errorsx.WithStack(ErrJTIKnown.WithHint("Claim 'jti' from 'client_assertion' MUST only be used once.").WithDebugError(err))
}
if err = s.Store.SetClientAssertionJWT(ctx, claims.JTI, time.Unix(claims.ExpiresAt.Unix(), 0)); err != nil {
return "", err
}
return method, nil
}
}
func (s *DefaultClientAuthenticationStrategy) doAuthenticateAssertionParseAssertionJWTBearer(ctx context.Context, client AuthenticationMethodClient, assertion *ClientAssertion, handler EndpointClientAuthHandler) (method, kid, alg string, token *jwt.Token, err error) {
audience := s.Config.GetAllowedJWTAssertionAudiences(ctx)
if len(audience) == 0 {
return "", "", "", nil, errorsx.WithStack(ErrMisconfiguration.WithHint("The authorization server does not support OAuth 2.0 JWT Profile Client Authentication RFC7523 or OpenID Connect 1.0 specific authentication methods.").WithDebug("The authorization server could not determine any safe value for it's audience but it's required to validate the RFC7523 client assertions."))
}
if token, err = s.Config.GetJWTStrategy(ctx).Decode(ctx, assertion.Assertion, jwt.WithClient(&EndpointClientAuthJWTClient{client: client, handler: handler}), jwt.WithSigAlgorithm(jwt.SignatureAlgorithmsNone...)); err != nil {
return "", "", "", nil, errorsx.WithStack(fmtClientAssertionDecodeError(token, client, handler, audience, err))
}
optsClaims := []jwt.ClaimValidationOption{
jwt.ValidateAudienceAny(audience...), // Satisfies RFC7523 Section 3 Point 3.
jwt.ValidateRequireExpiresAt(), // Satisfies RFC7523 Section 3 Point 4.
jwt.ValidateTimeFunc(time.Now),
}
if err = token.Claims.Valid(optsClaims...); err != nil {
return "", "", "", nil, errorsx.WithStack(fmtClientAssertionDecodeError(token, client, handler, audience, err))
}
optsHeader := []jwt.HeaderValidationOption{
jwt.ValidateKeyID(handler.GetAuthSigningKeyID(client)),
jwt.ValidateAlgorithm(handler.GetAuthSigningAlg(client)),
jwt.ValidateEncryptionKeyID(handler.GetAuthEncryptionKeyID(client)),
jwt.ValidateKeyAlgorithm(handler.GetAuthEncryptionAlg(client)),
jwt.ValidateContentEncryption(handler.GetAuthEncryptionEnc(client)),
}
if err = token.Valid(optsHeader...); err != nil {
return "", "", "", nil, errorsx.WithStack(fmtClientAssertionDecodeError(token, client, handler, audience, err))
}
return assertion.Method, kid, alg, token, nil
}
func (s *DefaultClientAuthenticationStrategy) getClientCredentialsSecretPost(form url.Values) (id, secret string, ok bool) {
id, secret = form.Get(consts.FormParameterClientID), form.Get(consts.FormParameterClientSecret)
return id, secret, len(id) != 0 && len(secret) != 0
}
func resolveJWTErrorToRFCError(err error) (rfc error) {
var e *RFC6749Error
if errors.As(err, &e) {
return errorsx.WithStack(e)
}
if errJWTValidation := new(jwt.ValidationError); errors.As(err, &errJWTValidation) {
switch {
case errJWTValidation.Has(jwt.ValidationErrorMalformed):
e = ErrInvalidClient.
WithHint("OAuth 2.0 client provided a client assertion which could not be decoded or validated.").
WithWrap(err).
WithDebugf("OAuth 2.0 client provided a client assertion that was malformed. %s.", strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
case errJWTValidation.Has(jwt.ValidationErrorMalformedNotCompactSerialized):
e = ErrInvalidClient.
WithHint("OAuth 2.0 client provided a client assertion which could not be decoded or validated.").
WithWrap(err).
WithDebugf("OAuth 2.0 client provided a client assertion that was malformed. The client assertion does not appear to be a JWE or JWS compact serialized JWT.")
case errJWTValidation.Has(jwt.ValidationErrorUnverifiable):
e = ErrInvalidClient.
WithHint("OAuth 2.0 client provided a client assertion which could not be decoded or validated.").
WithWrap(err).
WithDebugf("OAuth 2.0 client provided a client assertion that was not able to be verified. %s.", strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
default:
e = ErrInvalidClient.
WithHint("OAuth 2.0 client provided a client assertion which could not be decoded or validated.").
WithWrap(err).
WithDebugf("Unknown error occurred handling the client assertion.")
}
}
return errorsx.WithStack(e)
}
func fmtClientAssertionDecodeError(token *jwt.Token, client AuthenticationMethodClient, handler EndpointClientAuthHandler, audience []string, inner error) (outer *RFC6749Error) {
outer = ErrInvalidClient.WithWrap(inner).WithHintf("OAuth 2.0 client with id '%s' provided a client assertion which could not be decoded or validated.", client.GetID())
if errJWTValidation := new(jwt.ValidationError); errors.As(inner, &errJWTValidation) {
switch {
case errJWTValidation.Has(jwt.ValidationErrorHeaderKeyIDInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be signed with the 'kid' header value '%s' due to the client registration 'request_object_signing_key_id' value but the client assertion was signed with the 'kid' header value '%s'.", client.GetID(), handler.GetAuthSigningKeyID(client), token.KeyID)
case errJWTValidation.Has(jwt.ValidationErrorHeaderAlgorithmInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be signed with the 'alg' header value '%s' due to the client registration 'request_object_signing_alg' value but the client assertion was signed with the 'alg' header value '%s'.", client.GetID(), handler.GetAuthSigningAlg(client), token.SignatureAlgorithm)
case errJWTValidation.Has(jwt.ValidationErrorHeaderTypeInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be signed with the 'typ' header value '%s' but the client assertion was signed with the 'typ' header value '%s'.", client.GetID(), consts.JSONWebTokenTypeJWT, token.Header[consts.JSONWebTokenHeaderType])
case errJWTValidation.Has(jwt.ValidationErrorHeaderEncryptionTypeInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with the 'typ' header value '%s' but the client assertion was encrypted with the 'typ' header value '%s'.", client.GetID(), consts.JSONWebTokenTypeJWT, token.HeaderJWE[consts.JSONWebTokenHeaderType])
case errJWTValidation.Has(jwt.ValidationErrorHeaderContentTypeInvalidMismatch):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with a 'cty' header value and signed with a 'typ' value that match but the client assertions was encrypted with the 'cty' header value '%s' and signed with the 'typ' header value '%s'.", client.GetID(), token.HeaderJWE[consts.JSONWebTokenHeaderContentType], token.HeaderJWE[consts.JSONWebTokenHeaderType])
case errJWTValidation.Has(jwt.ValidationErrorHeaderContentTypeInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with the 'cty' header value '%s' but the client assertion was encrypted with the 'cty' header value '%s'.", client.GetID(), consts.JSONWebTokenTypeJWT, token.HeaderJWE[consts.JSONWebTokenHeaderContentType])
case errJWTValidation.Has(jwt.ValidationErrorHeaderEncryptionKeyIDInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with the 'kid' header value '%s' due to the client registration 'request_object_encryption_key_id' value but the client assertion was encrypted with the 'kid' header value '%s'.", client.GetID(), handler.GetAuthEncryptionKeyID(client), token.EncryptionKeyID)
case errJWTValidation.Has(jwt.ValidationErrorHeaderKeyAlgorithmInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with the 'alg' header value '%s' due to the client registration 'request_object_encryption_alg' value but the client assertion was encrypted with the 'alg' header value '%s'.", client.GetID(), handler.GetAuthEncryptionAlg(client), token.KeyAlgorithm)
case errJWTValidation.Has(jwt.ValidationErrorHeaderContentEncryptionInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' expects client assertions to be encrypted with the 'enc' header value '%s' due to the client registration 'request_object_encryption_enc' value but the client assertion was encrypted with the 'enc' header value '%s'.", client.GetID(), handler.GetAuthEncryptionEnc(client), token.ContentEncryption)
case errJWTValidation.Has(jwt.ValidationErrorMalformedNotCompactSerialized):
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was malformed. The client assertion does not appear to be a JWE or JWS compact serialized JWT.", client.GetID())
case errJWTValidation.Has(jwt.ValidationErrorMalformed):
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was malformed. %s.", client.GetID(), strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
case errJWTValidation.Has(jwt.ValidationErrorUnverifiable):
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was not able to be verified. %s.", client.GetID(), strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
case errJWTValidation.Has(jwt.ValidationErrorSignatureInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that has an invalid signature. %s.", client.GetID(), strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
case errJWTValidation.Has(jwt.ValidationErrorExpired):
exp, err := token.Claims.GetExpirationTime()
if err == nil {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was expired. The client assertion expired at %d.", client.GetID(), exp.Int64())
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was expired. The client assertion does not have an 'exp' claim or it has an invalid type.", client.GetID())
}
case errJWTValidation.Has(jwt.ValidationErrorIssuedAt):
iat, err := token.Claims.GetIssuedAt()
if err == nil {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was issued in the future. The client assertion was issued at %d.", client.GetID(), iat.Int64())
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was issued in the future. The client assertion does not have an 'iat' claim or it has an invalid type.", client.GetID())
}
case errJWTValidation.Has(jwt.ValidationErrorNotValidYet):
nbf, err := token.Claims.GetNotBefore()
if err == nil {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was issued in the future. The client assertion is not valid before %d.", client.GetID(), nbf.Int64())
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that was issued in the future. The client assertion does not have an 'nbf' claim or it has an invalid type.", client.GetID())
}
case errJWTValidation.Has(jwt.ValidationErrorIssuer):
iss, err := token.Claims.GetIssuer()
if err == nil {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that has an invalid issuer. The client assertion was expected to have an 'iss' claim which matches the value '%s' but the 'iss' claim had the value '%s'.", client.GetID(), client.GetID(), iss)
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that has an invalid issuer. The client assertion does not have an 'iss' claim or it has an invalid type.", client.GetID())
}
case errJWTValidation.Has(jwt.ValidationErrorAudience):
aud, err := token.Claims.GetAudience()
if err == nil {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that has an invalid audience. The client assertion was expected to have an 'aud' claim which matches one of the values '%s' but the 'aud' claim had the values '%s'.", client.GetID(), strings.Join(audience, "', '"), strings.Join(aud, "', '"))
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that has an invalid audience. The client assertion does not have an 'aud' claim or it has an invalid type.", client.GetID())
}
case errJWTValidation.Has(jwt.ValidationErrorClaimsInvalid):
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that had one or more invalid claims. Error occurred trying to validate the client assertions claims: %s", client.GetID(), strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
default:
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that could not be validated. Error occurred trying to validate the client assertion: %s", client.GetID(), strings.TrimPrefix(errJWTValidation.Error(), "go-jose/go-jose: "))
}
} else if errJWKLookup := new(jwt.JWKLookupError); errors.As(inner, &errJWKLookup) {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that could not be validated due to a key lookup error. %s.", client.GetID(), errJWKLookup.Description)
} else {
return outer.WithDebugf("OAuth 2.0 client with id '%s' provided a client assertion that could not be validated. %s.", client.GetID(), ErrorToDebugRFC6749Error(inner).Error())
}
}