sjohnr / springone-2021

Spring Security 5.5 From Taxi To Takeoff
https://springone.io/2021/sessions/spring-security-5-5
68 stars 27 forks source link

Access OIDC token information from Angular SPA #10

Closed godfriedmeesters closed 2 years ago

godfriedmeesters commented 2 years ago

What would be the best way to access the information encoded in the OpenID token from the Angular SPA side? For example, I want to display the user's name in the SPA after login.

As far as I understand no tokens at all are available directly to the SPA.

marcusdacoregio commented 2 years ago

You can have an endpoint in your BFF that just returns whatever is in the currently Authentication object, something like this:

@GetMapping("/user/me")
public Authentication getCurrentAuthentication(Authentication authentication) {
    return authentication;
}