OAuth2TokenCustomizer lets an authorization server add application-specific claims to OAuth 2 access tokens before issuance. A resource server can then read those claims and use them in authorization decisions. section 15.2
@Bean
public OAuth2TokenCustomizer<JwtEncodingContext> jwtCustomizer() {
return context -> {
JwtClaimsSet.Builder claims = context.getClaims();
claims.claim("priority", "HIGH");
};
}
Define a JwtEncodingContext customizer, obtain the claims builder, and add a claim such as priority to the token. section 15.2
A practical integration proceeds in three stages:
- Customize the authorization server so issued JWT access tokens contain the application-specific claim. section 15.2
- Configure the resource server to convert the claim into a custom authentication object. section 15.2
- Apply the authentication value in authorization rules; an endpoint can expose the resulting authentication for verification. section 15.2
