Skip to content

Commit

Permalink
fix: 개발 배포 서버로 테스트 가능하도록 redirecturi 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-seong committed Jan 31, 2024
1 parent 590b5b7 commit 29de647
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
Expand All @@ -33,27 +34,31 @@ public class LoginController {
private final UserService userService;
private final JwtUtil jwtUtil;

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



/*
테스트용 API, CORS 때문에 직접 호출하지 않고 redirect
*/
@GetMapping("/oauth2/authorize/kakao")
public String login(){
String redirectUri = UriComponentsBuilder.fromUriString("https://kauth.kakao.com/oauth/authorize")
String toRedirectUri = UriComponentsBuilder.fromUriString("https://kauth.kakao.com/oauth/authorize")
.queryParam("response_type", "code")
.queryParam("client_id", "32c0787d1b1e9fcabcc24af247903ba8")
.queryParam("redirect_uri", "http://localhost:8080/oauth2/login/kakao")
.queryParam("redirect_uri", redirectUri)
.toUriString();
return "redirect:" + redirectUri;
return "redirect:" + toRedirectUri;
}
/*
테스트용 API
*/
@GetMapping("/oauth2/login/kakao")
public ResponseEntity<String> getAccessToken(@RequestParam(name = "code") String code){
TokenResponse tokenResponse = kakaoLoginService.getAccessTokenByCode(code);
return ResponseEntity.ok("http://localhost:8080/oauth2/kakao/token/validate?accessToken="+ tokenResponse.getAccessToken());
return ResponseEntity.ok("accessToken="+ tokenResponse.getAccessToken() +
"idToken=" + tokenResponse.getIdToken());
}
/*
1. ID 토큰 유효성 검증
Expand Down Expand Up @@ -117,6 +122,12 @@ public ApiResponse<?> validateAppleToken(HttpServletResponse response, @RequestB
response.addHeader("Refresh-Token", token.getRefreshToken());
return ApiResponse.onSuccess(UserConverter.toLoginDTO(user));
}

@GetMapping("/token/validate")
public ApiResponse<String> validateServerToken(@RequestParam(name = "code") String code){
TokenResponse tokenResponse = kakaoLoginService.getAccessTokenByCode(code);
return ApiResponse.onSuccess(null);
}
/*
테스트용 API
*/
Expand Down

0 comments on commit 29de647

Please sign in to comment.