I'm working with oauth2login in spring security. The redirection to the provider (facebook or google) was made with success but I'm getting the error : org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser cannot be cast to model.UserPrincipal, in this line of code
UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal();
My UserPrincipal class is like this :
public class UserPrincipal implements OAuth2User, OidcUser, UserDetails {
private Long id;
private String email;
private String password;
private Collection<? extends GrantedAuthority> authorities;
private Map<String, Object> attributes;
private Map<String, Object> claims;
private OidcUserInfo oidcUserInfo;
private OidcIdToken oidcIdToken;
...
}
How can I resolve this issue please?
Have You Override methods in UserPrincipal class that implements OAuth2User, UserDetails.