-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
How-to: Override default algorithm used to sign Jwt #1030
Comments
add accessTokenSignatureAlgorithm to TokenSettings to allow configuring Signature algo for access tokens
Not all access tokens are signed. This only applies to However, some clients may be configured for opaque tokens (
You can override the default algorithm by configuring an OAuth2TokenCustomizer @Bean
OAuth2TokenCustomizer<JwtEncodingContext> jwtCustomizer() {
return context -> {
if (OAuth2TokenType.ACCESS_TOKEN.equals(context.getTokenType())) {
context.getJwsHeader().algorithm(MacAlgorithm.HS512);
}
};
} This should work for your configuration. |
@jgrandja Thank you for the explanation, with that I am in agreement with your view on not having JWT specific setting on access token settings in general. I also tried out your suggestion and it works for my use case. However this was not obvious to me, as a specific algorithm setting is exists for idToken. Should we have a how-to for this use case somewhere? (please let me know if one exists already) |
Yes, this question will come up again so we'll document it in the reference. I changed the subject of the issue. I'll close the associated PR and we'll address this soon in the reference manual. |
@TelmaCorreia if you follow the discussion above, this is by design. Access token does not have to be a JWT and thus it does not make sense to put a JWT signing algorithm in access token setting. Did you try setting up a token customizer and change algorithm to your preference -
You may also have to setup a |
Clear the default idToken algorithm and add all algorithms supported by jwk
|
Expected Behavior
One should be able to choose Signature Algorithm used to sign access tokens.
Current Behavior
No configuration parameter exists in
TokenSettings
to choose signature algo for access token. It is hard coded as RS256 while generating Jwt.spring-authorization-server/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/token/JwtGenerator.java
Lines 93 to 102 in aed93f3
Context
Because of this, cannot choose another algorithm like HSxxx or EDxxx for access tokens.
TokenSettings
does allow to configuring signing algo for Id Token usingidTokenSignatureAlgorithm(SignatureAlgorithm idTokenSignatureAlgorithm)
method in the Builder.The text was updated successfully, but these errors were encountered: