|
@@ -20,12 +20,14 @@ public class OAuthController {
|
|
|
|
|
|
// http://127.0.0.1:8080/api/oauth2/authorize?client_id=clientid&redirect_uri=http://127.0.0.1:8080/api/oauth2/redirect&scope=scope&response_type=code&state=state
|
|
|
@RequestMapping(value = "/api/oauth2/authorize", method = RequestMethod.GET)
|
|
|
- public @ResponseBody ModelAndView Authorize(@RequestHeader HttpHeaders headers,
|
|
|
+ public ModelAndView Authorize(@RequestHeader HttpHeaders headers,
|
|
|
@RequestParam(value = "response_type", required = true) String responseType,
|
|
|
@RequestParam(value = "client_id", required = true) String clientId,
|
|
|
@RequestParam(value = "state", required = true) String state, @RequestParam(value = "scope") String scope,
|
|
|
@RequestParam(value = "redirect_uri", required = true) String redirectUri, HttpSession httpSession) {
|
|
|
|
|
|
+ logger.info("/api/oauth2/authorize");
|
|
|
+
|
|
|
ModelAndView mav = new ModelAndView();
|
|
|
|
|
|
mav.setViewName("/view/authorize.html");
|
|
@@ -33,12 +35,15 @@ public class OAuthController {
|
|
|
httpSession.setAttribute("redirectUri", redirectUri);
|
|
|
httpSession.setAttribute("state", state);
|
|
|
|
|
|
+ logger.info(httpSession.toString());
|
|
|
return mav;
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/api/oauth2/auth", method = RequestMethod.GET)
|
|
|
- public @ResponseBody RedirectView Redirect(HttpSession httpSession) {
|
|
|
+ public @ResponseBody RedirectView SendCode(HttpSession httpSession) {
|
|
|
+ logger.info("/api/oauth2/auth");
|
|
|
|
|
|
+ // authorize.html에서 submit 버튼 눌러서 넘어오는 페이지 redirectUrl로 리다이렉트 (코드를 전송 하는 역할)
|
|
|
// 웹뷰에서 사용자의 정보를 입력받아서 넘어와야함
|
|
|
// 사용자 정보를 단지서버에 전송해 사용자 확인하는 절차필요
|
|
|
|
|
@@ -53,36 +58,37 @@ public class OAuthController {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/api/oauth2/token", method = RequestMethod.GET)
|
|
|
- public @ResponseBody RedirectView Token(HttpSession httpSession) {
|
|
|
-
|
|
|
+ // ((Test)) Redirect Destination
|
|
|
+ // 여기는 리다이렉트 받는 URl임 테스트용. Client를 대신함.
|
|
|
+ @RequestMapping(value = "/api/oauth2/redirect", method = RequestMethod.GET, produces = "application/json")
|
|
|
+ public @ResponseBody RedirectView RedirectTester(HttpSession httpSession,
|
|
|
+ @RequestParam(value = "code", required = false) String code) {
|
|
|
+ logger.info("/api/oauth2/redirect");
|
|
|
// 웹뷰에서 사용자의 정보를 입력받아서 넘어와야함
|
|
|
// 사용자 정보를 단지서버에 전송해 사용자 확인하는 절차필요
|
|
|
-
|
|
|
- String redirectUri = (String) httpSession.getAttribute("redirectUri");
|
|
|
- String code = "SampleCode"; // Code를 생성하고 이후에 토큰 요청을 수신했을 때 검사할 수 있어야 함.(DB저장 등이 필요함.)
|
|
|
- redirectUri += "?state=" + httpSession.getAttribute("state");
|
|
|
- redirectUri += "&code=" + code;
|
|
|
- logger.info(redirectUri);
|
|
|
+ String redirectUri = "http://127.0.0.1:8080/api/oauth2/token?grant_type=authorization_code&code=" + code;
|
|
|
RedirectView redirectView = new RedirectView();
|
|
|
redirectView.setUrl(redirectUri);
|
|
|
return redirectView;
|
|
|
|
|
|
}
|
|
|
|
|
|
- // ((Test)) Redirect Destination
|
|
|
- @RequestMapping(value = "/api/oauth2/redirect", method = RequestMethod.GET, produces = "application/json")
|
|
|
+ @RequestMapping(value = "/api/oauth2/token", method = RequestMethod.GET)
|
|
|
public @ResponseBody String Token(@RequestParam(value = "grant_type", required = true) String grantType,
|
|
|
@RequestParam(value = "code", required = false) String code,
|
|
|
@RequestParam(value = "refresh_token", required = false) String refreshToken, HttpSession httpSession) {
|
|
|
|
|
|
+ logger.info("/api/oauth2/token");
|
|
|
// Code유효성 검사
|
|
|
// token 발급
|
|
|
+ logger.info(code);
|
|
|
+ logger.info(grantType);
|
|
|
String newAccessToken = "ACCESSTOKEN"; // 생성해야 함.
|
|
|
String newRefreshToken = "REFRESHTOKEN"; // 생성해야 함.
|
|
|
String tokenType = "bearer";
|
|
|
int expiresIn = 3600;
|
|
|
|
|
|
+ // class 만들어서 사용하는 것으로 변경해야함.
|
|
|
String result = "{" + "access_toke:" + newAccessToken + ", refresh_token:" + newRefreshToken + ", token_type:"
|
|
|
+ tokenType + ", expires_in:" + expiresIn + "}";
|
|
|
|