Social Login - 코드 구현 - Model
ProviderUser
public interface ProviderUser {
String getId();
String getUsername();
String getPassword();
String getEmail();
String getProvider();
List<? extends GrantedAuthority> getAuthorities();
Map<String, Object> getAttributes();
}OAuth2ProviderUser
public abstract class OAuth2ProviderUser implements ProviderUser{
protected Map<String, Object> attributes;
protected OAuth2User oAuth2User;
protected ClientRegistration clientRegistration;
public OAuth2ProviderUser(Map<String, Object> attributes, OAuth2User oAuth2User, ClientRegistration clientRegistration) {
this.attributes = attributes;
this.oAuth2User = oAuth2User;
this.clientRegistration = clientRegistration;
}
@Override
public String getPassword() {
return UUID.randomUUID().toString().substring(0, 8);
}
@Override
public String getProvider() {
return clientRegistration.getRegistrationId();
}
@Override
public String getEmail() {
return (String) getAttributes().get("email");
}
@Override
public List<? extends GrantedAuthority> getAuthorities() {
return oAuth2User.getAuthorities()
.stream()
.map(authority -> new SimpleGrantedAuthority(authority.getAuthority()))
.toList();
}
@Override
public Map<String, Object> getAttributes() {
return attributes;
}
}GoogleUser
NaverUser
KeycloakUser
User
Last updated