use of com.ruoyi.iot.model.login.AuthRequestWrap 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 com.ruoyi.iot.model.login.AuthRequestWrap 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 com.ruoyi.iot.model.login.AuthRequestWrap in project wumei-smart by kerwincui.
the class AuthRequestFactoryImpl method getAuthRequest.
/**
* 获得对于AUthRequest
*
* @param source 登录方式
* @return 对应AuthRequest
*/
@Override
public AuthRequestWrap getAuthRequest(String source) {
AuthRequestWrap authRequestWrap = new AuthRequestWrap();
AuthRequest authRequest;
try {
SocialPlatformType socialPlatformType = SocialPlatformType.valueOf(source.toUpperCase(Locale.ROOT));
SocialPlatform socialPlatform = iSocialPlatformService.selectSocialPlatformByPlatform(source);
authRequestWrap.setSocialPlatform(socialPlatform);
AuthConfig authConfig = AuthConfig.builder().clientId(socialPlatform.getClientId()).clientSecret(socialPlatform.getSecretKey()).redirectUri(socialPlatform.getRedirectUri()).build();
switch(socialPlatformType) {
case QQ:
{
authRequest = new AuthQqRequest(authConfig, authStateRedisCache);
break;
}
case Wechat:
{
authRequest = new AuthWeChatMpRequest(authConfig, authStateRedisCache);
break;
}
default:
{
throw new ServiceException("source: " + source + ",暂不支持");
}
}
authRequestWrap.setAuthRequest(authRequest);
return authRequestWrap;
} catch (Exception e) {
throw new ServiceException(e.getMessage());
}
}
Aggregations