Skip to content

Commit 49129d2

Browse files
authored
[CLOUDTRUST-5700] Log invalid audience when validating jot (#157)
1 parent 3e255cd commit 49129d2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

middleware/authentication.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func ParseAndValidateOIDCToken(ctx context.Context, accessToken string, keycloak
223223
}
224224

225225
if !jot.AssertMatchingAudience(audienceRequired) {
226-
logger.Info(ctx, "msg", "Authorization error: Incorrect audience")
226+
logger.Info(ctx, "msg", "Authorization error: Incorrect audience", "audience", jot.GetAudience())
227227
return nil, security.ForbiddenError{}
228228
}
229229

@@ -297,6 +297,7 @@ type TokenAudience interface {
297297
GetUsername() string
298298
GetIssuer() string
299299
GetGroups() []string
300+
GetAudience() any
300301

301302
AssertMatchingAudience(requiredValue string) bool
302303
}
@@ -341,6 +342,9 @@ func (ta *TokenAudienceStringArray) GetIssuer() string { return ta.Issuer }
341342
// GetGroups provides the groups from the token
342343
func (ta *TokenAudienceStringArray) GetGroups() []string { return ta.Groups }
343344

345+
// GetAudience provides the audience from the token
346+
func (ta *TokenAudienceStringArray) GetAudience() any { return ta.Audience }
347+
344348
// AssertMatchingAudience checks if the required audience is in the token list of audiences
345349
func (ta *TokenAudienceStringArray) AssertMatchingAudience(requiredValue string) bool {
346350
return AssertMatchingAudience(ta.Audience, requiredValue)
@@ -358,6 +362,9 @@ func (ta *TokenAudienceString) GetIssuer() string { return ta.Issuer }
358362
// GetGroups provides the groups from the token
359363
func (ta *TokenAudienceString) GetGroups() []string { return ta.Groups }
360364

365+
// GetAudience provides the audience from the token
366+
func (ta *TokenAudienceString) GetAudience() any { return ta.Audience }
367+
361368
// AssertMatchingAudience checks if the required audience is in the token list of audiences
362369
func (ta *TokenAudienceString) AssertMatchingAudience(requiredValue string) bool {
363370
return ta.Audience == requiredValue

0 commit comments

Comments
 (0)