Skip to content

Commit

Permalink
#1 Feat : 네이버 로그인 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaeYoon committed Jul 18, 2023
1 parent 365b97c commit a7c6ae9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/kr/org/booklog/config/auth/dto/OAuthAttributes.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ public OAuthAttributes(Map<String, Object> attributes, String nameAttributeKey,
}

public static OAuthAttributes of(String registrationId, String userNameAttributeName, Map<String, Object> attributes) {
if ("naver".equals(registrationId)) {
return ofNaver("id", attributes);
}
return ofGoogle(userNameAttributeName, attributes);
}

private static OAuthAttributes ofNaver(String userNameAttributeName, Map<String, Object> attributes) {
Map<String, Object> response = (Map<String, Object>) attributes.get("response");
return OAuthAttributes.builder()
.name((String) response.get("name"))
.email((String) response.get("email"))
.attributes(response)
.nameAttributeKey(userNameAttributeName)
.build();
}

private static OAuthAttributes ofGoogle(String userNameAttributeName, Map<String, Object> attributes) {
return OAuthAttributes.builder()
.name((String) attributes.get("name"))
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{{/userName}}
{{^userName}}
<a href="/oauth2/authorization/google" class="btn btn-success active" role="button">Google Login</a>
<a href="/oauth2/authorization/naver" class="btn btn-secondary active" role="button">Naver Login</a>
{{/userName}}
</div>
</div>
Expand Down

0 comments on commit a7c6ae9

Please sign in to comment.