Skip to content

Commit

Permalink
Merge pull request #63 from NewsFit-jolp/fix/oauth-redirect
Browse files Browse the repository at this point in the history
Fix/oauth redirect
  • Loading branch information
k000927 authored Oct 30, 2024
2 parents fbf556b + 845ca22 commit 214831a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ public class MemberController {

@GetMapping("/oauth/kakao")
public SuccessResponse<TokenResponse> kakaoLogin(@Parameter(name = "code", description = "카카오 인증서버에서 받은 인증 코드", required = true)
@RequestParam String code) throws JsonProcessingException {
@RequestParam String code,
@Parameter(name = "redirect_uri", description = "리다이렉트 uri", required = true)
@RequestParam String redirect_uri) throws JsonProcessingException {

String accessToken = kakaoMemberService.getAccessToken(code);
String accessToken = kakaoMemberService.getAccessToken(code, redirect_uri);

Pair<TokenResponse, Boolean> pair = kakaoMemberService.kakaoLogin(accessToken);

Expand All @@ -62,7 +64,6 @@ public SuccessResponse<TokenResponse> kakaoLogin(@Parameter(name = "code", descr
} else {
return SuccessResponse.success(pair.getLeft());
}

}

@Operation(summary = "구글 인증 서버를 통한 로그인",
Expand All @@ -85,9 +86,10 @@ public SuccessResponse<TokenResponse> kakaoLogin(@Parameter(name = "code", descr

@GetMapping("/oauth/google")
public SuccessResponse<TokenResponse> googleLogin(@Parameter(name = "code", description = "구글 인증서버에서 받은 인증 코드", required = true)
@RequestParam String code) throws JsonProcessingException {

String accessToken = googleMemberService.getAccessToken(code);
@RequestParam String code,
@Parameter(name = "redirect_uri", description = "리다이렉트 uri", required = true)
@RequestParam String redirect_uri) throws JsonProcessingException {
String accessToken = googleMemberService.getAccessToken(code, redirect_uri);
Pair<TokenResponse, Boolean> pair = googleMemberService.googleLogin(accessToken);

if (pair.getRight()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ public class GoogleMemberService {
private String clientId;
@Value("${spring.security.oauth2.client.registration.google.client-secret}")
private String clientSecret;
@Value("${spring.security.oauth2.client.registration.google.redirect-uri}")
private String googleRedirectUri;

// 카카오 엑세스 토큰 발급
public String getAccessToken(String code) throws JsonProcessingException {
public String getAccessToken(String code, String redirectUri) throws JsonProcessingException {
String reqUrl = "https://oauth2.googleapis.com/token";

RestTemplate rt = new RestTemplate();
Expand All @@ -51,7 +49,7 @@ public String getAccessToken(String code) throws JsonProcessingException {
params.add("code", code);
params.add("client_id", clientId);
params.add("client_secret", clientSecret);
params.add("redirect_uri", googleRedirectUri);
params.add("redirect_uri", redirectUri);
params.add("grant_type", "authorization_code");

//http 바디(params)와 http 헤더(headers)를 가진 엔티티
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public class KakaoMemberService {

@Value("${spring.security.oauth2.client.registration.kakao.client-id}")
private String clientId;
@Value("${spring.security.oauth2.client.registration.kakao.client-secret}")
private String clientSecret;
@Value("${spring.security.oauth2.client.registration.kakao.redirect-uri}")
private String kakaoRedirectUri;

public Pair<TokenResponse, Boolean> kakaoLogin(String accessToken) throws JsonProcessingException {

Expand All @@ -49,7 +45,7 @@ public Pair<TokenResponse, Boolean> kakaoLogin(String accessToken) throws JsonPr


// 카카오 엑세스 토큰 발급
public String getAccessToken(String code) throws JsonProcessingException {
public String getAccessToken(String code, String redirectUri) throws JsonProcessingException {
String reqUrl = "https://kauth.kakao.com/oauth/token";

RestTemplate rt = new RestTemplate();
Expand All @@ -62,7 +58,7 @@ public String getAccessToken(String code) throws JsonProcessingException {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("grant_type", "authorization_code");
params.add("client_id", clientId);
params.add("redirect_uri", kakaoRedirectUri);
params.add("redirect_uri", redirectUri);
params.add("code", code);

//http 바디(params)와 http 헤더(headers)를 가진 엔티티
Expand Down

0 comments on commit 214831a

Please sign in to comment.