Unable to retrieve custom claims from JwtAuthenticationToken and JWT okta spring boot starter 2.x

Hello Team,

failing to retrieve custom claims in rest controller method
project stack
Spring boot 2.x
Okta spring boot starter 2.x

Client → reactJS app
server side → spring boot

dev account

Followed this example to retrieve JWTAuthenticationToken and Jwt, but from these references unable to retrieve custom claims created for SPA application, more over my observation is that it is like hit and miss sometimes custom attributes are populated and most of the time they are not available.

My source code looks like below
public class WebSecurity extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
.authorizeRequests(authorize → authorize

    public void configure(WebSecurity web) throws Exception {

    public ResponseEntity<String> getCliam(JwtAuthenticationToken token, @AuthenticationPrincipal Jwt jwt) {
        token.getTokenAttributes().forEach((key, value) -> System.out.println(key + "---------" + value));

        jwt.getClaims().forEach((key, value) -> System.out.println(key + "---------" + value));

please correct me if my understanding wrong and kindly support in resolving this issue.
Thank you,

Are you using a custom authorization server to 1) add these custom claims and 2) actually mint the tokens?

When you say they are sometimes populated, are you ensuring that the user you are signing in as has a value for the attribute being used to populate the claim?

Thank you was able to resolve issue

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.