-
Notifications
You must be signed in to change notification settings - Fork 41.3k
Validate the aud claim in OAuth2 resource server #29084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Provide JWT audience field validation support, if the new optional audience property is supplied Fixes spring-projectsgh-28427
/** | ||
* Identifies the recipients that the JWT is intended for. | ||
*/ | ||
private String audience; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the spring-cloud-gateway scenario, I suggest to use List<String>
instead of String
.
client -> spring-cloud-gateway -> resource-server-1
-> resource-server-2
-> etc..
When spring-cloud-gateway validate the access-token, the valid audience is a list of string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And rename variable from audience
to audiences
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @chenrujun. This makes sense to me. The validation should then use a predicate that checks that at least one audience in the JWT matches one of the configured audiences. Does that makes sense to you, @mbhave?
The changes in this PR only apply the audience validation if decoder is configured via "jwk-set-uri". Would it make sense to also provide this feature when decoder is configured via "issuer-uri"? |
@ahmedmq thank you for making your first contribution to Spring Boot. |
This feature is not mentioned in the docs, in fact audience validation is shown as an example for custom validators: This feature should be in the docs |
got it, thanks! |
Configure a new optional property for audience in resource server. Validate the audience claim in JWT if the audience property is provided.
Closes #28427