카카오로그인 부분 에러 수정
This commit is contained in:
parent
c0a5cb2672
commit
7d2da3c8a3
@ -1,5 +1,8 @@
|
|||||||
package egovframework.com.ext.oauth.service;
|
package egovframework.com.ext.oauth.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.github.scribejava.core.builder.ScopeBuilder;
|
import com.github.scribejava.core.builder.ScopeBuilder;
|
||||||
@ -10,6 +13,7 @@ import com.github.scribejava.core.model.Response;
|
|||||||
import com.github.scribejava.core.model.Verb;
|
import com.github.scribejava.core.model.Verb;
|
||||||
import com.github.scribejava.core.oauth.OAuth20Service;
|
import com.github.scribejava.core.oauth.OAuth20Service;
|
||||||
|
|
||||||
|
import nlib.user.web.LoginController;
|
||||||
import nlib.util.StringUtil;
|
import nlib.util.StringUtil;
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +22,7 @@ public class OAuthLogin {
|
|||||||
/** SNS 호출 시, URL callType 대체 문자열 */
|
/** SNS 호출 시, URL callType 대체 문자열 */
|
||||||
public static final String CALL_TYPE_LOGIN = "login";
|
public static final String CALL_TYPE_LOGIN = "login";
|
||||||
public static final String CALL_TYPE_MEMBER = "member";
|
public static final String CALL_TYPE_MEMBER = "member";
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(OAuthLogin.class);
|
||||||
|
|
||||||
private OAuth20Service oauthService;
|
private OAuth20Service oauthService;
|
||||||
private OAuthVO oauthVO;
|
private OAuthVO oauthVO;
|
||||||
@ -61,9 +66,9 @@ public class OAuthLogin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public OAuthUniversalUser getUserProfile(String code) throws Exception {
|
public OAuthUniversalUser getUserProfile(String code) throws Exception {
|
||||||
|
log.debug("getUserProfile > getAccessToken");
|
||||||
OAuth2AccessToken accessToken = oauthService.getAccessToken(code);
|
OAuth2AccessToken accessToken = oauthService.getAccessToken(code);
|
||||||
|
log.debug("getUserProfile > getAccessToken2");
|
||||||
OAuthRequest request = new OAuthRequest(Verb.GET, this.oauthVO.getProfileUrl());
|
OAuthRequest request = new OAuthRequest(Verb.GET, this.oauthVO.getProfileUrl());
|
||||||
oauthService.signRequest(accessToken, request);
|
oauthService.signRequest(accessToken, request);
|
||||||
|
|
||||||
@ -153,7 +158,9 @@ public class OAuthLogin {
|
|||||||
user.setSnsType(OAuthConfig.KAKAO_SERVICE_NAME);
|
user.setSnsType(OAuthConfig.KAKAO_SERVICE_NAME);
|
||||||
JsonNode resNode = rootNode.get("kakao_account");
|
JsonNode resNode = rootNode.get("kakao_account");
|
||||||
|
|
||||||
user.setSnsId((rootNode.get("id").asText() == null) ? "" : rootNode.get("id").asText());
|
if(rootNode.has("id")) {
|
||||||
|
user.setSnsId((rootNode.get("id").asText() == null) ? "" : rootNode.get("id").asText());
|
||||||
|
}
|
||||||
|
|
||||||
if (resNode.has("email")) {
|
if (resNode.has("email")) {
|
||||||
user.setSnsUserId(StringUtil.getString(resNode.get("email").asText(), ""));
|
user.setSnsUserId(StringUtil.getString(resNode.get("email").asText(), ""));
|
||||||
@ -170,8 +177,19 @@ public class OAuthLogin {
|
|||||||
user.setSnsGender("F");
|
user.setSnsGender("F");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (resNode.has("birthday") || resNode.has("birthyear"))
|
// 생년월일
|
||||||
user.setSnsUserId((resNode.get("email").asText() == null) ? "" : resNode.get("email").asText());
|
String birthday ="0000";
|
||||||
|
String birthyear = "0000";
|
||||||
|
if (resNode.has("birthday")) {
|
||||||
|
birthday = StringUtil.getString(resNode.get("birthday").asText(), "0000");
|
||||||
|
}
|
||||||
|
if (resNode.has("birthyear")) {
|
||||||
|
birthyear = StringUtil.getString(resNode.get("birthyear").asText(), "0000");
|
||||||
|
}
|
||||||
|
birthday = birthday.replaceAll("-", "");
|
||||||
|
if(birthday.length() != 4) birthday = "0000";
|
||||||
|
if(birthyear.length() != 4) birthyear = "0000";
|
||||||
|
user.setSnsBirthday(birthyear + birthday);
|
||||||
|
|
||||||
if (resNode.has("phone_number"))
|
if (resNode.has("phone_number"))
|
||||||
user.setSnsMobileNo(StringUtil.getString(resNode.get("phone_number").asText(), ""));
|
user.setSnsMobileNo(StringUtil.getString(resNode.get("phone_number").asText(), ""));
|
||||||
|
|||||||
@ -406,13 +406,20 @@ public class LoginController extends NlibCommonController {
|
|||||||
|
|
||||||
// SNS 클라이언트 설정 정보 할당
|
// SNS 클라이언트 설정 정보 할당
|
||||||
OAuthVO oauthVO = null;
|
OAuthVO oauthVO = null;
|
||||||
if (StringUtil.equalsIgnoreCase(OAuthConfig.NAVER_SERVICE_NAME, oauthServiceName))
|
if (StringUtil.equalsIgnoreCase(OAuthConfig.NAVER_SERVICE_NAME, oauthServiceName)) {
|
||||||
|
log.debug("callbackOauth > NAVER_SERVICE_NAME");
|
||||||
oauthVO = naverAuthVO;
|
oauthVO = naverAuthVO;
|
||||||
else if (StringUtil.equalsIgnoreCase(OAuthConfig.GOOGLE_SERVICE_NAME, oauthServiceName))
|
}
|
||||||
|
else if (StringUtil.equalsIgnoreCase(OAuthConfig.GOOGLE_SERVICE_NAME, oauthServiceName)) {
|
||||||
|
log.debug("callbackOauth > GOOGLE_SERVICE_NAME");
|
||||||
oauthVO = googleAuthVO;
|
oauthVO = googleAuthVO;
|
||||||
else if (StringUtil.equalsIgnoreCase(OAuthConfig.KAKAO_SERVICE_NAME, oauthServiceName))
|
}
|
||||||
|
else if (StringUtil.equalsIgnoreCase(OAuthConfig.KAKAO_SERVICE_NAME, oauthServiceName)) {
|
||||||
|
log.debug("callbackOauth > KAKAO_SERVICE_NAME");
|
||||||
oauthVO = kakaoAuthVO;
|
oauthVO = kakaoAuthVO;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
|
log.debug("callbackOauth > SNS 연동 콜백정보가 올바르지 않습니다.");
|
||||||
throw new Exception("SNS 연동 콜백정보가 올바르지 않습니다.");
|
throw new Exception("SNS 연동 콜백정보가 올바르지 않습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,9 +427,15 @@ public class LoginController extends NlibCommonController {
|
|||||||
// 1. code를 이용해서 Access Token 받기
|
// 1. code를 이용해서 Access Token 받기
|
||||||
// 2. Access Token을 이용해서 사용자 제공 정보 가져오기
|
// 2. Access Token을 이용해서 사용자 제공 정보 가져오기
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|
||||||
OAuthLogin oauthLogin = new OAuthLogin(oauthVO, callType);
|
OAuthLogin oauthLogin = new OAuthLogin(oauthVO, callType);
|
||||||
OAuthUniversalUser oauthUser = oauthLogin.getUserProfile(code); // 1,2번 동시
|
OAuthUniversalUser oauthUser = null;
|
||||||
log.debug("oauthLoginCallback > Profile ===>>" + oauthUser.getSnsId() + ", " + oauthUser.getSnsName());
|
try {
|
||||||
|
oauthUser = oauthLogin.getUserProfile(code); // 1,2번 동시
|
||||||
|
} catch(Exception e) {
|
||||||
|
log.debug("oauthLoginCallback > SNS 연동 콜백정보 코드가 업습니다. error ===>>" + e.toString());
|
||||||
|
throw new Exception("SNS 연동 콜백정보 코드가 업습니다.");
|
||||||
|
}
|
||||||
|
|
||||||
// oAuth를 통한 SNS연동이 실패한 경우
|
// oAuth를 통한 SNS연동이 실패한 경우
|
||||||
if(oauthUser == null || !oauthUser.isValid()) {
|
if(oauthUser == null || !oauthUser.isValid()) {
|
||||||
@ -432,6 +445,8 @@ public class LoginController extends NlibCommonController {
|
|||||||
return "nlib/login/loginPreSet";
|
return "nlib/login/loginPreSet";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.debug("oauthLoginCallback > Profile ===>>" + oauthUser.getSnsId() + ", " + oauthUser.getSnsName());
|
||||||
|
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
// 해당 처리기로 전환
|
// 해당 처리기로 전환
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
|
|||||||
@ -181,10 +181,18 @@ $(document).ready(function() {
|
|||||||
{
|
{
|
||||||
birth_dd = birth_dd.substr(1,1)
|
birth_dd = birth_dd.substr(1,1)
|
||||||
}
|
}
|
||||||
|
if(birth_yy != "0000")
|
||||||
$("#birth_yy").val(birth_yy).prop("selected", true);
|
{
|
||||||
$("#birth_mm").val(birth_mm).prop("selected", true);
|
$("#birth_yy").val(birth_yy).prop("selected", true);
|
||||||
$("#birth_dd").val(birth_dd).prop("selected", true);
|
}
|
||||||
|
if(birth_mm != "00")
|
||||||
|
{
|
||||||
|
$("#birth_mm").val(birth_mm).prop("selected", true);
|
||||||
|
}
|
||||||
|
if(birth_dd != "00")
|
||||||
|
{
|
||||||
|
$("#birth_dd").val(birth_dd).prop("selected", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var mobileNo="<c:out value="${loginVO.snsMobileNo}"/>";
|
var mobileNo="<c:out value="${loginVO.snsMobileNo}"/>";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user