토큰받기까지 성공
This commit is contained in:
0
prd/gradlew
vendored
Normal file → Executable file
0
prd/gradlew
vendored
Normal file → Executable file
@@ -26,7 +26,9 @@ public class SecurityConfig {
|
||||
};
|
||||
cors.configurationSource(configurationSource);
|
||||
})
|
||||
.csrf(AbstractHttpConfigurer::disable); //대체 언제 이런 문법이 생겼냐;
|
||||
.csrf(AbstractHttpConfigurer::disable) //대체 언제 이런 문법이 생겼냐;
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.anyRequest().permitAll()); //외부 요청은 필터가 다 거르는 형태였기때문에 허용 해줘야함
|
||||
return http.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package site.ocr.prd.contorllers;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
@@ -7,10 +10,6 @@ import site.ocr.prd.dto.LoginRequestDto;
|
||||
import site.ocr.prd.dto.LoginResponseDto;
|
||||
import site.ocr.prd.services.LoginService;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
|
||||
|
||||
@RestController
|
||||
@@ -19,22 +18,21 @@ public class LoginController {
|
||||
//service 선언
|
||||
private LoginService loginService = new LoginService(WebClient.builder());
|
||||
|
||||
@GetMapping("login/oauth-kakao-authorize") //kakao에서 get으로 요청 보냄
|
||||
public void kakaoLoginRequestDto(HttpServletRequest request) {
|
||||
String accessToken = request.getParameter("code");
|
||||
@GetMapping("/oauth/oauth-kakao-authorize") //kakao에서 get으로 요청 보냄
|
||||
public void kakaoLoginRequestDto(HttpServletRequest redirectRespn) {
|
||||
String accessToken = redirectRespn.getParameter("code");
|
||||
System.out.println(accessToken);
|
||||
LoginRequestDto requestDTO = new LoginRequestDto();
|
||||
requestDTO.setGrant_type("authorization_code");
|
||||
requestDTO.setClient_id("a1d6afef2d4508a10a498b7069f67496");
|
||||
requestDTO.setRedirect_uri("http://localhost:9001/login/oauth-kakao-authorize");
|
||||
requestDTO.setRedirect_uri("http://localhost:9001/oauth/oauth-kakao-authorize");
|
||||
requestDTO.setCode(accessToken);
|
||||
|
||||
LoginResponseDto result = loginService.getToken(requestDTO);
|
||||
System.out.println(result.toString());
|
||||
|
||||
System.out.println("결과 :: " + result.toString());
|
||||
}
|
||||
|
||||
@PostMapping("login/oauth-kakao-token")
|
||||
@GetMapping("login/oauth-kakao-token")
|
||||
public String kakaoLoginResponseDto(@RequestBody LoginResponseDto response) {
|
||||
//TODO: process POST request
|
||||
System.out.println("response :: ");
|
||||
|
||||
@@ -17,5 +17,6 @@ public class LoginRequestDto {
|
||||
String client_id; //앱 REST API 키
|
||||
@JsonProperty("redirect_uri")
|
||||
String redirect_uri; //인가코드가 리다이렉트된 uri
|
||||
@JsonProperty("code")
|
||||
String code; //인가코드 요청으로 얻은 인가코드
|
||||
}
|
||||
@@ -19,19 +19,18 @@ public class LoginService {
|
||||
}
|
||||
|
||||
public LoginResponseDto getToken(LoginRequestDto request) {
|
||||
System.out.println("kakao auth code = {}" + request.getCode());
|
||||
|
||||
LoginResponseDto result = webClient.post()
|
||||
.uri("https://kauth.kakao.com/oauth/token")
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=utf-8")
|
||||
.body(BodyInserters.fromFormData("grant_type", "authorization_code")
|
||||
.with("client_id", "a1d6afef2d4508a10a498b7069f67496")
|
||||
.with("redirect_uri", "http://localhost:9001/login/oauth-kakao-authorize")
|
||||
.with("redirect_uri", "http://localhost:9001/oauth/oauth-kakao-authorize")
|
||||
.with("code", request.getCode()))
|
||||
.retrieve()
|
||||
.bodyToMono(LoginResponseDto.class)
|
||||
//.bodyToMono(String.class)
|
||||
.block();
|
||||
//System.out.println("요청 ::: " + request.toString());
|
||||
//System.out.println("성공여부 ::: " + "result");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,3 +8,4 @@ server:
|
||||
logging:
|
||||
level:
|
||||
root: debug
|
||||
org.springframework.security: DEBUG
|
||||
|
||||
Reference in New Issue
Block a user