Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: redirectUri 수정 #37

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,33 @@ 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 +124,13 @@ 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
Loading