Okta + Spring Boot - how to get access token

We are using Spring Boot with Okta. I have configured application with OIDC and able to sign in with Okta. However, need to get access token for the logged in user. How can we get access token?

Spring Security is saving/maintaining idToken as jwt token but I am trying get accessToken value to use as bearer token for further API calls.


Iā€™m using the following in a logout() method to get an ID token. Maybe you can use something similar for the access token?

public ResponseEntity<?> logout(HttpServletRequest request,
                                @AuthenticationPrincipal(expression = "idToken") OidcIdToken idToken) {
    String logoutUrl = this.registration.getProviderDetails()

    Map<String, String> logoutDetails = new HashMap<>();
    logoutDetails.put("logoutUrl", logoutUrl);
    logoutDetails.put("idToken", idToken.getTokenValue());
    return ResponseEntity.ok().body(logoutDetails);

Thank for your quick reply. idToken does not have access token embedded in it. Seems like Spring is not saving access token on to the idToken. Any other ideas to get access token?

Used oAuth2AuthorizedClientService to get access token :

  public OAuth2AccessToken jwt(OAuth2AuthenticationToken authentication) {
    OAuth2AuthorizedClient client =
        oAuth2AuthorizedClientService.loadAuthorizedClient(authentication.getAuthorizedClientRegistrationId(), authentication.getName());

    return client.getAccessToken();
1 Like