-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add Kakao Oauth2 and refactor some for #3
- Loading branch information
Showing
35 changed files
with
276 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/me/study/mylog/auth/oauth/GoogleOAuth2UserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.study.mylog.auth.oauth; | ||
|
||
import me.study.mylog.users.domain.AuthProviderType; | ||
import java.util.Map; | ||
|
||
public class GoogleOAuth2UserInfo extends OAuth2UserInfo { | ||
|
||
private static final AuthProviderType authProviderType = AuthProviderType.GOOGLE; | ||
|
||
public GoogleOAuth2UserInfo(Map<String, Object> attributes) { | ||
super(attributes); | ||
} | ||
|
||
@Override | ||
public AuthProviderType getProviderType() { | ||
return authProviderType; | ||
} | ||
@Override | ||
public String getId() { | ||
return (String) attributes.get("sub"); | ||
} | ||
@Override | ||
public String getName() { | ||
return (String) attributes.get("name"); | ||
} | ||
@Override | ||
public String getEmail() { | ||
return (String) attributes.get("email"); | ||
} | ||
@Override | ||
public String getImageUrl() { | ||
return (String) attributes.get("picture"); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/me/study/mylog/auth/oauth/KakaoOAuth2UserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package me.study.mylog.auth.oauth; | ||
|
||
import me.study.mylog.users.domain.AuthProviderType; | ||
import java.util.Map; | ||
|
||
public class KakaoOAuth2UserInfo extends OAuth2UserInfo { | ||
|
||
private static final AuthProviderType authProviderType = AuthProviderType.KAKAO; | ||
private Map<String, Object> attributesAccount; | ||
private Map<String, Object> attributesProfile; | ||
|
||
public KakaoOAuth2UserInfo(Map<String, Object> attributes) { | ||
super(attributes); | ||
// 카카오 응답값 기준 파싱 | ||
this.attributesAccount = (Map<String, Object>) attributes.get("kakao_account"); | ||
this.attributesProfile = (Map<String, Object>) attributesAccount.get("profile"); | ||
} | ||
|
||
@Override | ||
public AuthProviderType getProviderType() { | ||
return authProviderType; | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return attributes.get("id").toString(); | ||
} | ||
|
||
@Override | ||
public String getEmail() { | ||
if (attributesAccount == null) { | ||
return null; | ||
} | ||
return (String) attributesAccount.get("email"); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
if (attributesProfile == null) { | ||
return null; | ||
} | ||
return (String) attributesProfile.get("nickname"); | ||
} | ||
|
||
@Override | ||
public String getImageUrl() { | ||
if (attributesProfile == null) { | ||
return null; | ||
} | ||
return (String) attributesProfile.get("profile_image"); | ||
} | ||
|
||
} |
88 changes: 35 additions & 53 deletions
88
src/main/java/me/study/mylog/auth/oauth/OAuth2UserInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,44 @@ | ||
package me.study.mylog.auth.oauth; | ||
|
||
import lombok.Builder; | ||
import me.study.mylog.users.domain.AuthProviderType; | ||
import me.study.mylog.users.domain.RoleType; | ||
import me.study.mylog.users.domain.User; | ||
import me.study.mylog.users.domain.UserStatus; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
public class OAuth2UserInfo { | ||
|
||
Map<String, Object> attributes; | ||
String nameAttributeKey; | ||
String id; | ||
String name; | ||
String email; | ||
String imageUrl; | ||
|
||
public OAuth2UserInfo(Map<String, Object> attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
public Map<String, Object> getAttributes () { return attributes; } | ||
|
||
public String getId () { return id; } | ||
|
||
public String getName() { return name; } | ||
|
||
public String getEmail() { return email; } | ||
|
||
public String getImageUrl() { return imageUrl; } | ||
|
||
@Builder | ||
public OAuth2UserInfo(Map<String, Object> attributes, String nameAttributeKey, String name, | ||
String email, String imageUrl) { | ||
this.attributes = attributes; | ||
this.nameAttributeKey= nameAttributeKey; | ||
this.name = name; | ||
this.email = email; | ||
this.imageUrl = imageUrl; | ||
} | ||
|
||
public User toEntity() { | ||
return User.builder() | ||
.status(UserStatus.Normal) | ||
.name(name+ UUID.randomUUID()) // TODO 해당 속성은 유니크이므로, 선검증이 추가로 필요하다. | ||
.nickname(name) | ||
.email(email) | ||
.imageUrl(imageUrl) | ||
.role(RoleType.USER) | ||
.status(UserStatus.Normal) | ||
.build(); | ||
} | ||
|
||
// /* 구현체에 객체 생성 처리를 맡긴다. 팩토리 패턴이라고 볼 수 있나? */ | ||
// public abstract void createUserInfo(AuthProvider authProvider); | ||
// public OAuth2UserInfo(AuthProvider authProvider, Map<String, Object> attributes) { | ||
// this.attributes = attributes; | ||
// createUserInfo(authProvider); | ||
// } | ||
} | ||
public abstract class OAuth2UserInfo { | ||
Map<String, Object> attributes; | ||
|
||
public OAuth2UserInfo(Map<String, Object> attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
public Map<String, Object> getAttributes() { | ||
return attributes; | ||
} | ||
|
||
public abstract AuthProviderType getProviderType(); | ||
|
||
public abstract String getId(); | ||
|
||
public abstract String getName(); | ||
|
||
public abstract String getEmail(); | ||
|
||
public abstract String getImageUrl(); | ||
|
||
public User toEntity(String tempName) { | ||
|
||
return User.builder() | ||
.name(tempName) // TODO 해당 속성은 유니크이므로, 선검증이 추가로 필요하다. | ||
.nickname(getName()) | ||
.email(getEmail()) | ||
.imageUrl(getImageUrl()) | ||
.role(RoleType.USER) | ||
.status(UserStatus.Normal) | ||
.authProviderType(getProviderType()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../auth/handler/JwtAccessDeniedHandler.java → ...auth/security/JwtAccessDeniedHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../handler/JwtAuthenticationEntryPoint.java → ...security/JwtAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.