로그인 성공
This commit is contained in:
@@ -11,9 +11,6 @@ public class WebClientConfig {
|
|||||||
@Bean
|
@Bean
|
||||||
public WebClient webClient() {
|
public WebClient webClient() {
|
||||||
return WebClient.builder()
|
return WebClient.builder()
|
||||||
.defaultHeaders(httpHeaders -> {
|
|
||||||
httpHeaders.setContentType(MediaType.valueOf("application/x-www-form-urlencoded;charset=utf-8"));
|
|
||||||
})
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ public class LoginController {
|
|||||||
String accessToken = request.getParameter("code");
|
String accessToken = request.getParameter("code");
|
||||||
System.out.println(accessToken);
|
System.out.println(accessToken);
|
||||||
LoginRequestDto requestDTO = new LoginRequestDto();
|
LoginRequestDto requestDTO = new LoginRequestDto();
|
||||||
requestDTO.setGrantType("authorization_code");
|
requestDTO.setGrant_type("authorization_code");
|
||||||
requestDTO.setClientId("a1d6afef2d4508a10a498b7069f67496");
|
requestDTO.setClient_id("a1d6afef2d4508a10a498b7069f67496");
|
||||||
requestDTO.setRedirectUri("http://localhost:9001/login/oauth-kakao-authorize");
|
requestDTO.setRedirect_uri("http://localhost:9001/login/oauth-kakao-authorize");
|
||||||
requestDTO.setCode(accessToken);
|
requestDTO.setCode(accessToken);
|
||||||
|
|
||||||
loginService.getToken(requestDTO);
|
LoginResponseDto result = loginService.getToken(requestDTO);
|
||||||
|
System.out.println(result.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +38,9 @@ public class LoginController {
|
|||||||
public String kakaoLoginResponseDto(@RequestBody LoginResponseDto response) {
|
public String kakaoLoginResponseDto(@RequestBody LoginResponseDto response) {
|
||||||
//TODO: process POST request
|
//TODO: process POST request
|
||||||
System.out.println("response :: ");
|
System.out.println("response :: ");
|
||||||
System.out.println(response.getAccessToken());
|
System.out.println(response.getAccess_token());
|
||||||
|
|
||||||
return response.getAccessToken();
|
return response.getAccess_token();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ import lombok.ToString;
|
|||||||
public class LoginRequestDto {
|
public class LoginRequestDto {
|
||||||
|
|
||||||
@JsonProperty("grant_type")
|
@JsonProperty("grant_type")
|
||||||
String grantType; //authorization_code
|
String grant_type; //authorization_code
|
||||||
@JsonProperty("client_id")
|
@JsonProperty("client_id")
|
||||||
String clientId; //앱 REST API 키
|
String client_id; //앱 REST API 키
|
||||||
@JsonProperty("redirect_uri")
|
@JsonProperty("redirect_uri")
|
||||||
String redirectUri; //인가코드가 리다이렉트된 uri
|
String redirect_uri; //인가코드가 리다이렉트된 uri
|
||||||
String code; //인가코드 요청으로 얻은 인가코드
|
String code; //인가코드 요청으로 얻은 인가코드
|
||||||
}
|
}
|
||||||
@@ -12,16 +12,16 @@ import lombok.ToString;
|
|||||||
public class LoginResponseDto {
|
public class LoginResponseDto {
|
||||||
|
|
||||||
@JsonProperty("token_type")
|
@JsonProperty("token_type")
|
||||||
String tokenType; //토큰타입, bearer 고정
|
String token_type; //토큰타입, bearer 고정
|
||||||
@JsonProperty("access_token")
|
@JsonProperty("access_token")
|
||||||
String accessToken; //사용자 엑세스 토큰 값
|
String access_token; //사용자 엑세스 토큰 값
|
||||||
@JsonProperty("id_token")
|
@JsonProperty("id_token")
|
||||||
String idToken; //ID 토큰값, openID connect가 활성화된 경우만 발급
|
String id_token; //ID 토큰값, openID connect가 활성화된 경우만 발급
|
||||||
@JsonProperty("expires_in")
|
@JsonProperty("expires_in")
|
||||||
Integer expiresIn; //엑세스토큰과 id토큰의 만료시간(초))
|
Integer expires_in; //엑세스토큰과 id토큰의 만료시간(초))
|
||||||
@JsonProperty("refresh_token")
|
@JsonProperty("refresh_token")
|
||||||
String refreshToken; //사용자 리프레시 토큰 값
|
String refresh_token; //사용자 리프레시 토큰 값
|
||||||
@JsonProperty("refresh_token_expires_in")
|
@JsonProperty("refresh_token_expires_in")
|
||||||
Integer refreshTokenExpiresIn; //리프레시 토큰 만료 시간(초)
|
Integer refresh_token_expires_in; //리프레시 토큰 만료 시간(초)
|
||||||
String scope; //인증된 사용자의 정보조회 범위, 여러개일 경우 공백으로 구분
|
String scope; //인증된 사용자의 정보조회 범위, 여러개일 경우 공백으로 구분
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package site.ocr.prd.services;
|
package site.ocr.prd.services;
|
||||||
|
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.reactive.function.BodyInserters;
|
||||||
import org.springframework.web.reactive.function.client.WebClient;
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
import site.ocr.prd.dto.LoginRequestDto;
|
import site.ocr.prd.dto.LoginRequestDto;
|
||||||
import site.ocr.prd.dto.LoginResponseDto;
|
import site.ocr.prd.dto.LoginResponseDto;
|
||||||
@@ -16,17 +18,20 @@ public class LoginService {
|
|||||||
this.webClient = builder.build();
|
this.webClient = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken(LoginRequestDto request) {
|
public LoginResponseDto getToken(LoginRequestDto request) {
|
||||||
|
LoginResponseDto result = webClient.post()
|
||||||
System.out.println("요청 ::: " + request.toString());
|
.uri("https://kauth.kakao.com/oauth/token")
|
||||||
String result = webClient.post()
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||||
.uri("https://kauth.kakao.com/oauth/token/")
|
.body(BodyInserters.fromFormData("grant_type", "authorization_code")
|
||||||
.bodyValue(request)
|
.with("client_id", "a1d6afef2d4508a10a498b7069f67496")
|
||||||
.retrieve()
|
.with("redirect_uri", "http://localhost:9001/login/oauth-kakao-authorize")
|
||||||
//.bodyToMono(LoginResponseDto.class)
|
.with("code", request.getCode()))
|
||||||
.bodyToMono(String.class)
|
.retrieve()
|
||||||
.block();
|
.bodyToMono(LoginResponseDto.class)
|
||||||
System.out.println("성공여부 ::: " + result);
|
//.bodyToMono(String.class)
|
||||||
|
.block();
|
||||||
|
//System.out.println("요청 ::: " + request.toString());
|
||||||
|
//System.out.println("성공여부 ::: " + "result");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user