Spring Boot Oauth2 - Where is the access token stored?

Viewed 4267

I have a jhipster (spring boot and angular) project implementing oauth2 protocol with Keycloak. I managed to get the application to redirect to keycloak for authentication. I am quite confused as to where the access token is in the response after sign in and where is it stored after redirecting back to my site? I tried using chrome inspect to view the network but I can't seem to find the access token.

Below is a link I used to setup oauth2 for my project: https://www.jhipster.tech/security/

URL when login is clicked: http://localhost:8080/oauth2/authorization/oidc

2 Answers

Thanks for all the reply. Managed to get the tokens using the following:

SecurityContext securityContext = SecurityContextHolder.getContext();
    OAuth2AuthenticationToken oauth2Token = (OAuth2AuthenticationToken) 
securityContext.getAuthentication();

OAuth2AuthorizedClient client = clientService
            .loadAuthorizedClient(oauth2Token.getAuthorizedClientRegistrationId(), 
oauth2Token.getName());

refreshToken = client.getRefreshToken().getTokenValue();

With OAuth2, the authentication is stateful which means that you have a cookie (JSESSIONID) for the Spring session.

You can get more information by inspecting the context using SecurityContextHolder.getContext().getAuthentication() in the backend.

Related