Skip to content

Commit

Permalink
πŸ”₯ Remove[#10]: μ‚¬μš©ν•˜μ§€ μ•ŠλŠ” 둜직 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 22, 2024
1 parent a05670d commit 1d37dc3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 89 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.groom.swipo.domain.auth.dto.request;

public record AppleLoginRequest (
public record SocialLoginRequest(
String token
){
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import java.net.URI;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestClient;
import org.springframework.web.util.UriComponentsBuilder;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -27,7 +25,6 @@
@RequiredArgsConstructor
public class KakaoLoginService {

private static final String TOKEN_URL = "https://kauth.kakao.com/oauth/token";
private static final String USER_INFO_URL = "https://kapi.kakao.com/v2/user/me";

private final UserRepository userRepository;
Expand All @@ -36,19 +33,9 @@ public class KakaoLoginService {
private final RestClient restClient;
private final ObjectMapper objectMapper;

@Value("${oauth.kakao.client-id}")
private String clientId;

@Value("${oauth.kakao.client-secret}")
private String clientSecret;

@Value("${oauth.kakao.redirect-uri}")
private String redirectUri;

@Transactional
public SocialLoginResponse kakaoLogin(String code) {
public SocialLoginResponse kakaoLogin(String kakaoAccessToken) {
try {
String kakaoAccessToken = getKakaoAccessToken(code);
String[] userInfo = getKakaoUserInfo(kakaoAccessToken);

return userRepository.findByProviderAndProviderId(Provider.KAKAO, userInfo[0])
Expand All @@ -66,25 +53,6 @@ private SocialLoginResponse handleExistingUserLogin(User user) {
return SocialLoginResponse.of(user.getId(), accessToken, refreshToken);
}

private String getKakaoAccessToken(String code) throws JsonProcessingException {
String url = UriComponentsBuilder.fromHttpUrl(TOKEN_URL)
.queryParam("grant_type", "authorization_code")
.queryParam("client_id", clientId)
.queryParam("redirect_uri", redirectUri)
.queryParam("code", code)
.queryParam("client_secret", clientSecret)
.toUriString();

String response = restClient.post()
.uri(url)
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.retrieve()
.body(String.class);

JsonNode jsonNode = objectMapper.readTree(response);
return jsonNode.get("access_token").asText();
}

private String[] getKakaoUserInfo(String kakaoAccessToken) throws JsonProcessingException {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + kakaoAccessToken);
Expand All @@ -102,17 +70,4 @@ private String[] getKakaoUserInfo(String kakaoAccessToken) throws JsonProcessing

return new String[] {providerId, profileImageUrl};
}

@Transactional
public SocialLoginResponse kakaoLoginWithAccessToken(String kakaoAccessToken) {
try {
String[] userInfo = getKakaoUserInfo(kakaoAccessToken);

return userRepository.findByProviderAndProviderId(Provider.KAKAO, userInfo[0])
.map(this::handleExistingUserLogin)
.orElseGet(() -> SocialLoginResponse.of(userInfo[0], userInfo[1]));
} catch (JsonProcessingException e) {
throw new KakaoAuthException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.groom.swipo.domain.auth.dto.request.AppleLoginRequest;
import com.groom.swipo.domain.auth.dto.request.KakaoLoginRequest;
import com.groom.swipo.domain.auth.dto.request.SocialLoginRequest;
import com.groom.swipo.domain.auth.dto.request.TokenRefreshRequest;
import com.groom.swipo.domain.auth.dto.response.SocialLoginResponse;
import com.groom.swipo.domain.auth.dto.response.TokenRefreshResponse;
Expand Down Expand Up @@ -43,31 +42,10 @@ public class UserController {
private final AppleLoginService appleLoginService;
private final TokenRenewService tokenRenewService;

@PostMapping("/kakao/accessToken")
@Operation(
summary = "카카였 둜그인",
description = "카카였 μ•‘μ„ΈμŠ€ 토큰을 μ‚¬μš©ν•˜μ—¬ 둜그인 λ˜λŠ” νšŒμ›κ°€μž… ν•„μš” μ—¬λΆ€λ₯Ό νŒλ³„ν•©λ‹ˆλ‹€. DB에 μ‚¬μš©μž 정보가 있으면 둜그인 성곡, μ—†μœΌλ©΄ νšŒμ›κ°€μž… ν•„μš” μƒνƒœλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.",
security = {},
responses = {
@ApiResponse(responseCode = "200", description = "둜그인 성곡"),
@ApiResponse(responseCode = "400", description = "잘λͺ»λœ μš”μ²­"),
@ApiResponse(responseCode = "401", description = "μΈμ¦λ˜μ§€ μ•Šμ€ μš”μ²­"),
@ApiResponse(responseCode = "418", description = "νšŒμ›κ°€μž… ν•„μš”"),
@ApiResponse(responseCode = "500", description = "μ„œλ²„ 였λ₯˜")
}
)
public ResTemplate<SocialLoginResponse> kakaoLoginWithAccessToken(@RequestBody KakaoLoginRequest request) {
SocialLoginResponse data = kakaoLoginService.kakaoLoginWithAccessToken(request.kakaoCode());
if (data.userId() == null) {
return new ResTemplate<>(HttpStatus.I_AM_A_TEAPOT, "νšŒμ›κ°€μž… ν•„μš”", data);
}
return new ResTemplate<>(HttpStatus.OK, "둜그인 성곡", data);
}

@PostMapping("/kakao")
@Operation(
summary = "카카였 둜그인",
description = "카카였 인가 μ½”λ“œλ₯Ό μ‚¬μš©ν•˜μ—¬ 둜그인 λ˜λŠ” νšŒμ›κ°€μž… ν•„μš” μ—¬λΆ€λ₯Ό νŒλ³„ν•©λ‹ˆλ‹€. DB에 μ‚¬μš©μž 정보가 있으면 둜그인 성곡, μ—†μœΌλ©΄ νšŒμ›κ°€μž… ν•„μš” μƒνƒœλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.",
description = "카카였 μ•‘μ„ΈμŠ€ 토큰을 μ‚¬μš©ν•˜μ—¬ 둜그인 λ˜λŠ” νšŒμ›κ°€μž… ν•„μš” μ—¬λΆ€λ₯Ό νŒλ³„ν•©λ‹ˆλ‹€. DB에 μ‚¬μš©μž 정보가 있으면 둜그인 성곡, μ—†μœΌλ©΄ νšŒμ›κ°€μž… ν•„μš” μƒνƒœλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.",
security = {},
responses = {
@ApiResponse(responseCode = "200", description = "둜그인 성곡"),
Expand All @@ -77,8 +55,8 @@ public ResTemplate<SocialLoginResponse> kakaoLoginWithAccessToken(@RequestBody K
@ApiResponse(responseCode = "500", description = "μ„œλ²„ 였λ₯˜")
}
)
public ResTemplate<SocialLoginResponse> kakaoLogin(@RequestBody KakaoLoginRequest request) {
SocialLoginResponse data = kakaoLoginService.kakaoLogin(request.kakaoCode());
public ResTemplate<SocialLoginResponse> kakaoLogin(@RequestBody SocialLoginRequest request) {
SocialLoginResponse data = kakaoLoginService.kakaoLogin(request.token());
if (data.userId() == null) {
return new ResTemplate<>(HttpStatus.I_AM_A_TEAPOT, "νšŒμ›κ°€μž… ν•„μš”", data);
}
Expand All @@ -98,7 +76,7 @@ public ResTemplate<SocialLoginResponse> kakaoLogin(@RequestBody KakaoLoginReques
@ApiResponse(responseCode = "500", description = "μ„œλ²„ 였λ₯˜")
}
)
public ResTemplate<SocialLoginResponse> appleLogin(@RequestBody AppleLoginRequest request) {
public ResTemplate<SocialLoginResponse> appleLogin(@RequestBody SocialLoginRequest request) {
SocialLoginResponse data = appleLoginService.appleLogin(request.token());
if (data.userId() == null) {
return new ResTemplate<>(HttpStatus.I_AM_A_TEAPOT, "νšŒμ›κ°€μž… ν•„μš”", data);
Expand Down
9 changes: 0 additions & 9 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ jwt:
access-token: ${jwt.expire-time.access-token}
refresh-token: ${jwt.expire-time.refresh-token}

oauth:
kakao:
client-id: ${oauth.kakao.client-id}
client-secret: ${oauth.kakao.client-secret}
redirect-uri: ${oauth.kakao.redirect-uri}

apple:
public-key-url: ${oauth.apple.public-key-url}

imp:
api:
key: ${imp.api.key}
Expand Down

0 comments on commit 1d37dc3

Please sign in to comment.