@ -17,6 +17,8 @@ import org.dromara.common.social.config.properties.SocialProperties;
* @author thiszhc
* /
public class SocialUtils {
@SuppressWarnings ( "unchecked" )
public static AuthResponse < AuthUser > loginAuth ( LoginBody loginBody , SocialProperties socialProperties ) throws AuthException {
AuthRequest authRequest = getAuthRequest ( loginBody . getSource ( ) , socialProperties ) ;
AuthCallback callback = new AuthCallback ( ) ;
@ -25,7 +27,7 @@ public class SocialUtils {
return authRequest . login ( callback ) ;
}
public static AuthRequest getAuthRequest ( String source , SocialProperties socialProperties ) throws AuthException {
public static AuthRequest getAuthRequest ( String source , SocialProperties socialProperties ) throws AuthException {
SocialLoginConfigProperties obj = socialProperties . getType ( ) . get ( source ) ;
if ( ObjectUtil . isNull ( obj ) ) {
throw new AuthException ( "不支持的第三方登录类型" ) ;
@ -33,106 +35,32 @@ public class SocialUtils {
String clientId = obj . getClientId ( ) ;
String clientSecret = obj . getClientSecret ( ) ;
String redirectUri = obj . getRedirectUri ( ) ;
AuthRequest authRequest = null ;
switch ( source . toLowerCase ( ) ) {
case "dingtalk" - >
authRequest = new AuthDingTalkRequest ( AuthConfig . builder ( )
. clientId ( clientId )
. clientSecret ( clientSecret )
. redirectUri ( redirectUri )
. build ( ) ) ;
case "baidu" - >
authRequest = new AuthBaiduRequest ( AuthConfig . builder ( )
. clientId ( clientId )
. clientSecret ( clientSecret )
. redirectUri ( redirectUri )
. build ( ) ) ;
case "github" - >
authRequest = new AuthGithubRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "gitee" - >
authRequest = new AuthGiteeRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "weibo" - >
authRequest = new AuthWeiboRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "coding" - >
authRequest = new AuthCodingRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "oschina" - >
authRequest = new AuthOschinaRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "alipay" - >
// 支付宝在创建回调地址时, 不允许使用localhost或者127.0.0.1, 所以这儿的回调地址使用的局域网内的ip
authRequest = new AuthAlipayRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "qq" - >
authRequest = new AuthQqRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_open" - > authRequest = new AuthWeChatOpenRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "csdn" - >
//注意,经咨询CSDN官方客服得知, CSDN的授权开放平台已经下线。如果以前申请过的应用, 可以继续使用, 但是不再支持申请新的应用。
// so, 本项目中的CSDN登录只能针对少部分用户使用了
authRequest = new AuthCsdnRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "taobao" - >
authRequest = new AuthTaobaoRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "douyin" - >
authRequest = new AuthDouyinRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "linkedin" - >
authRequest = new AuthLinkedinRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "microsoft" - > authRequest = new AuthMicrosoftRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "mi" - >
authRequest = new AuthMiRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "toutiao" - >
authRequest = new AuthToutiaoRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "teambition" - > authRequest = new AuthTeambitionRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "pinterest" - > authRequest = new AuthPinterestRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "renren" - >
authRequest = new AuthRenrenRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "stack_overflow" - > authRequest = new AuthStackOverflowRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . stackOverflowKey ( "" ) . build ( ) ) ;
case "huawei" - >
authRequest = new AuthHuaweiRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_enterprise" - >
authRequest = new AuthWeChatEnterpriseQrcodeRequest ( AuthConfig . builder ( ) . clientId ( clientId )
. clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . agentId ( "" ) . build ( ) ) ;
case "kujiale" - >
authRequest = new AuthKujialeRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "gitlab" - >
authRequest = new AuthGitlabRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "meituan" - >
authRequest = new AuthMeituanRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "eleme" - >
authRequest = new AuthElemeRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_mp" - >
authRequest = new AuthWeChatMpRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
case "aliyun" - >
authRequest = new AuthAliyunRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret )
. redirectUri ( redirectUri ) . build ( ) ) ;
default - > {
}
}
if ( null = = authRequest ) {
throw new AuthException ( "未获取到有效的Auth配置" ) ;
}
return authRequest ;
return switch ( source . toLowerCase ( ) ) {
case "dingtalk" - > new AuthDingTalkRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "baidu" - > new AuthBaiduRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "github" - > new AuthGithubRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "gitee" - > new AuthGiteeRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "weibo" - > new AuthWeiboRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "coding" - > new AuthCodingRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "oschina" - > new AuthOschinaRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
// 支付宝在创建回调地址时, 不允许使用localhost或者127.0.0.1, 所以这儿的回调地址使用的局域网内的ip
// 使用支付宝需要提供alipay公钥
// case "alipay" -> new AuthAlipayRequest(AuthConfig.builder().clientId(clientId).clientSecret(clientSecret).redirectUri(redirectUri).build(), alipayPublicKey);
case "qq" - > new AuthQqRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_open" - > new AuthWeChatOpenRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "taobao" - > new AuthTaobaoRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "douyin" - > new AuthDouyinRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "linkedin" - > new AuthLinkedinRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "microsoft" - > new AuthMicrosoftRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "renren" - > new AuthRenrenRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "stack_overflow" - > new AuthStackOverflowRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . stackOverflowKey ( "" ) . build ( ) ) ;
case "huawei" - > new AuthHuaweiRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_enterprise" - > new AuthWeChatEnterpriseQrcodeRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . agentId ( "" ) . build ( ) ) ;
case "gitlab" - > new AuthGitlabRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "wechat_mp" - > new AuthWeChatMpRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
case "aliyun" - > new AuthAliyunRequest ( AuthConfig . builder ( ) . clientId ( clientId ) . clientSecret ( clientSecret ) . redirectUri ( redirectUri ) . build ( ) ) ;
default - > throw new AuthException ( "未获取到有效的Auth配置" ) ;
} ;
}
}