use of me.zhyd.oauth.exception.AuthException in project wumei-smart by kerwincui.
the class SocialLoginServiceImpl method renderAuth.
@Override
public String renderAuth(String source, HttpServletRequest httpServletRequest) {
AuthRequestWrap authRequestWrap = null;
try {
authRequestWrap = iAuthRequestFactory.getAuthRequest(source);
checkSocialPlatform(authRequestWrap.getSocialPlatform());
return authRequestWrap.getAuthRequest().authorize(AuthStateUtils.createState());
} catch (AuthException authException) {
// 返回错误信息
log.error("", authException);
if (authRequestWrap != null) {
String errorId = genErrorId(authException.getMessage());
return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
} else {
return httpServletRequest.getProtocol() + httpServletRequest.getServerName() + httpServletRequest.getServerPort();
}
} catch (Exception exception) {
// 这类错误 直接不返回,重定向到主页
log.error("", exception);
return HTTPS + httpServletRequest.getServerName();
}
}
use of me.zhyd.oauth.exception.AuthException in project wumei-smart by kerwincui.
the class SocialLoginServiceImpl method callback.
@Override
public String callback(String source, AuthCallback authCallback, HttpServletRequest httpServletRequest) {
AuthRequestWrap authRequestWrap = null;
try {
authRequestWrap = iAuthRequestFactory.getAuthRequest(source);
checkSocialPlatform(authRequestWrap.getSocialPlatform());
AuthResponse<AuthUser> authResponse = authRequestWrap.getAuthRequest().login(authCallback);
String bindId = null;
String loginId = null;
if (authResponse.ok()) {
SocialUser socialUser = findSocialUser(authResponse.getData().getUuid(), authResponse.getData().getSource());
createOrUpdateSocialUser(socialUser, authResponse.getData());
if (socialUser == null) {
// 第一次登录
bindId = genBindId(authResponse.getData());
} else if (socialUser.getSysUserId() == null || socialUser.getSysUserId() <= 0) {
// 初次绑定
bindId = genBindId(authResponse.getData());
} else {
// 查看是否已经绑定
SysUser sysUser = iSysUserService.selectUserById(socialUser.getSysUserId());
if (sysUser == null) {
bindId = genBindId(authResponse.getData());
} else {
// 直接登录跳转
loginId = genLoginId(sysUser);
}
}
if (StringUtils.isNotEmpty(bindId)) {
return authRequestWrap.getSocialPlatform().getBindUri() + bindId;
} else {
return authRequestWrap.getSocialPlatform().getRedirectLoginUri() + loginId;
}
} else {
log.error("登录授权异常,code:{}, msg:{}", authResponse.getCode(), authResponse.getMsg());
String errorId = genErrorId(authResponse.getMsg());
return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
}
} catch (AuthException authException) {
// 返回错误信息
log.error("", authException);
if (authRequestWrap != null) {
String errorId = genErrorId(authException.getMessage());
return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
} else {
return httpServletRequest.getServerName() + httpServletRequest.getServerPort();
}
} catch (Exception exception) {
log.error("", exception);
return HTTPS + httpServletRequest.getServerName();
}
}
use of me.zhyd.oauth.exception.AuthException in project blade-tool by chillzhuang.
the class SocialUtil method getAuthRequest.
/**
* 根据具体的授权来源,获取授权请求工具类
*
* @param source 授权来源
* @return AuthRequest
*/
public static AuthRequest getAuthRequest(String source, SocialProperties socialProperties) {
AuthDefaultSource authSource = Objects.requireNonNull(AuthDefaultSource.valueOf(source.toUpperCase()));
AuthConfig authConfig = socialProperties.getOauth().get(authSource);
if (authConfig == null) {
throw new AuthException("未获取到有效的Auth配置");
}
AuthRequest authRequest = null;
switch(authSource) {
case GITHUB:
authRequest = new AuthGithubRequest(authConfig);
break;
case GITEE:
authRequest = new AuthGiteeRequest(authConfig);
break;
case OSCHINA:
authRequest = new AuthOschinaRequest(authConfig);
break;
case QQ:
authRequest = new AuthQqRequest(authConfig);
break;
case WECHAT_OPEN:
authRequest = new AuthWeChatOpenRequest(authConfig);
break;
case WECHAT_ENTERPRISE:
authRequest = new AuthWeChatEnterpriseRequest(authConfig);
break;
case WECHAT_MP:
authRequest = new AuthWeChatMpRequest(authConfig);
break;
case DINGTALK:
authRequest = new AuthDingTalkRequest(authConfig);
break;
case ALIPAY:
// 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1,所以这儿的回调地址使用的局域网内的ip
authRequest = new AuthAlipayRequest(authConfig);
break;
case BAIDU:
authRequest = new AuthBaiduRequest(authConfig);
break;
case WEIBO:
authRequest = new AuthWeiboRequest(authConfig);
break;
case CODING:
authRequest = new AuthCodingRequest(authConfig);
break;
case CSDN:
authRequest = new AuthCsdnRequest(authConfig);
break;
case TAOBAO:
authRequest = new AuthTaobaoRequest(authConfig);
break;
case GOOGLE:
authRequest = new AuthGoogleRequest(authConfig);
break;
case FACEBOOK:
authRequest = new AuthFacebookRequest(authConfig);
break;
case DOUYIN:
authRequest = new AuthDouyinRequest(authConfig);
break;
case LINKEDIN:
authRequest = new AuthLinkedinRequest(authConfig);
break;
case MICROSOFT:
authRequest = new AuthMicrosoftRequest(authConfig);
break;
case MI:
authRequest = new AuthMiRequest(authConfig);
break;
case TOUTIAO:
authRequest = new AuthToutiaoRequest(authConfig);
break;
case TEAMBITION:
authRequest = new AuthTeambitionRequest(authConfig);
break;
case PINTEREST:
authRequest = new AuthPinterestRequest(authConfig);
break;
case RENREN:
authRequest = new AuthRenrenRequest(authConfig);
break;
case STACK_OVERFLOW:
authRequest = new AuthStackOverflowRequest(authConfig);
break;
case HUAWEI:
authRequest = new AuthHuaweiRequest(authConfig);
break;
case KUJIALE:
authRequest = new AuthKujialeRequest(authConfig);
break;
case GITLAB:
authRequest = new AuthGitlabRequest(authConfig);
break;
case MEITUAN:
authRequest = new AuthMeituanRequest(authConfig);
break;
case ELEME:
authRequest = new AuthElemeRequest(authConfig);
break;
case TWITTER:
authRequest = new AuthTwitterRequest(authConfig);
break;
default:
break;
}
if (null == authRequest) {
throw new AuthException("未获取到有效的Auth配置");
}
return authRequest;
}
Aggregations