Skip to content

Commit

Permalink
feat: oAuth에 id, thumbnail_image,nick_name email받아오게 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ktj1997 committed Jan 22, 2024
1 parent 8ca7c6e commit fe1a809
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.imlinker.coreapi.configuration;

import com.imlinker.coreapi.core.auth.jwt.JwtTokenProperties;
import com.imlinker.coreapi.core.auth.jwt.TokenProperties;
import com.imlinker.coreapi.core.auth.oauth2.*;
import com.imlinker.coreapi.core.auth.security.jwt.JwtTokenProperties;
import com.imlinker.coreapi.core.auth.security.jwt.TokenProperties;
import com.imlinker.coreapi.core.auth.security.oauth2.*;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.imlinker.coreapi.core.auth.controller;

import com.imlinker.coreapi.support.response.ApiResponse;
import com.imlinker.enums.OperationResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthController {

@PostMapping
public ApiResponse<OperationResult> signUp() {
return ApiResponse.success(OperationResult.SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.imlinker.coreapi.core.auth.controller.request;

import com.imlinker.domain.tag.Tag;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record SignUpRequest(
@Schema(description = "oAuth 식별자") String oAuthId,
@Schema(description = "이름") String name,
@Schema(description = "프로필 이미지 URL") String profileImgUrl,
@Schema(description = "핸드폰 번호") String phoneNumber,
@Schema(description = "관심사") List<Tag> tags) {}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.jwt;
package com.imlinker.coreapi.core.auth.security.jwt;

import com.imlinker.coreapi.support.exception.FilterExceptionHandler;
import com.imlinker.error.ErrorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.jwt;
package com.imlinker.coreapi.core.auth.security.jwt;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.jwt;
package com.imlinker.coreapi.core.auth.security.jwt;

import com.imlinker.coreapi.support.exception.FilterExceptionHandler;
import com.imlinker.domain.common.Email;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.jwt;
package com.imlinker.coreapi.core.auth.security.jwt;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.jwt;
package com.imlinker.coreapi.core.auth.security.jwt;

public enum TokenType {
ACCESS_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.coreapi.support.exception.FilterExceptionHandler;
import com.imlinker.error.ErrorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.coreapi.support.exception.FilterExceptionHandler;
import com.imlinker.error.ErrorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.coreapi.core.auth.jwt.JwtTokenProvider;
import com.imlinker.coreapi.core.auth.jwt.TokenType;
import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor;
import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendorAttributeResolver;
import com.imlinker.coreapi.core.auth.security.jwt.JwtTokenProvider;
import com.imlinker.coreapi.core.auth.security.jwt.TokenType;
import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor;
import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendorAttributeResolver;
import com.imlinker.domain.common.Email;
import com.imlinker.domain.user.UserService;
import com.imlinker.error.ApplicationException;
import com.imlinker.error.ErrorType;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -64,11 +66,25 @@ public void onAuthenticationSuccess(
String refreshToken = jwtTokenProvider.generateToken(email, TokenType.REFRESH_TOKEN);

String redirectUri =
String.format(
"%s?accessToken=%s&refreshToken=%s", clientOriginHost, accessToken, refreshToken);
clientOriginHost
+ "?"
+ String.format(
"%s?accessToken=%s&refreshToken=%s", clientOriginHost, accessToken, refreshToken);
getRedirectStrategy().sendRedirect(request, response, redirectUri);
} else {
String redirectUri = String.format("%s?email=%s", clientOriginHost, email.getValue());
String oAuthId = resolver.getOAuthId(oAuth2User.getAttributes());
String nickname = resolver.getNickname(oAuth2User.getAttributes());
String profileImgUrl = resolver.getProfileImgUrl(oAuth2User.getAttributes());

String redirectUri =
clientOriginHost
+ "?"
+ URLEncoder.encode(
String.format(
"oAuthId=%s&nickname=%s&profileImgUrl=%s&email=%s",
oAuthId, nickname, profileImgUrl, email.getValue()),
StandardCharsets.UTF_8);

getRedirectStrategy().sendRedirect(request, response, redirectUri);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.localcache.LocalCache;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.error.ApplicationException;
import com.imlinker.error.ErrorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor;
import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.imlinker.coreapi.core.auth.oauth2;
package com.imlinker.coreapi.core.auth.security.oauth2;

import com.imlinker.coreapi.core.auth.oauth2.vendor.OAuthVendor;
import com.imlinker.coreapi.core.auth.security.oauth2.vendor.OAuthVendor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.client.userinfo.DefaultOAuth2UserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.imlinker.coreapi.core.auth.security.oauth2.vendor;

import com.imlinker.domain.common.Email;
import java.util.Map;
import org.springframework.stereotype.Component;

@Component
public class KakaoOAuthVendorAttributeResolver implements OAuthVendorAttributeResolver {
@Override
public OAuthVendor getVendor() {
return OAuthVendor.KAKAO;
}

@Override
public String getOAuthId(Map<String, Object> attributes) {
return attributes.get("id").toString();
}

@Override
public Email getEmail(Map<String, Object> attributes) {
Map<String, String> emailAttributes = (Map<String, String>) attributes.get("kakao_account");
return Email.of(emailAttributes.get("email"));
}

@Override
public String getProfileImgUrl(Map<String, Object> attributes) {
Map<String, String> emailAttributes = (Map<String, String>) attributes.get("properties");
return emailAttributes.get("thumbnail_image");
}

@Override
public String getNickname(Map<String, Object> attributes) {
Map<String, String> emailAttributes = (Map<String, String>) attributes.get("properties");
return emailAttributes.get("nickname");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.imlinker.coreapi.core.auth.oauth2.vendor;
package com.imlinker.coreapi.core.auth.security.oauth2.vendor;

import com.imlinker.error.ApplicationException;
import com.imlinker.error.ErrorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.imlinker.coreapi.core.auth.security.oauth2.vendor;

import com.imlinker.domain.common.Email;
import java.util.Map;

public interface OAuthVendorAttributeResolver {

OAuthVendor getVendor();

String getOAuthId(Map<String, Object> attributes);

Email getEmail(Map<String, Object> attributes);

String getProfileImgUrl(Map<String, Object> attributes);

String getNickname(Map<String, Object> attributes);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.imlinker.coreapi.core.my.request;

import com.imlinker.domain.tag.Tag;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record UpdateMyInfoRequest(
@Schema(description = "이름") String name,
@Schema(description = "프로필 이미지 URL") String profileImgUrl,
@Schema(description = "직업", nullable = true) String job,
@Schema(description = "소속", nullable = true) String association,
@Schema(description = "관심사") List<String> tags) {}
@Schema(description = "관심사") List<Tag> tags) {}
2 changes: 2 additions & 0 deletions core-api/src/main/resources/oauth/application-oauth-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ spring:
client-name: kakao
scope:
- account_email
- profile_nickname
- profile_image
provider:
kakao:
authorization-uri: https://kauth.kakao.com/oauth/authorize
Expand Down
2 changes: 2 additions & 0 deletions core-api/src/main/resources/oauth/application-oauth-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ spring:
client-name: kakao
scope:
- account_email
- profile_nickname
- profile_image
provider:
kakao:
authorization-uri: https://kauth.kakao.com/oauth/authorize
Expand Down

0 comments on commit fe1a809

Please sign in to comment.