Spring
[ Spring Authorization Server ] Access Token ( JWT ) 확장하기
Arthur Kim
2021. 12. 29. 15:39
spring-authorization-server 에서 custom claim 추가하기
@Bean
public OAuth2TokenCustomizer<JwtEncodingContext> customizer() {
return context -> {
if (context.getTokenType() == OAuth2TokenType.ACCESS_TOKEN) {
OAuth2Authorization oAuth2Authorization = context.getAuthorization();
if (oAuth2Authorization != null) {
OAuth2AuthorizationRequest authorizationRequest =
oAuth2Authorization.getAttribute(OAuth2AuthorizationRequest.class.getName());
if (authorizationRequest != null) {
context.getClaims().claims(claims -> {
claims.put("custom token", "cello");
// TODO: cello 개별 속성 추가
});
}
}
}
};
}
참조 -
https://github.com/spring-projects/spring-authorization-server/issues/199
Customizing Jwt claims and headers needs to be more flexible · Issue #199 · spring-projects/spring-authorization-server
The NimbusJwsEncoder.jwtCustomizer (#173) needs to be re-designed as it does not easily provide all the context required for customization. For example, it is complicated to obtain the associated O...
github.com