Accessing the Authenticated OAuth2 User
Learn how to read the logged-in user's profile and attributes from an OAuth2 login in Spring Security using OAuth2User and OidcUser.
After Login, Then What?
Once a user signs in through an OAuth2 provider, your app needs their profile: name, email, and provider id. Spring Security exposes this through a principal object you can inject anywhere.
The OAuth2User Principal
For plain OAuth2 logins, the authenticated principal is an OAuth2User. It holds the provider's attributes as a map plus the granted authorities.
public interface OAuth2User {
Map<String, Object> getAttributes();
Collection<? extends GrantedAuthority> getAuthorities();
String getName();
}All lessons in this course
- OAuth2 Client Setup
- Social Login Integration
- Custom OAuth2 Success Handler
- Accessing the Authenticated OAuth2 User