Skip to content

Commit

Permalink
update audience error returned to have more information (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohEmily authored Mar 15, 2024
1 parent 0e62b10 commit 4fe24aa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rpc/server_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,18 @@ func (ss *simpleServer) ensureAuthed(ctx context.Context) (context.Context, erro
}
}
if !audVerified {
return nil, status.Error(codes.Unauthenticated, "invalid audience")
audienceList := strings.Join(ss.authAudience, ", ")
var claimAudience []byte
err := claims.RegisteredClaims.Audience.UnmarshalJSON(claimAudience)
if err != nil {
ss.logger.Errorw("invalid audience: cannot unmarshall audience claim",
"expected audience list", audienceList)
return nil, status.Error(codes.Unauthenticated, "invalid audience")
}
ss.logger.Errorw("invalid audience",
"expected audience list", audienceList,
"registered audience", claims.RegisteredClaims.Audience)
return nil, status.Error(codes.Unauthenticated, "invalid audience (registered aud claim: "+string(claimAudience)+")")
}

// Note(erd): may want to verify issuers in the future where the claims/scope are
Expand Down

0 comments on commit 4fe24aa

Please sign in to comment.