Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
02f9f833
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看板
提交
02f9f833
编写于
9月 06, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
提取公共的Source接口,支持自定义扩展第三方平台的授权登录,具体扩展例子可参考AuthExtendRequest
上级
05374e7a
变更
41
隐藏空白更改
内联
并排
Showing
41 changed file
with
1100 addition
and
801 deletion
+1100
-801
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
+677
-0
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+21
-672
src/main/java/me/zhyd/oauth/enums/AuthResponseStatus.java
src/main/java/me/zhyd/oauth/enums/AuthResponseStatus.java
+1
-1
src/main/java/me/zhyd/oauth/model/AuthUser.java
src/main/java/me/zhyd/oauth/model/AuthUser.java
+1
-2
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
+6
-6
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthGitlabRequest.java
src/main/java/me/zhyd/oauth/request/AuthGitlabRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
...main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
...main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
+2
-2
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
+2
-2
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
.../java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
+2
-2
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
...ain/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
...va/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
+4
-4
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
+4
-4
src/main/java/me/zhyd/oauth/utils/AuthChecker.java
src/main/java/me/zhyd/oauth/utils/AuthChecker.java
+8
-7
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
+63
-0
src/test/java/me/zhyd/oauth/model/AuthUserTest.java
src/test/java/me/zhyd/oauth/model/AuthUserTest.java
+24
-0
src/test/java/me/zhyd/oauth/request/AuthExtendRequest.java
src/test/java/me/zhyd/oauth/request/AuthExtendRequest.java
+105
-0
src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
...est/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
+81
-0
src/test/java/me/zhyd/oauth/request/AuthRequestTest.java
src/test/java/me/zhyd/oauth/request/AuthRequestTest.java
+1
-1
src/test/java/me/zhyd/oauth/utils/UrlBuilderTest.java
src/test/java/me/zhyd/oauth/utils/UrlBuilderTest.java
+2
-2
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
0 → 100644
浏览文件 @
02f9f833
package
me.zhyd.oauth.config
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
/**
* JustAuth内置的各api需要的url, 用枚举类分平台类型管理
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @since 1.0
*/
public
enum
AuthDefaultSource
implements
AuthSource
{
/**
* Github
*/
GITHUB
{
@Override
public
String
authorize
()
{
return
"https://github.com/login/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://github.com/login/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.github.com/user"
;
}
},
/**
* 新浪微博
*/
WEIBO
{
@Override
public
String
authorize
()
{
return
"https://api.weibo.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.weibo.com/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.weibo.com/2/users/show.json"
;
}
},
/**
* gitee
*/
GITEE
{
@Override
public
String
authorize
()
{
return
"https://gitee.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://gitee.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://gitee.com/api/v5/user"
;
}
},
/**
* 钉钉
*/
DINGTALK
{
@Override
public
String
authorize
()
{
return
"https://oapi.dingtalk.com/connect/qrconnect"
;
}
@Override
public
String
accessToken
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
userInfo
()
{
return
"https://oapi.dingtalk.com/sns/getuserinfo_bycode"
;
}
},
/**
* 百度
*/
BAIDU
{
@Override
public
String
authorize
()
{
return
"https://openapi.baidu.com/oauth/2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.baidu.com/oauth/2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.baidu.com/rest/2.0/passport/users/getInfo"
;
}
@Override
public
String
revoke
()
{
return
"https://openapi.baidu.com/rest/2.0/passport/auth/revokeAuthorization"
;
}
@Override
public
String
refresh
()
{
return
"https://openapi.baidu.com/oauth/2.0/token"
;
}
},
/**
* csdn
*/
CSDN
{
@Override
public
String
authorize
()
{
return
"https://api.csdn.net/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.csdn.net/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.csdn.net/user/getinfo"
;
}
},
/**
* Coding
*/
CODING
{
@Override
public
String
authorize
()
{
return
"https://coding.net/oauth_authorize.html"
;
}
@Override
public
String
accessToken
()
{
return
"https://coding.net/api/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://coding.net/api/account/current_user"
;
}
},
/**
* 腾讯云开发者平台(coding升级后就变成腾讯云开发者平台了)
*/
TENCENT_CLOUD
{
@Override
public
String
authorize
()
{
return
"https://dev.tencent.com/oauth_authorize.html"
;
}
@Override
public
String
accessToken
()
{
return
"https://dev.tencent.com/api/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://dev.tencent.com/api/account/current_user"
;
}
},
/**
* oschina 开源中国
*/
OSCHINA
{
@Override
public
String
authorize
()
{
return
"https://www.oschina.net/action/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.oschina.net/action/openapi/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://www.oschina.net/action/openapi/user"
;
}
},
/**
* 支付宝
*/
ALIPAY
{
@Override
public
String
authorize
()
{
return
"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
},
/**
* QQ
*/
QQ
{
@Override
public
String
authorize
()
{
return
"https://graph.qq.com/oauth2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.qq.com/oauth2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.qq.com/user/get_user_info"
;
}
@Override
public
String
refresh
()
{
return
"https://graph.qq.com/oauth2.0/token"
;
}
},
/**
* 微信
*/
WECHAT
{
@Override
public
String
authorize
()
{
return
"https://open.weixin.qq.com/connect/qrconnect"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.weixin.qq.com/sns/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.weixin.qq.com/sns/userinfo"
;
}
@Override
public
String
refresh
()
{
return
"https://api.weixin.qq.com/sns/oauth2/refresh_token"
;
}
},
/**
* 淘宝
*/
TAOBAO
{
@Override
public
String
authorize
()
{
return
"https://oauth.taobao.com/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth.taobao.com/token"
;
}
@Override
public
String
userInfo
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
},
/**
* Google
*/
GOOGLE
{
@Override
public
String
authorize
()
{
return
"https://accounts.google.com/o/oauth2/v2/auth"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.googleapis.com/oauth2/v4/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://www.googleapis.com/oauth2/v3/userinfo"
;
}
},
/**
* Facebook
*/
FACEBOOK
{
@Override
public
String
authorize
()
{
return
"https://www.facebook.com/v3.3/dialog/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.facebook.com/v3.3/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.facebook.com/v3.3/me"
;
}
},
/**
* 抖音
*/
DOUYIN
{
@Override
public
String
authorize
()
{
return
"https://open.douyin.com/platform/oauth/connect"
;
}
@Override
public
String
accessToken
()
{
return
"https://open.douyin.com/oauth/access_token/"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.douyin.com/oauth/userinfo/"
;
}
@Override
public
String
refresh
()
{
return
"https://open.douyin.com/oauth/refresh_token/"
;
}
},
/**
* 领英
*/
LINKEDIN
{
@Override
public
String
authorize
()
{
return
"https://www.linkedin.com/oauth/v2/authorization"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.linkedin.com/oauth/v2/accessToken"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.linkedin.com/v2/me"
;
}
@Override
public
String
refresh
()
{
return
"https://www.linkedin.com/oauth/v2/accessToken"
;
}
},
/**
* 微软
*/
MICROSOFT
{
@Override
public
String
authorize
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.microsoft.com/v1.0/me"
;
}
@Override
public
String
refresh
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
;
}
},
/**
* 小米
*/
MI
{
@Override
public
String
authorize
()
{
return
"https://account.xiaomi.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://account.xiaomi.com/oauth2/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.account.xiaomi.com/user/profile"
;
}
@Override
public
String
refresh
()
{
return
"https://account.xiaomi.com/oauth2/token"
;
}
},
/**
* 今日头条
*/
TOUTIAO
{
@Override
public
String
authorize
()
{
return
"https://open.snssdk.com/auth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://open.snssdk.com/auth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.snssdk.com/data/user_profile"
;
}
},
/**
* Teambition
*/
TEAMBITION
{
@Override
public
String
authorize
()
{
return
"https://account.teambition.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://account.teambition.com/oauth2/access_token"
;
}
@Override
public
String
refresh
()
{
return
"https://account.teambition.com/oauth2/refresh_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.teambition.com/users/me"
;
}
},
/**
* 人人网
*/
RENREN
{
@Override
public
String
authorize
()
{
return
"https://graph.renren.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
refresh
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.renren.com/v2/user/get"
;
}
},
/**
* Pinterest
*/
PINTEREST
{
@Override
public
String
authorize
()
{
return
"https://api.pinterest.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.pinterest.com/v1/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.pinterest.com/v1/me"
;
}
},
/**
* Stack Overflow
*/
STACK_OVERFLOW
{
@Override
public
String
authorize
()
{
return
"https://stackoverflow.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://stackoverflow.com/oauth/access_token/json"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.stackexchange.com/2.2/me"
;
}
},
/**
* 华为
*
* @since 1.10.0
*/
HUAWEI
{
@Override
public
String
authorize
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.vmall.com/rest.php"
;
}
@Override
public
String
refresh
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/token"
;
}
},
/**
* 企业微信
*
* @since 1.10.0
*/
WECHAT_ENTERPRISE
{
@Override
public
String
authorize
()
{
return
"https://open.work.weixin.qq.com/wwopen/sso/qrConnect"
;
}
@Override
public
String
accessToken
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/gettoken"
;
}
@Override
public
String
userInfo
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"
;
}
},
/**
* 酷家乐
*
* @since 1.11.0
*/
KUJIALE
{
@Override
public
String
authorize
()
{
return
"https://oauth.kujiale.com/oauth2/show"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth.kujiale.com/oauth2/auth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://oauth.kujiale.com/oauth2/openapi/user"
;
}
@Override
public
String
refresh
()
{
return
"https://oauth.kujiale.com/oauth2/auth/token/refresh"
;
}
},
/**
* Gitlab
*
* @since 1.11.0
*/
GITLAB
{
@Override
public
String
authorize
()
{
return
"https://gitlab.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://gitlab.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://gitlab.com/api/v4/user"
;
}
},
/**
* 美团
*
* @since 1.12.0
*/
MEITUAN
{
@Override
public
String
authorize
()
{
return
"https://openapi.waimai.meituan.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.waimai.meituan.com/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.waimai.meituan.com/oauth/userinfo"
;
}
@Override
public
String
refresh
()
{
return
"https://openapi.waimai.meituan.com/oauth/refresh_token"
;
}
},
/**
* 饿了么
* <p>
* 注:集成的是正式环境,非沙箱环境
*
* @since 1.12.0
*/
ELEME
{
@Override
public
String
authorize
()
{
return
"https://open-api.shop.ele.me/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://open-api.shop.ele.me/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open-api.shop.ele.me/api/v1/"
;
}
@Override
public
String
refresh
()
{
return
"https://open-api.shop.ele.me/token"
;
}
}
}
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
02f9f833
...
...
@@ -2,705 +2,55 @@ package me.zhyd.oauth.config;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
/**
* 各api需要的url, 用枚举类分平台类型管理
* OAuth平台的API管理类的统一接口,提供以下接口:
* 1) {@link AuthSource#authorize()}: 获取授权api. 必须实现
* 2) {@link AuthSource#accessToken()}: 获取授权api. 必须实现
* 3) {@link AuthSource#userInfo()}: 获取授权api. 必须实现
* 4) {@link AuthSource#revoke()}: 获取授权api. 非必须实现接口(部分平台不支持)
* 5) {@link AuthSource#refresh()} ()}: 获取授权api. 非必须实现接口(部分平台不支持)
* <p>
* 注:
* ①、如需通过JustAuth扩展实现第三方授权,请参考{@link AuthDefaultSource}自行创建对应的枚举类并实现{@link AuthSource}接口
* ②、如果不是使用的枚举类,那么在授权成功后获取用户信息时,需要单独处理{@link me.zhyd.oauth.model.AuthUser#setSource}字段的赋值
* ③、如果扩展了对应枚举类时,在{@link me.zhyd.oauth.request.AuthRequest#login(AuthCallback)}中可以通过{@code xx.toString()}获取对应的source
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @since 1.0
* @version 1.0
* @date 2019/9/6 21:17
* @since 1.8
*/
public
enum
AuthSource
{
/**
* Github
*/
GITHUB
{
@Override
public
String
authorize
()
{
return
"https://github.com/login/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://github.com/login/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.github.com/user"
;
}
},
/**
* 新浪微博
*/
WEIBO
{
@Override
public
String
authorize
()
{
return
"https://api.weibo.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.weibo.com/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.weibo.com/2/users/show.json"
;
}
},
/**
* gitee
*/
GITEE
{
@Override
public
String
authorize
()
{
return
"https://gitee.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://gitee.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://gitee.com/api/v5/user"
;
}
},
/**
* 钉钉
*/
DINGTALK
{
@Override
public
String
authorize
()
{
return
"https://oapi.dingtalk.com/connect/qrconnect"
;
}
@Override
public
String
accessToken
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
@Override
public
String
userInfo
()
{
return
"https://oapi.dingtalk.com/sns/getuserinfo_bycode"
;
}
},
/**
* 百度
*/
BAIDU
{
@Override
public
String
authorize
()
{
return
"https://openapi.baidu.com/oauth/2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.baidu.com/oauth/2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.baidu.com/rest/2.0/passport/users/getInfo"
;
}
@Override
public
String
revoke
()
{
return
"https://openapi.baidu.com/rest/2.0/passport/auth/revokeAuthorization"
;
}
@Override
public
String
refresh
()
{
return
"https://openapi.baidu.com/oauth/2.0/token"
;
}
},
/**
* csdn
*/
CSDN
{
@Override
public
String
authorize
()
{
return
"https://api.csdn.net/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.csdn.net/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.csdn.net/user/getinfo"
;
}
},
/**
* Coding
*/
CODING
{
@Override
public
String
authorize
()
{
return
"https://coding.net/oauth_authorize.html"
;
}
@Override
public
String
accessToken
()
{
return
"https://coding.net/api/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://coding.net/api/account/current_user"
;
}
},
/**
* 腾讯云开发者平台(coding升级后就变成腾讯云开发者平台了)
*/
TENCENT_CLOUD
{
@Override
public
String
authorize
()
{
return
"https://dev.tencent.com/oauth_authorize.html"
;
}
@Override
public
String
accessToken
()
{
return
"https://dev.tencent.com/api/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://dev.tencent.com/api/account/current_user"
;
}
},
/**
* oschina 开源中国
*/
OSCHINA
{
@Override
public
String
authorize
()
{
return
"https://www.oschina.net/action/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.oschina.net/action/openapi/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://www.oschina.net/action/openapi/user"
;
}
},
/**
* 支付宝
*/
ALIPAY
{
@Override
public
String
authorize
()
{
return
"https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.alipay.com/gateway.do"
;
}
},
/**
* QQ
*/
QQ
{
@Override
public
String
authorize
()
{
return
"https://graph.qq.com/oauth2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.qq.com/oauth2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.qq.com/user/get_user_info"
;
}
@Override
public
String
refresh
()
{
return
"https://graph.qq.com/oauth2.0/token"
;
}
},
/**
* 微信
*/
WECHAT
{
@Override
public
String
authorize
()
{
return
"https://open.weixin.qq.com/connect/qrconnect"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.weixin.qq.com/sns/oauth2/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.weixin.qq.com/sns/userinfo"
;
}
@Override
public
String
refresh
()
{
return
"https://api.weixin.qq.com/sns/oauth2/refresh_token"
;
}
},
/**
* 淘宝
*/
TAOBAO
{
@Override
public
String
authorize
()
{
return
"https://oauth.taobao.com/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth.taobao.com/token"
;
}
@Override
public
String
userInfo
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
},
/**
* Google
*/
GOOGLE
{
@Override
public
String
authorize
()
{
return
"https://accounts.google.com/o/oauth2/v2/auth"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.googleapis.com/oauth2/v4/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://www.googleapis.com/oauth2/v3/userinfo"
;
}
},
/**
* Facebook
*/
FACEBOOK
{
@Override
public
String
authorize
()
{
return
"https://www.facebook.com/v3.3/dialog/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.facebook.com/v3.3/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.facebook.com/v3.3/me"
;
}
},
/**
* 抖音
*/
DOUYIN
{
@Override
public
String
authorize
()
{
return
"https://open.douyin.com/platform/oauth/connect"
;
}
@Override
public
String
accessToken
()
{
return
"https://open.douyin.com/oauth/access_token/"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.douyin.com/oauth/userinfo/"
;
}
@Override
public
String
refresh
()
{
return
"https://open.douyin.com/oauth/refresh_token/"
;
}
},
/**
* 领英
*/
LINKEDIN
{
@Override
public
String
authorize
()
{
return
"https://www.linkedin.com/oauth/v2/authorization"
;
}
@Override
public
String
accessToken
()
{
return
"https://www.linkedin.com/oauth/v2/accessToken"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.linkedin.com/v2/me"
;
}
@Override
public
String
refresh
()
{
return
"https://www.linkedin.com/oauth/v2/accessToken"
;
}
},
/**
* 微软
*/
MICROSOFT
{
@Override
public
String
authorize
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://graph.microsoft.com/v1.0/me"
;
}
@Override
public
String
refresh
()
{
return
"https://login.microsoftonline.com/common/oauth2/v2.0/token"
;
}
},
/**
* 小米
*/
MI
{
@Override
public
String
authorize
()
{
return
"https://account.xiaomi.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://account.xiaomi.com/oauth2/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.account.xiaomi.com/user/profile"
;
}
@Override
public
String
refresh
()
{
return
"https://account.xiaomi.com/oauth2/token"
;
}
},
/**
* 今日头条
*/
TOUTIAO
{
@Override
public
String
authorize
()
{
return
"https://open.snssdk.com/auth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://open.snssdk.com/auth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.snssdk.com/data/user_profile"
;
}
},
/**
* Teambition
*/
TEAMBITION
{
@Override
public
String
authorize
()
{
return
"https://account.teambition.com/oauth2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://account.teambition.com/oauth2/access_token"
;
}
@Override
public
String
refresh
()
{
return
"https://account.teambition.com/oauth2/refresh_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.teambition.com/users/me"
;
}
},
/**
* 人人网
*/
RENREN
{
@Override
public
String
authorize
()
{
return
"https://graph.renren.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
refresh
()
{
return
"https://graph.renren.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.renren.com/v2/user/get"
;
}
},
/**
* Pinterest
*/
PINTEREST
{
@Override
public
String
authorize
()
{
return
"https://api.pinterest.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://api.pinterest.com/v1/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.pinterest.com/v1/me"
;
}
},
/**
* Stack Overflow
*/
STACK_OVERFLOW
{
@Override
public
String
authorize
()
{
return
"https://stackoverflow.com/oauth"
;
}
@Override
public
String
accessToken
()
{
return
"https://stackoverflow.com/oauth/access_token/json"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.stackexchange.com/2.2/me"
;
}
},
/**
* 华为
*
* @since 1.10.0
*/
HUAWEI
{
@Override
public
String
authorize
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://api.vmall.com/rest.php"
;
}
@Override
public
String
refresh
()
{
return
"https://oauth-login.cloud.huawei.com/oauth2/v2/token"
;
}
},
/**
* 企业微信
*
* @since 1.10.0
*/
WECHAT_ENTERPRISE
{
@Override
public
String
authorize
()
{
return
"https://open.work.weixin.qq.com/wwopen/sso/qrConnect"
;
}
@Override
public
String
accessToken
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/gettoken"
;
}
@Override
public
String
userInfo
()
{
return
"https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"
;
}
},
/**
* 酷家乐
*
* @since 1.11.0
*/
KUJIALE
{
@Override
public
String
authorize
()
{
return
"https://oauth.kujiale.com/oauth2/show"
;
}
@Override
public
String
accessToken
()
{
return
"https://oauth.kujiale.com/oauth2/auth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://oauth.kujiale.com/oauth2/openapi/user"
;
}
@Override
public
String
refresh
()
{
return
"https://oauth.kujiale.com/oauth2/auth/token/refresh"
;
}
},
/**
* Gitlab
*
* @since 1.11.0
*/
GITLAB
{
@Override
public
String
authorize
()
{
return
"https://gitlab.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://gitlab.com/oauth/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://gitlab.com/api/v4/user"
;
}
},
/**
* 美团
*
* @since 1.12.0
*/
MEITUAN
{
@Override
public
String
authorize
()
{
return
"https://openapi.waimai.meituan.com/oauth/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://openapi.waimai.meituan.com/oauth/access_token"
;
}
@Override
public
String
userInfo
()
{
return
"https://openapi.waimai.meituan.com/oauth/userinfo"
;
}
@Override
public
String
refresh
()
{
return
"https://openapi.waimai.meituan.com/oauth/refresh_token"
;
}
},
/**
* 饿了么
* <p>
* 注:集成的是正式环境,非沙箱环境
*
* @since 1.12.0
*/
ELEME
{
@Override
public
String
authorize
()
{
return
"https://open-api.shop.ele.me/authorize"
;
}
@Override
public
String
accessToken
()
{
return
"https://open-api.shop.ele.me/token"
;
}
@Override
public
String
userInfo
()
{
return
"https://open-api.shop.ele.me/api/v1/"
;
}
@Override
public
String
refresh
()
{
return
"https://open-api.shop.ele.me/token"
;
}
};
public
interface
AuthSource
{
/**
* 授权的api
*
* @return url
*/
public
abstract
String
authorize
();
String
authorize
();
/**
* 获取accessToken的api
*
* @return url
*/
public
abstract
String
accessToken
();
String
accessToken
();
/**
* 获取用户信息的api
*
* @return url
*/
public
abstract
String
userInfo
();
String
userInfo
();
/**
* 取消授权的api
*
* @return url
*/
public
String
revoke
()
{
default
String
revoke
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
...
...
@@ -709,8 +59,7 @@ public enum AuthSource {
*
* @return url
*/
public
String
refresh
()
{
default
String
refresh
()
{
throw
new
AuthException
(
AuthResponseStatus
.
UNSUPPORTED
);
}
}
src/main/java/me/zhyd/oauth/enums/AuthResponseStatus.java
浏览文件 @
02f9f833
...
...
@@ -21,7 +21,7 @@ public enum AuthResponseStatus {
NOT_IMPLEMENTED
(
5001
,
"Not Implemented"
),
PARAMETER_INCOMPLETE
(
5002
,
"Parameter incomplete"
),
UNSUPPORTED
(
5003
,
"Unsupported operation"
),
NO_AUTH_SOURCE
(
5004
,
"AuthSource cannot be null"
),
NO_AUTH_SOURCE
(
5004
,
"Auth
Default
Source cannot be null"
),
UNIDENTIFIED_PLATFORM
(
5005
,
"Unidentified platform"
),
ILLEGAL_REDIRECT_URI
(
5006
,
"Illegal redirect uri"
),
ILLEGAL_REQUEST
(
5007
,
"Illegal request"
),
...
...
src/main/java/me/zhyd/oauth/model/AuthUser.java
浏览文件 @
02f9f833
package
me.zhyd.oauth.model
;
import
lombok.*
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.enums.AuthUserGender
;
/**
...
...
@@ -61,7 +60,7 @@ public class AuthUser {
/**
* 用户来源
*/
private
AuthSource
source
;
private
String
source
;
/**
* 用户授权的token信息
*/
...
...
src/main/java/me/zhyd/oauth/request/AuthAlipayRequest.java
浏览文件 @
02f9f833
...
...
@@ -9,7 +9,7 @@ import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import
com.alipay.api.response.AlipayUserInfoShareResponse
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -29,14 +29,14 @@ public class AuthAlipayRequest extends AuthDefaultRequest {
private
AlipayClient
alipayClient
;
public
AuthAlipayRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
ALIPAY
);
this
.
alipayClient
=
new
DefaultAlipayClient
(
AuthSource
.
ALIPAY
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
"json"
,
"UTF-8"
,
config
super
(
config
,
Auth
Default
Source
.
ALIPAY
);
this
.
alipayClient
=
new
DefaultAlipayClient
(
Auth
Default
Source
.
ALIPAY
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
"json"
,
"UTF-8"
,
config
.
getAlipayPublicKey
(),
"RSA2"
);
}
public
AuthAlipayRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
ALIPAY
,
authStateCache
);
this
.
alipayClient
=
new
DefaultAlipayClient
(
AuthSource
.
ALIPAY
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
"json"
,
"UTF-8"
,
config
super
(
config
,
Auth
Default
Source
.
ALIPAY
,
authStateCache
);
this
.
alipayClient
=
new
DefaultAlipayClient
(
Auth
Default
Source
.
ALIPAY
.
accessToken
(),
config
.
getClientId
(),
config
.
getClientSecret
(),
"json"
,
"UTF-8"
,
config
.
getAlipayPublicKey
(),
"RSA2"
);
}
...
...
@@ -87,7 +87,7 @@ public class AuthAlipayRequest extends AuthDefaultRequest {
.
location
(
location
)
.
gender
(
AuthUserGender
.
getRealGender
(
response
.
getGender
()))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -25,11 +25,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthBaiduRequest
extends
AuthDefaultRequest
{
public
AuthBaiduRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
BAIDU
);
super
(
config
,
Auth
Default
Source
.
BAIDU
);
}
public
AuthBaiduRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
BAIDU
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
BAIDU
,
authStateCache
);
}
@Override
...
...
@@ -52,7 +52,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"userdetail"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthCodingRequest
extends
AuthDefaultRequest
{
public
AuthCodingRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
CODING
);
super
(
config
,
Auth
Default
Source
.
CODING
);
}
public
AuthCodingRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
CODING
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
CODING
,
authStateCache
);
}
@Override
...
...
@@ -59,7 +59,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.model.AuthUser;
public
class
AuthCsdnRequest
extends
AuthDefaultRequest
{
public
AuthCsdnRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
CSDN
);
super
(
config
,
Auth
Default
Source
.
CSDN
);
}
public
AuthCsdnRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
CSDN
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
CSDN
,
authStateCache
);
}
@Override
...
...
@@ -48,7 +48,7 @@ public class AuthCsdnRequest extends AuthDefaultRequest {
.
blog
(
object
.
getString
(
"website"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthDingTalkRequest.java
浏览文件 @
02f9f833
...
...
@@ -6,7 +6,7 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -24,11 +24,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthDingTalkRequest
extends
AuthDefaultRequest
{
public
AuthDingTalkRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
DINGTALK
);
super
(
config
,
Auth
Default
Source
.
DINGTALK
);
}
public
AuthDingTalkRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
DINGTALK
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
DINGTALK
,
authStateCache
);
}
@Override
...
...
@@ -56,7 +56,7 @@ public class AuthDingTalkRequest extends AuthDefaultRequest {
.
nickname
(
object
.
getString
(
"nick"
))
.
username
(
object
.
getString
(
"nick"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
token
(
token
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthDouyinRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -25,11 +25,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthDouyinRequest
extends
AuthDefaultRequest
{
public
AuthDouyinRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
DOUYIN
);
super
(
config
,
Auth
Default
Source
.
DOUYIN
);
}
public
AuthDouyinRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
DOUYIN
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
DOUYIN
,
authStateCache
);
}
@Override
...
...
@@ -50,7 +50,7 @@ public class AuthDouyinRequest extends AuthDefaultRequest {
.
remark
(
userInfoObject
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthElemeRequest.java
浏览文件 @
02f9f833
...
...
@@ -6,7 +6,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -32,11 +32,11 @@ import java.util.Map;
public
class
AuthElemeRequest
extends
AuthDefaultRequest
{
public
AuthElemeRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
ELEME
);
super
(
config
,
Auth
Default
Source
.
ELEME
);
}
public
AuthElemeRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
ELEME
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
ELEME
,
authStateCache
);
}
@Override
...
...
@@ -107,7 +107,7 @@ public class AuthElemeRequest extends AuthDefaultRequest {
.
nickname
(
result
.
getString
(
"userName"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthFacebookRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthFacebookRequest
extends
AuthDefaultRequest
{
public
AuthFacebookRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
FACEBOOK
);
super
(
config
,
Auth
Default
Source
.
FACEBOOK
);
}
public
AuthFacebookRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
FACEBOOK
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
FACEBOOK
,
authStateCache
);
}
@Override
...
...
@@ -55,7 +55,7 @@ public class AuthFacebookRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGiteeRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -20,11 +20,11 @@ import me.zhyd.oauth.model.AuthUser;
public
class
AuthGiteeRequest
extends
AuthDefaultRequest
{
public
AuthGiteeRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
GITEE
);
super
(
config
,
Auth
Default
Source
.
GITEE
);
}
public
AuthGiteeRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
GITEE
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
GITEE
,
authStateCache
);
}
@Override
...
...
@@ -59,7 +59,7 @@ public class AuthGiteeRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGithubRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -23,11 +23,11 @@ import java.util.Map;
public
class
AuthGithubRequest
extends
AuthDefaultRequest
{
public
AuthGithubRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
GITHUB
);
super
(
config
,
Auth
Default
Source
.
GITHUB
);
}
public
AuthGithubRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
GITHUB
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
GITHUB
,
authStateCache
);
}
@Override
...
...
@@ -63,7 +63,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGitlabRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthGitlabRequest
extends
AuthDefaultRequest
{
public
AuthGitlabRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
GITLAB
);
super
(
config
,
Auth
Default
Source
.
GITLAB
);
}
public
AuthGitlabRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
GITLAB
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
GITLAB
,
authStateCache
);
}
@Override
...
...
@@ -63,7 +63,7 @@ public class AuthGitlabRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"bio"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthGoogleRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -22,11 +22,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthGoogleRequest
extends
AuthDefaultRequest
{
public
AuthGoogleRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
GOOGLE
);
super
(
config
,
Auth
Default
Source
.
GOOGLE
);
}
public
AuthGoogleRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
GOOGLE
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
GOOGLE
,
authStateCache
);
}
@Override
...
...
@@ -60,7 +60,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthHuaweiRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -26,11 +26,11 @@ import static me.zhyd.oauth.enums.AuthResponseStatus.SUCCESS;
public
class
AuthHuaweiRequest
extends
AuthDefaultRequest
{
public
AuthHuaweiRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
HUAWEI
);
super
(
config
,
Auth
Default
Source
.
HUAWEI
);
}
public
AuthHuaweiRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
HUAWEI
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
HUAWEI
,
authStateCache
);
}
/**
...
...
@@ -80,7 +80,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
.
gender
(
gender
)
.
avatar
(
object
.
getString
(
"headPictureURL"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthKujialeRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -24,11 +24,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthKujialeRequest
extends
AuthDefaultRequest
{
public
AuthKujialeRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
KUJIALE
);
super
(
config
,
Auth
Default
Source
.
KUJIALE
);
}
public
AuthKujialeRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
KUJIALE
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
KUJIALE
,
authStateCache
);
}
/**
...
...
@@ -108,7 +108,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
.
avatar
(
resultObject
.
getString
(
"avatar"
))
.
uuid
(
resultObject
.
getString
(
"openId"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthLinkedinRequest.java
浏览文件 @
02f9f833
...
...
@@ -7,7 +7,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.alibaba.fastjson.JSONPath
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -28,11 +28,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthLinkedinRequest
extends
AuthDefaultRequest
{
public
AuthLinkedinRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
LINKEDIN
);
super
(
config
,
Auth
Default
Source
.
LINKEDIN
);
}
public
AuthLinkedinRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
LINKEDIN
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
LINKEDIN
,
authStateCache
);
}
@Override
...
...
@@ -67,7 +67,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
.
email
(
email
)
.
token
(
authToken
)
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
source
(
AuthSource
.
LINKEDIN
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthMeituanRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -24,11 +24,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthMeituanRequest
extends
AuthDefaultRequest
{
public
AuthMeituanRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
MEITUAN
);
super
(
config
,
Auth
Default
Source
.
MEITUAN
);
}
public
AuthMeituanRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
MEITUAN
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
MEITUAN
,
authStateCache
);
}
@Override
...
...
@@ -68,7 +68,7 @@ public class AuthMeituanRequest extends AuthDefaultRequest {
.
avatar
(
object
.
getString
(
"avatar"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthMiRequest.java
浏览文件 @
02f9f833
...
...
@@ -6,7 +6,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -29,11 +29,11 @@ public class AuthMiRequest extends AuthDefaultRequest {
private
static
final
String
PREFIX
=
"&&&START&&&"
;
public
AuthMiRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
MI
);
super
(
config
,
Auth
Default
Source
.
MI
);
}
public
AuthMiRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
MI
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
MI
,
authStateCache
);
}
@Override
...
...
@@ -82,7 +82,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
.
email
(
user
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
// 获取用户邮箱手机号等信息
...
...
src/main/java/me/zhyd/oauth/request/AuthMicrosoftRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -25,11 +25,11 @@ import static me.zhyd.oauth.utils.GlobalAuthUtil.parseQueryToMap;
*/
public
class
AuthMicrosoftRequest
extends
AuthDefaultRequest
{
public
AuthMicrosoftRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
MICROSOFT
);
super
(
config
,
Auth
Default
Source
.
MICROSOFT
);
}
public
AuthMicrosoftRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
MICROSOFT
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
MICROSOFT
,
authStateCache
);
}
@Override
...
...
@@ -91,7 +91,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"mail"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthOschinaRequest
extends
AuthDefaultRequest
{
public
AuthOschinaRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
OSCHINA
);
super
(
config
,
Auth
Default
Source
.
OSCHINA
);
}
public
AuthOschinaRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
OSCHINA
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
OSCHINA
,
authStateCache
);
}
@Override
...
...
@@ -56,7 +56,7 @@ public class AuthOschinaRequest extends AuthDefaultRequest {
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
email
(
object
.
getString
(
"email"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java
浏览文件 @
02f9f833
...
...
@@ -14,7 +14,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
PINTEREST
;
import
static
me
.
zhyd
.
oauth
.
config
.
Auth
Default
Source
.
PINTEREST
;
/**
* Pinterest登录
...
...
@@ -60,7 +60,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
remark
(
userObj
.
getString
(
"bio"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthQqRequest.java
浏览文件 @
02f9f833
...
...
@@ -6,7 +6,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -29,11 +29,11 @@ import java.util.Map;
*/
public
class
AuthQqRequest
extends
AuthDefaultRequest
{
public
AuthQqRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
QQ
);
super
(
config
,
Auth
Default
Source
.
QQ
);
}
public
AuthQqRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
QQ
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
QQ
,
authStateCache
);
}
@Override
...
...
@@ -70,7 +70,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
.
uuid
(
openId
)
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java
浏览文件 @
02f9f833
...
...
@@ -16,7 +16,7 @@ import me.zhyd.oauth.utils.UrlBuilder;
import
java.util.Objects
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
RENREN
;
import
static
me
.
zhyd
.
oauth
.
config
.
Auth
Default
Source
.
RENREN
;
import
static
me
.
zhyd
.
oauth
.
enums
.
AuthResponseStatus
.
SUCCESS
;
/**
...
...
@@ -52,7 +52,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
.
company
(
getCompany
(
userObj
))
.
gender
(
getGender
(
userObj
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthStackOverflowRequest.java
浏览文件 @
02f9f833
...
...
@@ -12,7 +12,7 @@ import me.zhyd.oauth.model.AuthToken;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.UrlBuilder
;
import
static
me
.
zhyd
.
oauth
.
config
.
AuthSource
.
STACK_OVERFLOW
;
import
static
me
.
zhyd
.
oauth
.
config
.
Auth
Default
Source
.
STACK_OVERFLOW
;
import
static
me
.
zhyd
.
oauth
.
utils
.
GlobalAuthUtil
.
parseQueryToMap
;
/**
...
...
@@ -67,7 +67,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
.
blog
(
userObj
.
getString
(
"website_url"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTaobaoRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -22,11 +22,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthTaobaoRequest
extends
AuthDefaultRequest
{
public
AuthTaobaoRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TAOBAO
);
super
(
config
,
Auth
Default
Source
.
TAOBAO
);
}
public
AuthTaobaoRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
TAOBAO
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
TAOBAO
,
authStateCache
);
}
@Override
...
...
@@ -54,7 +54,7 @@ public class AuthTaobaoRequest extends AuthDefaultRequest {
.
nickname
(
nick
)
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -23,11 +23,11 @@ import me.zhyd.oauth.model.AuthUser;
public
class
AuthTeambitionRequest
extends
AuthDefaultRequest
{
public
AuthTeambitionRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TEAMBITION
);
super
(
config
,
Auth
Default
Source
.
TEAMBITION
);
}
public
AuthTeambitionRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
TEAMBITION
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
TEAMBITION
,
authStateCache
);
}
/**
...
...
@@ -75,7 +75,7 @@ public class AuthTeambitionRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOWN
)
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -21,11 +21,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthTencentCloudRequest
extends
AuthDefaultRequest
{
public
AuthTencentCloudRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TENCENT_CLOUD
);
super
(
config
,
Auth
Default
Source
.
TENCENT_CLOUD
);
}
public
AuthTencentCloudRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
TENCENT_CLOUD
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
TENCENT_CLOUD
,
authStateCache
);
}
@Override
...
...
@@ -59,7 +59,7 @@ public class AuthTencentCloudRequest extends AuthDefaultRequest {
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthToutiaoRequest.java
浏览文件 @
02f9f833
...
...
@@ -4,7 +4,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthToutiaoErrorCode
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -22,11 +22,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthToutiaoRequest
extends
AuthDefaultRequest
{
public
AuthToutiaoRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TOUTIAO
);
super
(
config
,
Auth
Default
Source
.
TOUTIAO
);
}
public
AuthToutiaoRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
TOUTIAO
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
TOUTIAO
,
authStateCache
);
}
@Override
...
...
@@ -64,7 +64,7 @@ public class AuthToutiaoRequest extends AuthDefaultRequest {
.
remark
(
user
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
getRealGender
(
user
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeChatEnterpriseRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -24,11 +24,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
*/
public
class
AuthWeChatEnterpriseRequest
extends
AuthDefaultRequest
{
public
AuthWeChatEnterpriseRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
WECHAT_ENTERPRISE
);
super
(
config
,
Auth
Default
Source
.
WECHAT_ENTERPRISE
);
}
public
AuthWeChatEnterpriseRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
WECHAT_ENTERPRISE
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
WECHAT_ENTERPRISE
,
authStateCache
);
}
/**
...
...
@@ -74,7 +74,7 @@ public class AuthWeChatEnterpriseRequest extends AuthDefaultRequest {
.
uuid
(
userId
)
.
gender
(
AuthUserGender
.
getRealGender
(
gender
))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeChatRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -23,11 +23,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
*/
public
class
AuthWeChatRequest
extends
AuthDefaultRequest
{
public
AuthWeChatRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
WECHAT
);
super
(
config
,
Auth
Default
Source
.
WECHAT
);
}
public
AuthWeChatRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
WECHAT
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
WECHAT
,
authStateCache
);
}
/**
...
...
@@ -64,7 +64,7 @@ public class AuthWeChatRequest extends AuthDefaultRequest {
.
uuid
(
openId
)
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/request/AuthWeiboRequest.java
浏览文件 @
02f9f833
...
...
@@ -5,7 +5,7 @@ import cn.hutool.http.HttpResponse;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
@@ -25,11 +25,11 @@ import me.zhyd.oauth.utils.UrlBuilder;
public
class
AuthWeiboRequest
extends
AuthDefaultRequest
{
public
AuthWeiboRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
WEIBO
);
super
(
config
,
Auth
Default
Source
.
WEIBO
);
}
public
AuthWeiboRequest
(
AuthConfig
config
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthSource
.
WEIBO
,
authStateCache
);
super
(
config
,
Auth
Default
Source
.
WEIBO
,
authStateCache
);
}
@Override
...
...
@@ -73,7 +73,7 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
.
remark
(
object
.
getString
(
"description"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"gender"
)))
.
token
(
authToken
)
.
source
(
source
)
.
source
(
source
.
toString
()
)
.
build
();
}
...
...
src/main/java/me/zhyd/oauth/utils/AuthChecker.java
浏览文件 @
02f9f833
package
me.zhyd.oauth.utils
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthDefaultSource
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
...
...
@@ -24,13 +25,13 @@ public class AuthChecker {
*/
public
static
boolean
isSupportedAuth
(
AuthConfig
config
,
AuthSource
source
)
{
boolean
isSupported
=
StringUtils
.
isNotEmpty
(
config
.
getClientId
())
&&
StringUtils
.
isNotEmpty
(
config
.
getClientSecret
())
&&
StringUtils
.
isNotEmpty
(
config
.
getRedirectUri
());
if
(
isSupported
&&
AuthSource
.
ALIPAY
==
source
)
{
if
(
isSupported
&&
Auth
Default
Source
.
ALIPAY
==
source
)
{
isSupported
=
StringUtils
.
isNotEmpty
(
config
.
getAlipayPublicKey
());
}
if
(
isSupported
&&
AuthSource
.
STACK_OVERFLOW
==
source
)
{
if
(
isSupported
&&
Auth
Default
Source
.
STACK_OVERFLOW
==
source
)
{
isSupported
=
StringUtils
.
isNotEmpty
(
config
.
getStackOverflowKey
());
}
if
(
isSupported
&&
AuthSource
.
WECHAT_ENTERPRISE
==
source
){
if
(
isSupported
&&
Auth
Default
Source
.
WECHAT_ENTERPRISE
==
source
){
isSupported
=
StringUtils
.
isNotEmpty
(
config
.
getAgentId
());
}
return
isSupported
;
...
...
@@ -49,11 +50,11 @@ public class AuthChecker {
throw
new
AuthException
(
AuthResponseStatus
.
ILLEGAL_REDIRECT_URI
);
}
// facebook的回调地址必须为https的链接
if
(
AuthSource
.
FACEBOOK
==
source
&&
!
GlobalAuthUtil
.
isHttpsProtocol
(
redirectUri
))
{
if
(
Auth
Default
Source
.
FACEBOOK
==
source
&&
!
GlobalAuthUtil
.
isHttpsProtocol
(
redirectUri
))
{
throw
new
AuthException
(
AuthResponseStatus
.
ILLEGAL_REDIRECT_URI
);
}
// 支付宝在创建回调地址时,不允许使用localhost或者127.0.0.1
if
(
AuthSource
.
ALIPAY
==
source
&&
GlobalAuthUtil
.
isLocalHost
(
redirectUri
))
{
if
(
Auth
Default
Source
.
ALIPAY
==
source
&&
GlobalAuthUtil
.
isLocalHost
(
redirectUri
))
{
throw
new
AuthException
(
AuthResponseStatus
.
ILLEGAL_REDIRECT_URI
);
}
}
...
...
@@ -69,9 +70,9 @@ public class AuthChecker {
*/
public
static
void
checkCode
(
AuthSource
source
,
AuthCallback
callback
)
{
String
code
=
callback
.
getCode
();
if
(
source
==
AuthSource
.
ALIPAY
)
{
if
(
source
==
Auth
Default
Source
.
ALIPAY
)
{
code
=
callback
.
getAuth_code
();
}
else
if
(
source
==
AuthSource
.
HUAWEI
)
{
}
else
if
(
source
==
Auth
Default
Source
.
HUAWEI
)
{
code
=
callback
.
getAuthorization_code
();
}
if
(
StringUtils
.
isEmpty
(
code
))
{
...
...
src/test/java/me/zhyd/oauth/config/AuthExtendSource.java
0 → 100644
浏览文件 @
02f9f833
package
me.zhyd.oauth.config
;
/**
* 测试自定义实现{@link AuthSource}接口后的枚举类
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.12.0
*/
public
enum
AuthExtendSource
implements
AuthSource
{
OTHER
{
/**
* 授权的api
*
* @return url
*/
@Override
public
String
authorize
()
{
return
"http://authorize"
;
}
/**
* 获取accessToken的api
*
* @return url
*/
@Override
public
String
accessToken
()
{
return
"http://accessToken"
;
}
/**
* 获取用户信息的api
*
* @return url
*/
@Override
public
String
userInfo
()
{
return
null
;
}
/**
* 取消授权的api
*
* @return url
*/
@Override
public
String
revoke
()
{
return
null
;
}
/**
* 刷新授权的api
*
* @return url
*/
@Override
public
String
refresh
()
{
return
null
;
}
}
}
src/test/java/me/zhyd/oauth/model/AuthUserTest.java
浏览文件 @
02f9f833
package
me.zhyd.oauth.model
;
import
com.alibaba.fastjson.JSON
;
import
me.zhyd.oauth.config.AuthDefaultSource
;
import
me.zhyd.oauth.config.AuthExtendSource
;
import
me.zhyd.oauth.config.AuthSource
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -28,4 +31,25 @@ public class AuthUserTest {
Assert
.
assertEquals
(
deserializeUser
.
getNickname
(),
"test"
);
}
@Test
public
void
source
()
{
AuthSource
source
=
AuthDefaultSource
.
HUAWEI
;
AuthUser
user
=
AuthUser
.
builder
()
.
source
(
source
.
toString
())
.
build
();
Assert
.
assertEquals
(
user
.
getSource
(),
"HUAWEI"
);
source
=
AuthExtendSource
.
OTHER
;
user
=
AuthUser
.
builder
()
.
source
(
source
.
toString
())
.
build
();
Assert
.
assertEquals
(
user
.
getSource
(),
"OTHER"
);
source
=
AuthDefaultSource
.
HUAWEI
;
Assert
.
assertEquals
(
source
,
AuthDefaultSource
.
HUAWEI
);
source
=
AuthExtendSource
.
OTHER
;
Assert
.
assertEquals
(
source
,
AuthExtendSource
.
OTHER
);
}
}
src/test/java/me/zhyd/oauth/request/AuthExtendRequest.java
0 → 100644
浏览文件 @
02f9f833
package
me.zhyd.oauth.request
;
import
me.zhyd.oauth.cache.AuthStateCache
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthExtendSource
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.enums.AuthUserGender
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
/**
* 测试用自定义扩展的第三方request
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.12.0
*/
public
class
AuthExtendRequest
extends
AuthDefaultRequest
{
public
AuthExtendRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthExtendSource
.
OTHER
);
}
public
AuthExtendRequest
(
AuthConfig
config
,
AuthSource
source
,
AuthStateCache
authStateCache
)
{
super
(
config
,
AuthExtendSource
.
OTHER
,
authStateCache
);
}
/**
* 获取access token
*
* @param authCallback 授权成功后的回调参数
* @return token
* @see AuthDefaultRequest#authorize()
* @see AuthDefaultRequest#authorize(String)
*/
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
return
AuthToken
.
builder
()
.
openId
(
"openId"
)
.
expireIn
(
1000
)
.
idToken
(
"idToken"
)
.
scope
(
"scope"
)
.
refreshToken
(
"refreshToken"
)
.
accessToken
(
"accessToken"
)
.
code
(
"code"
)
.
build
();
}
/**
* 使用token换取用户信息
*
* @param authToken token信息
* @return 用户信息
* @see AuthDefaultRequest#getAccessToken(AuthCallback)
*/
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
return
AuthUser
.
builder
()
.
username
(
"test"
)
.
nickname
(
"test"
)
.
gender
(
AuthUserGender
.
MALE
)
.
token
(
authToken
)
.
source
(
this
.
source
.
toString
())
.
build
();
}
/**
* 撤销授权
*
* @param authToken 登录成功后返回的Token信息
* @return AuthResponse
*/
@Override
public
AuthResponse
revoke
(
AuthToken
authToken
)
{
return
AuthResponse
.
builder
()
.
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
())
.
msg
(
AuthResponseStatus
.
SUCCESS
.
getMsg
())
.
build
();
}
/**
* 刷新access token (续期)
*
* @param authToken 登录成功后返回的Token信息
* @return AuthResponse
*/
@Override
public
AuthResponse
refresh
(
AuthToken
authToken
)
{
return
AuthResponse
.
builder
()
.
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
())
.
data
(
AuthToken
.
builder
()
.
openId
(
"openId"
)
.
expireIn
(
1000
)
.
idToken
(
"idToken"
)
.
scope
(
"scope"
)
.
refreshToken
(
"refreshToken"
)
.
accessToken
(
"accessToken"
)
.
code
(
"code"
)
.
build
())
.
build
();
}
}
src/test/java/me/zhyd/oauth/request/AuthExtendRequestTest.java
0 → 100644
浏览文件 @
02f9f833
package
me.zhyd.oauth.request
;
import
com.alibaba.fastjson.JSON
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.model.AuthCallback
;
import
me.zhyd.oauth.model.AuthResponse
;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.AuthStateUtils
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
* 自定义扩展的第三方request的测试类,用于演示具体的用法
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.12.0
*/
public
class
AuthExtendRequestTest
{
@Test
public
void
authorize
()
{
AuthRequest
request
=
new
AuthExtendRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"http://redirectUri"
)
.
build
());
String
authorize
=
request
.
authorize
(
AuthStateUtils
.
createState
());
System
.
out
.
println
(
authorize
);
Assert
.
assertNotNull
(
authorize
);
}
@Test
public
void
login
()
{
AuthRequest
request
=
new
AuthExtendRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"http://redirectUri"
)
.
build
());
String
state
=
AuthStateUtils
.
createState
();
request
.
authorize
(
state
);
AuthCallback
callback
=
new
AuthCallback
();
callback
.
setCode
(
"code"
);
callback
.
setState
(
state
);
AuthResponse
response
=
request
.
login
(
callback
);
Assert
.
assertNotNull
(
response
);
AuthUser
user
=
(
AuthUser
)
response
.
getData
();
Assert
.
assertNotNull
(
user
);
System
.
out
.
println
(
JSON
.
toJSONString
(
user
));
}
@Test
public
void
revoke
()
{
AuthRequest
request
=
new
AuthExtendRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"http://redirectUri"
)
.
build
());
AuthResponse
response
=
request
.
revoke
(
AuthToken
.
builder
().
build
());
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
JSON
.
toJSONString
(
response
));
}
@Test
public
void
refresh
()
{
AuthRequest
request
=
new
AuthExtendRequest
(
AuthConfig
.
builder
()
.
clientId
(
"clientId"
)
.
clientSecret
(
"clientSecret"
)
.
redirectUri
(
"http://redirectUri"
)
.
build
());
AuthResponse
response
=
request
.
refresh
(
AuthToken
.
builder
().
build
());
Assert
.
assertNotNull
(
response
);
System
.
out
.
println
(
JSON
.
toJSONString
(
response
.
getData
()));
}
}
src/test/java/me/zhyd/oauth/AuthRequestTest.java
→
src/test/java/me/zhyd/oauth/
request/
AuthRequestTest.java
浏览文件 @
02f9f833
package
me.zhyd.oauth
;
package
me.zhyd.oauth
.request
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.model.AuthCallback
;
...
...
src/test/java/me/zhyd/oauth/utils/UrlBuilderTest.java
浏览文件 @
02f9f833
package
me.zhyd.oauth.utils
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.config.Auth
Default
Source
;
import
me.zhyd.oauth.request.AuthWeChatRequest
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -22,7 +22,7 @@ public class UrlBuilderTest {
.
clientSecret
(
"secret-110110110"
)
.
redirectUri
(
"https://xkcoding.com"
)
.
build
();
String
build
=
UrlBuilder
.
fromBaseUrl
(
AuthSource
.
WECHAT
.
authorize
())
String
build
=
UrlBuilder
.
fromBaseUrl
(
Auth
Default
Source
.
WECHAT
.
authorize
())
.
queryParam
(
"appid"
,
config
.
getClientId
())
.
queryParam
(
"redirect_uri"
,
config
.
getRedirectUri
())
.
queryParam
(
"response_type"
,
"code"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录