-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Kakao 로그인 기능 구현 * feat: redirect-uri 변경 * feat: client id 업데이트 * test: 테스트 위치 변경 * feat: 로그인 생성 후 행사 생성 페이지로 리다이렉트 * feat: 카카오 로그인 예외 처리 * refactor: 카카오 로그인 방식 변경 * style: 메소드 이름 변경
- Loading branch information
Showing
81 changed files
with
1,356 additions
and
793 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
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
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
46 changes: 46 additions & 0 deletions
46
server/src/main/java/server/haengdong/application/KakaoClient.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,46 @@ | ||
package server.haengdong.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestClient; | ||
import server.haengdong.application.response.KakaoTokenResponse; | ||
import server.haengdong.config.KakaoProperties; | ||
import server.haengdong.exception.HaengdongErrorCode; | ||
import server.haengdong.exception.HaengdongException; | ||
|
||
@RequiredArgsConstructor | ||
@EnableConfigurationProperties(KakaoProperties.class) | ||
@Component | ||
public class KakaoClient { | ||
|
||
private final KakaoProperties kakaoProperties; | ||
private final RestClient restClient; | ||
|
||
public KakaoTokenResponse join(String code, String redirectUri) { | ||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); | ||
params.add("grant_type", "authorization_code"); | ||
params.add("client_id", kakaoProperties.clientId()); | ||
params.add("redirect_uri", redirectUri); | ||
params.add("code", code); | ||
|
||
try { | ||
return restClient.post() | ||
.uri(kakaoProperties.baseUri() + kakaoProperties.tokenRequestUri()) | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) | ||
.body(params) | ||
.retrieve() | ||
.body(KakaoTokenResponse.class); | ||
} catch (Exception e) { | ||
throw new HaengdongException(HaengdongErrorCode.KAKAO_LOGIN_FAIL, e); | ||
} | ||
} | ||
|
||
public String getClientId() { | ||
return kakaoProperties.clientId(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
server/src/main/java/server/haengdong/application/KakaoUserService.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,32 @@ | ||
package server.haengdong.application; | ||
|
||
import com.auth0.jwt.JWT; | ||
import com.auth0.jwt.interfaces.DecodedJWT; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import server.haengdong.application.response.KakaoTokenResponse; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class KakaoUserService { | ||
|
||
private static final String NICKNAME_KEY = "nickname"; | ||
|
||
private final UserService userService; | ||
private final KakaoClient kakaoClient; | ||
|
||
public Long joinByKakao(String code, String redirectUri) { | ||
KakaoTokenResponse kakaoToken = kakaoClient.join(code, redirectUri); | ||
String idToken = kakaoToken.idToken(); | ||
DecodedJWT decodedJWT = JWT.decode(idToken); | ||
|
||
String memberNumber = decodedJWT.getSubject(); | ||
String nickname = decodedJWT.getClaim(NICKNAME_KEY).asString(); | ||
|
||
return userService.join(memberNumber, nickname); | ||
} | ||
|
||
public String getClientId() { | ||
return kakaoClient.getClientId(); | ||
} | ||
} |
Oops, something went wrong.