Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
7cdc7191
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
394
Star
15212
Fork
2708
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
JustAuth
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7cdc7191
编写于
8月 10, 2021
作者:
cly_0
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
继续进行优化,去掉多余的改动
上级
5073f828
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
521 deletion
+96
-521
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
+69
-475
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+0
-17
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
+25
-29
src/test/java/me/zhyd/oauth/request/AuthWeChatMpRequestTest.java
...t/java/me/zhyd/oauth/request/AuthWeChatMpRequestTest.java
+2
-0
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
浏览文件 @
7cdc7191
...
...
@@ -17,7 +17,7 @@ public enum AuthDefaultSource implements AuthSource {
/**
* Github
*/
GITHUB
{
GITHUB
(
AuthGithubRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://github.com/login/oauth/authorize"
;
...
...
@@ -32,21 +32,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.github.com/user"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthGithubRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 新浪微博
*/
WEIBO
{
WEIBO
(
AuthWeiboRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://api.weibo.com/oauth2/authorize"
;
...
...
@@ -62,16 +52,6 @@ public enum AuthDefaultSource implements AuthSource {
return
"https://api.weibo.com/2/users/show.json"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthWeiboRequest
.
class
,
authConfig
,
authStateCache
);
}
@Override
public
String
revoke
()
{
return
"https://api.weibo.com/oauth2/revokeoauth2"
;
...
...
@@ -80,7 +60,7 @@ public enum AuthDefaultSource implements AuthSource {
/**
* gitee
*/
GITEE
{
GITEE
(
AuthGiteeRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://gitee.com/oauth/authorize"
;
...
...
@@ -95,21 +75,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://gitee.com/api/v5/user"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthGiteeRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 钉钉扫码登录
*/
DINGTALK
{
DINGTALK
(
AuthDingTalkRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://oapi.dingtalk.com/connect/qrconnect"
;
...
...
@@ -124,21 +94,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://oapi.dingtalk.com/sns/getuserinfo_bycode"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthDingTalkRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 钉钉账号登录
*/
DINGTALK_ACCOUNT
{
DINGTALK_ACCOUNT
(
AuthDingTalkAccountRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://oapi.dingtalk.com/connect/oauth2/sns_authorize"
;
...
...
@@ -153,21 +113,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
DINGTALK
.
userInfo
();
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthDingTalkAccountRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 百度
*/
BAIDU
{
BAIDU
(
AuthBaiduRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://openapi.baidu.com/oauth/2.0/authorize"
;
...
...
@@ -192,21 +142,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://openapi.baidu.com/oauth/2.0/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthBaiduRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* csdn
*/
CSDN
{
CSDN
(
AuthCsdnRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://api.csdn.net/oauth2/authorize"
;
...
...
@@ -221,16 +161,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.csdn.net/user/getinfo"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthCsdnRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Coding,
...
...
@@ -238,7 +168,7 @@ public enum AuthDefaultSource implements AuthSource {
* 参考 https://help.coding.net/docs/project/open/oauth.html#%E7%94%A8%E6%88%B7%E6%8E%88%E6%9D%83 中的说明,
* 新版的 coding API 地址需要传入用户团队名,这儿使用动态参数,方便在 request 中使用
*/
CODING
{
CODING
(
AuthCodingRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://%s.coding.net/oauth_authorize.html"
;
...
...
@@ -253,21 +183,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://%s.coding.net/api/account/current_user"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthCodingRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* oschina 开源中国
*/
OSCHINA
{
OSCHINA
(
AuthOschinaRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://www.oschina.net/action/oauth2/authorize"
;
...
...
@@ -282,21 +202,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://www.oschina.net/action/openapi/user"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthOschinaRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 支付宝
*/
ALIPAY
{
ALIPAY
(
AuthAlipayRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"
;
...
...
@@ -311,21 +221,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthAlipayRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* QQ
*/
QQ
{
QQ
(
AuthQqRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://graph.qq.com/oauth2.0/authorize"
;
...
...
@@ -345,21 +245,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://graph.qq.com/oauth2.0/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthQqRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 微信开放平台
*/
WECHAT_OPEN
{
WECHAT_OPEN
(
AuthWeChatOpenRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.weixin.qq.com/connect/qrconnect"
;
...
...
@@ -379,21 +269,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://api.weixin.qq.com/sns/oauth2/refresh_token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthWeChatOpenRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 微信公众平台
*/
WECHAT_MP
{
WECHAT_MP
(
AuthWeChatMpRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.weixin.qq.com/connect/oauth2/authorize"
;
...
...
@@ -413,21 +293,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://api.weixin.qq.com/sns/oauth2/refresh_token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthWeChatMpRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 淘宝
*/
TAOBAO
{
TAOBAO
(
AuthTaobaoRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://oauth.taobao.com/authorize"
;
...
...
@@ -442,21 +312,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthTaobaoRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Google
*/
GOOGLE
{
GOOGLE
(
AuthGoogleRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://accounts.google.com/o/oauth2/v2/auth"
;
...
...
@@ -471,21 +331,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://www.googleapis.com/oauth2/v3/userinfo"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthGoogleRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Facebook
*/
FACEBOOK
{
FACEBOOK
(
AuthFacebookRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://www.facebook.com/v10.0/dialog/oauth"
;
...
...
@@ -500,21 +350,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://graph.facebook.com/v10.0/me"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthFacebookRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 抖音
*/
DOUYIN
{
DOUYIN
(
AuthDouyinRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.douyin.com/platform/oauth/connect"
;
...
...
@@ -534,21 +374,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://open.douyin.com/oauth/refresh_token/"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthDouyinRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 领英
*/
LINKEDIN
{
LINKEDIN
(
AuthLinkedinRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://www.linkedin.com/oauth/v2/authorization"
;
...
...
@@ -568,21 +398,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://www.linkedin.com/oauth/v2/accessToken"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthLinkedinRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 微软
*/
MICROSOFT
{
MICROSOFT
(
AuthMicrosoftRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
;
...
...
@@ -602,21 +422,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthMicrosoftRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 小米
*/
MI
{
MI
(
AuthMiRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://account.xiaomi.com/oauth2/authorize"
;
...
...
@@ -636,21 +446,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://account.xiaomi.com/oauth2/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthMiRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 今日头条
*/
TOUTIAO
{
TOUTIAO
(
AuthToutiaoRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.snssdk.com/auth/authorize"
;
...
...
@@ -665,21 +465,11 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://open.snssdk.com/data/user_profile"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthToutiaoRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Teambition
*/
TEAMBITION
{
TEAMBITION
(
AuthTeambitionRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://account.teambition.com/oauth2/authorize"
;
...
...
@@ -699,22 +489,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.teambition.com/users/me"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthTeambitionRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 人人网
*/
RENREN
{
RENREN
(
AuthRenrenRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://graph.renren.com/oauth/authorize"
;
...
...
@@ -734,22 +514,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.renren.com/v2/user/get"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthRenrenRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Pinterest
*/
PINTEREST
{
PINTEREST
(
AuthPinterestRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://api.pinterest.com/oauth"
;
...
...
@@ -764,22 +534,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.pinterest.com/v1/me"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthPinterestRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Stack Overflow
*/
STACK_OVERFLOW
{
STACK_OVERFLOW
(
AuthStackOverflowRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://stackoverflow.com/oauth"
;
...
...
@@ -794,16 +554,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.stackexchange.com/2.2/me"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthStackOverflowRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -811,7 +561,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.10.0
*/
HUAWEI
{
HUAWEI
(
AuthHuaweiRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/authorize"
;
...
...
@@ -831,16 +581,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthHuaweiRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -848,7 +588,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.10.0
*/
WECHAT_ENTERPRISE
{
WECHAT_ENTERPRISE
(
AuthWeChatEnterpriseQrcodeRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.work.weixin.qq.com/wwopen/sso/qrConnect"
;
...
...
@@ -863,22 +603,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AbstractAuthWeChatEnterpriseRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 企业微信网页登录
*/
WECHAT_ENTERPRISE_WEB
{
WECHAT_ENTERPRISE_WEB
(
AuthWeChatEnterpriseWebRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.weixin.qq.com/connect/oauth2/authorize"
;
...
...
@@ -893,16 +623,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthWeChatEnterpriseWebRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -910,7 +630,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.11.0
*/
KUJIALE
{
KUJIALE
(
AuthKujialeRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://oauth.kujiale.com/oauth2/show"
;
...
...
@@ -930,16 +650,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://oauth.kujiale.com/oauth2/auth/token/refresh"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthKujialeRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -947,7 +657,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.11.0
*/
GITLAB
{
GITLAB
(
AuthGitlabRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://gitlab.com/oauth/authorize"
;
...
...
@@ -962,16 +672,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://gitlab.com/api/v4/user"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthGitlabRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -979,7 +679,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.12.0
*/
MEITUAN
{
MEITUAN
(
AuthMeituanRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://openapi.waimai.meituan.com/oauth/authorize"
;
...
...
@@ -999,16 +699,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://openapi.waimai.meituan.com/oauth/refresh_token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthMeituanRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -1018,7 +708,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.12.0
*/
ELEME
{
ELEME
(
AuthElemeRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open-api.shop.ele.me/authorize"
;
...
...
@@ -1038,16 +728,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://open-api.shop.ele.me/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthElemeRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -1055,7 +735,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.13.0
*/
TWITTER
{
TWITTER
(
AuthTwitterRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://api.twitter.com/oauth/authenticate"
;
...
...
@@ -1070,16 +750,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.twitter.com/1.1/account/verify_credentials.json"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthTwitterRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -1089,7 +759,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.15.9
*/
FEISHU
{
FEISHU
(
AuthFeishuRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open.feishu.cn/open-apis/authen/v1/index"
;
...
...
@@ -1109,23 +779,13 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://open.feishu.cn/open-apis/authen/v1/refresh_access_token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthFeishuRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 京东
*
* @since 1.15.0
*/
JD
{
JD
(
AuthJdRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://open-oauth.jd.com/oauth2/to_login"
;
...
...
@@ -1145,22 +805,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://open-oauth.jd.com/oauth2/refresh_token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthJdRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 阿里云
*/
ALIYUN
{
ALIYUN
(
AuthAliyunRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://signin.aliyun.com/oauth2/v1/auth"
;
...
...
@@ -1180,22 +830,12 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://oauth.aliyun.com/v1/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthAliyunRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 喜马拉雅
*/
XMLY
{
XMLY
(
AuthXmlyRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://api.ximalaya.com/oauth2/js/authorize"
;
...
...
@@ -1215,16 +855,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://oauth.aliyun.com/v1/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthXmlyRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
...
...
@@ -1232,7 +862,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.16.0
*/
AMAZON
{
AMAZON
(
AuthAmazonRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://www.amazon.com/ap/oa"
;
...
...
@@ -1252,23 +882,13 @@ public enum AuthDefaultSource implements AuthSource {
public
String
refresh
()
{
return
"https://api.amazon.com/auth/o2/token"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthAmazonRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* Slack
*
* @since 1.16.0
*/
SLACK
{
SLACK
(
AuthSlackRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://slack.com/oauth/v2/authorize"
;
...
...
@@ -1295,23 +915,13 @@ public enum AuthDefaultSource implements AuthSource {
public
String
revoke
()
{
return
"https://slack.com/api/auth.revoke"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthSlackRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* line
*
* @since 1.16.0
*/
LINE
{
LINE
(
AuthLineRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://access.line.me/oauth2/v2.1/authorize"
;
...
...
@@ -1327,16 +937,6 @@ public enum AuthDefaultSource implements AuthSource {
return
"https://api.line.me/v2/profile"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthLineRequest
.
class
,
authConfig
,
authStateCache
);
}
@Override
public
String
refresh
()
{
return
"https://api.line.me/oauth2/v2.1/token"
;
...
...
@@ -1346,7 +946,6 @@ public enum AuthDefaultSource implements AuthSource {
public
String
revoke
()
{
return
"https://api.line.me/oauth2/v2.1/revoke"
;
}
},
/**
* Okta,
...
...
@@ -1355,7 +954,7 @@ public enum AuthDefaultSource implements AuthSource {
*
* @since 1.16.0
*/
OKTA
{
OKTA
(
AuthOktaRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://%s.okta.com/oauth2/%s/v1/authorize"
;
...
...
@@ -1380,23 +979,13 @@ public enum AuthDefaultSource implements AuthSource {
public
String
revoke
()
{
return
"https://%s.okta.com/oauth2/%s/v1/revoke"
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthOktaRequest
.
class
,
authConfig
,
authStateCache
);
}
},
/**
* 程序员客栈
*
* @since 1.16.2
*/
PROGINN
{
PROGINN
(
AuthProginnRequest
.
class
)
{
@Override
public
String
authorize
()
{
return
"https://www.proginn.com/oauth2/authorize"
;
...
...
@@ -1411,44 +1000,49 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://www.proginn.com/openapi/user/basic_info"
;
}
};
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
/** 对应的实现类 */
private
Class
<?
extends
AuthDefaultRequest
>
targetClass
;
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
return
getInstance
(
AuthProginnRequest
.
class
,
authConfig
,
authStateCache
);
}
};
AuthDefaultSource
(
Class
<?
extends
AuthDefaultRequest
>
targetClass
)
{
this
.
targetClass
=
targetClass
;
}
/**
* 根据source获取对应的AuthSource枚举
* @param source 枚举名
* @return AuthDefaultSource
*/
public
static
AuthDefaultSource
getAuthSource
(
String
source
){
return
Arrays
.
stream
(
AuthDefaultSource
.
values
()).
filter
(
authSource
->
authSource
.
name
().
equalsIgnoreCase
(
source
)).
findAny
().
orElseThrow
(()->
new
AuthException
(
"未获取到有效的AuthSource配置"
));
}
/**
* 根据配置获取 AuthRequest 实例
* @param authConfig 配置
* @return AuthRequest
*/
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
/**
* 利用反射 生成 AuthRequest 实例
* @param cl 目标 class
* @param authConfig 配置
* @param authStateCache 缓存配置
* @return AuthRequest
*/
AuthRequest
getInstance
(
Class
<?
extends
AuthDefaultRequest
>
cl
,
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
try
{
Class
<?>
clazz
=
Class
.
forName
(
cl
.
getName
());
if
(
authStateCache
==
null
){
return
(
AuthRequest
)
clazz
.
getDeclaredConstructor
(
AuthConfig
.
class
).
newInstance
(
authConfig
);
return
this
.
targetClass
.
getDeclaredConstructor
(
AuthConfig
.
class
).
newInstance
(
authConfig
);
}
else
{
return
(
AuthRequest
)
clazz
.
getDeclaredConstructor
(
AuthConfig
.
class
,
AuthStateCache
.
class
).
newInstance
(
authConfig
,
authStateCache
);
return
this
.
targetClass
.
getDeclaredConstructor
(
AuthConfig
.
class
,
AuthStateCache
.
class
).
newInstance
(
authConfig
,
authStateCache
);
}
}
catch
(
Exception
e
)
{
throw
new
AuthException
(
"未获取到有效的Auth配置"
);
}
}
/**
* 根据source获取对应的AuthSource枚举实例
* @param source 枚举名
* @return AuthDefaultSource
*/
public
static
AuthDefaultSource
getAuthSource
(
String
source
){
return
Arrays
.
stream
(
AuthDefaultSource
.
values
()).
filter
(
authSource
->
source
.
equalsIgnoreCase
(
authSource
.
name
())).
findAny
().
orElseThrow
(()->
new
AuthException
(
"未获取到有效的AuthSource配置"
));
}
}
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
7cdc7191
package
me.zhyd.oauth.config
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.request.AuthRequest
;
/**
* OAuth平台的API地址的统一接口,提供以下方法:
...
...
@@ -46,21 +44,6 @@ public interface AuthSource {
*/
String
userInfo
();
/**
* 根据配置获取对应的实例
* @param authConfig 配置
* @return AuthRequest
*/
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
);
/**
* 根据配置和缓存获取对应的实例
* @param authConfig 配置
* @param authStateCache 缓存
* @return AuthRequest
*/
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
);
/**
* 取消授权的api
*
...
...
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
浏览文件 @
7cdc7191
...
...
@@ -2,11 +2,10 @@ package me.zhyd.oauth.config;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.request.AuthDefaultRequest
;
import
me.zhyd.oauth.request.AuthExtendRequest
;
import
me.zhyd.oauth.request.AuthRequest
;
import
java.lang.reflect.Constructor
;
/**
* 测试自定义实现{@link AuthSource}接口后的枚举类
*
...
...
@@ -16,7 +15,7 @@ import java.lang.reflect.Constructor;
*/
public
enum
AuthExtendSource
implements
AuthSource
{
OTHER
{
OTHER
(
AuthExtendRequest
.
class
)
{
/**
* 授权的api
*
...
...
@@ -47,32 +46,6 @@ public enum AuthExtendSource implements AuthSource {
return
null
;
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
getAuthRequestInstance
(
authConfig
,
null
);
}
@Override
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
try
{
AuthRequest
request
;
Class
<?>
clazz
=
Class
.
forName
(
AuthExtendRequest
.
class
.
getName
());
Constructor
constructor
;
if
(
authStateCache
==
null
){
constructor
=
clazz
.
getDeclaredConstructor
(
AuthConfig
.
class
);
constructor
.
setAccessible
(
true
);
request
=
(
AuthRequest
)
constructor
.
newInstance
(
authConfig
);
}
else
{
constructor
=
clazz
.
getDeclaredConstructor
(
AuthConfig
.
class
,
AuthStateCache
.
class
);
constructor
.
setAccessible
(
true
);
request
=
(
AuthRequest
)
constructor
.
newInstance
(
authConfig
,
authStateCache
);
}
return
request
;
}
catch
(
Exception
e
)
{
throw
new
AuthException
(
"未获取到有效的Auth配置"
);
}
}
/**
* 取消授权的api
*
...
...
@@ -92,5 +65,28 @@ public enum AuthExtendSource implements AuthSource {
public
String
refresh
()
{
return
null
;
}
};
private
Class
<?
extends
AuthDefaultRequest
>
targetClass
;
AuthExtendSource
(
Class
<?
extends
AuthDefaultRequest
>
targetClass
)
{
this
.
targetClass
=
targetClass
;
}
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
)
{
return
this
.
getAuthRequestInstance
(
authConfig
,
null
);
}
public
AuthRequest
getAuthRequestInstance
(
AuthConfig
authConfig
,
AuthStateCache
authStateCache
)
{
try
{
if
(
authStateCache
==
null
){
return
this
.
targetClass
.
getDeclaredConstructor
(
AuthConfig
.
class
).
newInstance
(
authConfig
);
}
else
{
return
this
.
targetClass
.
getDeclaredConstructor
(
AuthConfig
.
class
,
AuthStateCache
.
class
).
newInstance
(
authConfig
,
authStateCache
);
}
}
catch
(
Exception
e
)
{
throw
new
AuthException
(
"未获取到有效的Auth配置"
);
}
}
}
src/test/java/me/zhyd/oauth/request/AuthWeChatMpRequestTest.java
浏览文件 @
7cdc7191
...
...
@@ -3,6 +3,7 @@ package me.zhyd.oauth.request;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthDefaultSource
;
import
me.zhyd.oauth.utils.AuthStateUtils
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
AuthWeChatMpRequestTest
{
...
...
@@ -25,6 +26,7 @@ public class AuthWeChatMpRequestTest {
.
clientSecret
(
"a"
)
.
redirectUri
(
"https://www.justauth.cn"
)
.
build
());
Assert
.
assertTrue
(
request
instanceof
AuthWeChatMpRequest
);
System
.
out
.
println
(
request
.
authorize
(
AuthStateUtils
.
createState
()));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录