Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the "id_token" and "refresh_token" when using spring-security-oauth2 client with OpenID Connect provider?

I have successfully integrated Spring Security OAuth2 with my Open ID Connect provider (Forgerock OpenAM). I can see the access token being retrieved. How can I access the id_token and refresh_token which are part of the response from the /token endpoint?

like image 444
KMeda Avatar asked Dec 10 '25 04:12

KMeda


1 Answers

I know this is an old thread, but I hope this helps anyone looking for the response.

Use your “Authentication authentication” object:

OAuth2AuthenticationToken oauth2Auth = (OAuth2AuthenticationToken) authentication;
String idToken = ((DefaultOidcUser) oauth2Auth.getPrincipal()).getIdToken().getTokenValue();

Regards.

like image 75
NRL Avatar answered Dec 12 '25 16:12

NRL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!