0

In configure() I have:

       ...
           .oauth2Login()
                .userInfoEndpoint()
                .oidcUserService(oidcUserService);

My CustomIodcUserService class:

@Service
public class CustomOidcUserService extends OidcUserService {

@Autowired
private UserRepository userRepository;

@Override
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
    OidcUser oidcUser = super.loadUser(userRequest);
    Map attributes = oidcUser.getAttributes();
    GoogleOAuth2UserInfo userInfo = new GoogleOAuth2UserInfo(attributes);
    updateUser(userInfo);
    return oidcUser;
}

private void updateUser(GoogleOAuth2UserInfo userInfo) {
    User user = userRepository.findByEmail(userInfo.getEmail()).get();
    if(user == null) {
        user = new User();
    }
    user.setEmail(userInfo.getEmail());
    user.setName(userInfo.getName());

    System.out.println(userRepository.save(user));
}

}

But methods of this class are never called Has anyone met this or how can I solve this or get UserInfo differently?

Dmytro
  • 139
  • 1
  • 10

1 Answers1

0

https://www.callicoder.com/spring-boot-security-oauth2-social-login-part-2/

This article describes how to do this, only there they used

userInfoEndpoint ()
       .userService (customOAuth2UserService)
Dmytro
  • 139
  • 1
  • 10