Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
54e97b0e
J
JustAuth
项目概览
justauth
/
JustAuth
1 年多 前同步成功
通知
391
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看板
提交
54e97b0e
编写于
5月 18, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
♻
优化获取authorize的代码
上级
aa187dd1
变更
18
显示空白变更内容
内联
并排
Showing
18 changed file
with
342 addition
and
48 deletion
+342
-48
src/main/java/me/zhyd/oauth/authorization/AlipayAuthorization.java
...java/me/zhyd/oauth/authorization/AlipayAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/Authorization.java
src/main/java/me/zhyd/oauth/authorization/Authorization.java
+15
-0
src/main/java/me/zhyd/oauth/authorization/AuthorizationFactory.java
...ava/me/zhyd/oauth/authorization/AuthorizationFactory.java
+74
-0
src/main/java/me/zhyd/oauth/authorization/BaiduAuthorization.java
.../java/me/zhyd/oauth/authorization/BaiduAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/CodingAuthorization.java
...java/me/zhyd/oauth/authorization/CodingAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/CsdnAuthorization.java
...n/java/me/zhyd/oauth/authorization/CsdnAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/DingTalkAuthorization.java
...va/me/zhyd/oauth/authorization/DingTalkAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/GiteeAuthorization.java
.../java/me/zhyd/oauth/authorization/GiteeAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/GithubAuthorization.java
...java/me/zhyd/oauth/authorization/GithubAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/OschinaAuthorization.java
...ava/me/zhyd/oauth/authorization/OschinaAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/QqAuthorization.java
...ain/java/me/zhyd/oauth/authorization/QqAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/TaobaoAuthorization.java
...java/me/zhyd/oauth/authorization/TaobaoAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/TencentCloudAuthorization.java
...e/zhyd/oauth/authorization/TencentCloudAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/WeChatAuthorization.java
...java/me/zhyd/oauth/authorization/WeChatAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/authorization/WeiboAuthorization.java
.../java/me/zhyd/oauth/authorization/WeiboAuthorization.java
+19
-0
src/main/java/me/zhyd/oauth/model/AuthSource.java
src/main/java/me/zhyd/oauth/model/AuthSource.java
+2
-0
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+2
-48
src/main/java/me/zhyd/oauth/request/ResponseStatus.java
src/main/java/me/zhyd/oauth/request/ResponseStatus.java
+2
-0
未找到文件。
src/main/java/me/zhyd/oauth/authorization/AlipayAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 支付宝授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
AlipayAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getAlipayAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/Authorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
/**
* 授权接口,用来获取具体第三方平台的授权地址
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
interface
Authorization
{
String
getAuthorizeUrl
(
AuthConfig
config
);
}
src/main/java/me/zhyd/oauth/authorization/AuthorizationFactory.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.request.ResponseStatus
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 授权工厂类,负责创建指定平台的授权类获取授权地址
* <p>
* 使用策略模式 + 工厂模式 避免大量的if else(swatch)操作
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
AuthorizationFactory
{
private
static
Map
<
String
,
Authorization
>
authorizationMap
=
new
HashMap
<>();
private
static
boolean
loader
=
false
;
private
AuthorizationFactory
()
{
}
/**
* 根据第三方平台,获取具体的授权工具
*
* @param source 平台
* @return 具体的Authorization
*/
public
static
Authorization
getAuthorize
(
AuthSource
source
)
{
if
(
null
==
source
)
{
throw
new
AuthException
(
ResponseStatus
.
NO_AUTH_SOURCE
);
}
registerAllAuthorize
();
Authorization
authorization
=
authorizationMap
.
get
(
source
.
toString
());
if
(
null
==
authorization
)
{
throw
new
AuthException
(
ResponseStatus
.
UNIDENTIFIED_PLATFORM
);
}
return
authorization
;
}
/**
* 将所有Authorize的实现类注册到authorizeMap中,
* 每次增加新的平台都需要在这儿添加注册代码
*/
private
static
void
registerAllAuthorize
()
{
if
(
loader
)
{
return
;
}
AuthorizationFactory
.
register
(
AuthSource
.
ALIPAY
,
new
AlipayAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
BAIDU
,
new
BaiduAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
CODING
,
new
CodingAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
CSDN
,
new
CsdnAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
DINGTALK
,
new
DingTalkAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
GITEE
,
new
GiteeAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
GITHUB
,
new
GithubAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
OSCHINA
,
new
OschinaAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
QQ
,
new
QqAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
TAOBAO
,
new
TaobaoAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
TENCEN_CLOUD
,
new
TencentCloudAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
WECHAT
,
new
WeChatAuthorization
());
AuthorizationFactory
.
register
(
AuthSource
.
WEIBO
,
new
WeiboAuthorization
());
loader
=
true
;
}
private
static
void
register
(
AuthSource
authSource
,
Authorization
authorization
)
{
authorizationMap
.
put
(
authSource
.
toString
(),
authorization
);
}
}
src/main/java/me/zhyd/oauth/authorization/BaiduAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 百度授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
BaiduAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getBaiduAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/CodingAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* Coding授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
CodingAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getCodingAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/CsdnAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* CSDN授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
CsdnAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getCsdnAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/DingTalkAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 钉钉授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
DingTalkAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getDingTalkQrConnectUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/GiteeAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 码云授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
GiteeAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getGiteeAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/GithubAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* Github授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
GithubAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getGithubAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/OschinaAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 开源中国授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
OschinaAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getOschinaAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/QqAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* QQ授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
QqAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getQqAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/TaobaoAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 淘宝授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
TaobaoAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getTaobaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/TencentCloudAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 腾讯云授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
TencentCloudAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getTencentCloudAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/WeChatAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 微信授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
WeChatAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getWeChatAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/authorization/WeiboAuthorization.java
0 → 100644
浏览文件 @
54e97b0e
package
me.zhyd.oauth.authorization
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* 微博授权
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
WeiboAuthorization
implements
Authorization
{
@Override
public
String
getAuthorizeUrl
(
AuthConfig
config
)
{
return
UrlBuilder
.
getWeiboAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
}
}
src/main/java/me/zhyd/oauth/model/AuthSource.java
浏览文件 @
54e97b0e
package
me.zhyd.oauth.model
;
/**
* 授权来源(平台)
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
...
...
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
54e97b0e
package
me.zhyd.oauth.request
;
import
lombok.Data
;
import
me.zhyd.oauth.authorization.AuthorizationFactory
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthResponse
;
...
...
@@ -8,7 +9,6 @@ import me.zhyd.oauth.model.AuthSource;
import
me.zhyd.oauth.model.AuthToken
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.utils.AuthConfigChecker
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
...
...
@@ -44,52 +44,6 @@ public abstract class BaseAuthRequest implements AuthRequest {
@Override
public
String
authorize
()
{
String
authorizeUrl
=
null
;
switch
(
source
)
{
case
WEIBO:
authorizeUrl
=
UrlBuilder
.
getWeiboAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
BAIDU:
authorizeUrl
=
UrlBuilder
.
getBaiduAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
DINGTALK:
authorizeUrl
=
UrlBuilder
.
getDingTalkQrConnectUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
GITEE:
authorizeUrl
=
UrlBuilder
.
getGiteeAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
GITHUB:
authorizeUrl
=
UrlBuilder
.
getGithubAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
CSDN:
authorizeUrl
=
UrlBuilder
.
getCsdnAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
CODING:
authorizeUrl
=
UrlBuilder
.
getCodingAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
TENCEN_CLOUD:
authorizeUrl
=
UrlBuilder
.
getTencentCloudAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
OSCHINA:
authorizeUrl
=
UrlBuilder
.
getOschinaAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
ALIPAY:
authorizeUrl
=
UrlBuilder
.
getAlipayAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
QQ:
authorizeUrl
=
UrlBuilder
.
getQqAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
WECHAT:
authorizeUrl
=
UrlBuilder
.
getWeChatAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
TAOBAO:
authorizeUrl
=
UrlBuilder
.
getTaobaoAuthorizeUrl
(
config
.
getClientId
(),
config
.
getRedirectUri
());
break
;
case
GOOGLE:
break
;
default
:
break
;
}
return
authorizeUrl
;
return
AuthorizationFactory
.
getAuthorize
(
source
).
getAuthorizeUrl
(
config
);
}
}
src/main/java/me/zhyd/oauth/request/ResponseStatus.java
浏览文件 @
54e97b0e
...
...
@@ -11,6 +11,8 @@ public enum ResponseStatus {
NOT_IMPLEMENTED
(
5001
,
"Not Implemented"
),
PARAMETER_INCOMPLETE
(
5002
,
"Parameter incomplete"
),
UNSUPPORTED
(
5003
,
"Unsupported operation"
),
NO_AUTH_SOURCE
(
5004
,
"AuthSource cannot be null"
),
UNIDENTIFIED_PLATFORM
(
5005
,
"Unidentified platform"
),
;
private
int
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录