Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
579c6ece
J
JustAuth
项目概览
justauth
/
JustAuth
大约 1 年 前同步成功
通知
368
Star
15210
Fork
2709
代码
文件
提交
分支
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
579c6ece
编写于
2月 24, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
支持腾讯云开发者平台(Coding升级变为了腾讯云开发者平台)
上级
299d90b8
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
129 addition
and
3 deletion
+129
-3
README.md
README.md
+7
-0
src/main/java/me/zhyd/oauth/consts/ApiUrlConst.java
src/main/java/me/zhyd/oauth/consts/ApiUrlConst.java
+15
-0
src/main/java/me/zhyd/oauth/model/AuthSource.java
src/main/java/me/zhyd/oauth/model/AuthSource.java
+1
-0
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
+3
-2
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
...n/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
+59
-0
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
+6
-0
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
+38
-1
未找到文件。
README.md
浏览文件 @
579c6ece
...
...
@@ -27,6 +27,7 @@
<td
align=
"center"
width=
"200"
><a
href=
"https://developer.baidu.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.csdn.net/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://coding.net"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://dev.tencent.com/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://www.oschina.net"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://connect.qq.com/devuser.html#/"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"30"
></a></td>
<td
align=
"center"
width=
"200"
><a
href=
"https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN"
><img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"30"
></a></td>
...
...
@@ -41,6 +42,7 @@
<td
align=
"center"
width=
"200"
><a
href=
"#授权百度"
>
百度
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权csdn"
>
CSDN
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权coding"
>
Coding
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权腾讯云开发者平台"
title=
"coding升级后就变成腾讯云开发者平台了"
>
腾讯云开发者平台
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权oschina"
>
OSChina
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权qq"
>
QQ
</a></td>
<td
align=
"center"
width=
"200"
><a
href=
"#授权微信"
>
微信
</a></td>
...
...
@@ -89,6 +91,7 @@ authRequest.login("code");
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/baidu.png"
width=
"20"
>
|
[
AuthBaiduRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthBaiduRequest.java
)
|
<a
href=
"https://developer.baidu.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/csdn.png"
width=
"20"
>
|
[
AuthCsdnRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCsdnRequest.java
)
| 待续 |
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/coding.png"
width=
"25"
>
|
[
AuthCodingRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
)
|
<a
href=
"https://open.coding.net/references/oauth/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/tencent_cloud.png"
width=
"25"
>
|
[
AuthTencentCloudRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
)
|
<a
href=
"https://dev.tencent.com/help/doc/faq/b4e5b7aee786/oauth"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/oschinas.png"
width=
"20"
>
|
[
AuthOschinaRequest
](
https://gitee.com/yadong.zhang/JustAuth/blob/master/src/main/java/me/zhyd/oauth/request/AuthOschinaRequest.java
)
|
<a
href=
"https://www.oschina.net/openapi/docs/openapi_user"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/qq.png"
width=
"20"
>
| AuthQqRequest |
<a
href=
"https://connect.qq.com/"
target=
"_blank"
>
参考文档
</a>
|
|
<img
src=
"https://gitee.com/yadong.zhang/static/raw/master/JustAuth/wechats.png"
width=
"20"
>
| AuthWechatRequest | 待续 |
...
...
@@ -123,6 +126,10 @@ authRequest.login("code");
待续
#### 授权腾讯云开发者平台
待续
#### 授权oschina
待续
...
...
src/main/java/me/zhyd/oauth/consts/ApiUrlConst.java
浏览文件 @
579c6ece
...
...
@@ -116,6 +116,21 @@ public class ApiUrlConst {
*/
public
static
final
String
CODING_AUTHORIZE_URL
=
"https://coding.net/oauth_authorize.html"
;
/**
* 获取腾讯云开发者平台 access_token的地址(coding升级后就变成腾讯云开发者平台了)
*/
public
static
final
String
TENCENT_ACCESS_TOKEN_URL
=
"https://dev.tencent.com/api/oauth/access_token"
;
/**
* 获取腾讯云开发者平台用户信息的地址(coding升级后就变成腾讯云开发者平台了)
*/
public
static
final
String
TENCENT_USER_INFO_URL
=
"https://dev.tencent.com/api/account/current_user"
;
/**
* 获取腾讯云开发者平台授权地址(coding升级后就变成腾讯云开发者平台了)
*/
public
static
final
String
TENCENT_AUTHORIZE_URL
=
"https://dev.tencent.com/oauth_authorize.html"
;
/**
* 获取oschina access_token的地址
*/
...
...
src/main/java/me/zhyd/oauth/model/AuthSource.java
浏览文件 @
579c6ece
...
...
@@ -16,6 +16,7 @@ public enum AuthSource {
CSDN
,
CODING
,
OSCHINA
,
TENCEN_CLOUD
,
QQ
,
WECHAT
,
...
...
src/main/java/me/zhyd/oauth/request/AuthCodingRequest.java
浏览文件 @
579c6ece
...
...
@@ -26,7 +26,7 @@ public class AuthCodingRequest extends BaseAuthRequest {
@Override
protected
String
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getCodingAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
HttpResponse
response
=
HttpRequest
.
pos
t
(
accessTokenUrl
).
execute
();
HttpResponse
response
=
HttpRequest
.
ge
t
(
accessTokenUrl
).
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
accessTokenObject
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from coding using code ["
+
code
+
"]"
);
...
...
@@ -41,9 +41,10 @@ public class AuthCodingRequest extends BaseAuthRequest {
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
object
.
getString
(
"msg"
));
}
object
=
object
.
getJSONObject
(
"data"
);
return
AuthUser
.
builder
()
.
username
(
object
.
getString
(
"name"
))
.
avatar
(
object
.
getString
(
"avatar"
))
.
avatar
(
"https://coding.net/"
+
object
.
getString
(
"avatar"
))
.
blog
(
"https://coding.net/"
+
object
.
getString
(
"path"
))
.
nickname
(
object
.
getString
(
"name"
))
.
company
(
object
.
getString
(
"company"
))
...
...
src/main/java/me/zhyd/oauth/request/AuthTencentCloudRequest.java
0 → 100644
浏览文件 @
579c6ece
package
me.zhyd.oauth.request
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.AuthSource
;
import
me.zhyd.oauth.model.AuthUser
;
import
me.zhyd.oauth.model.AuthUserGender
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/2/23 15:48
* @since 1.8
*/
public
class
AuthTencentCloudRequest
extends
BaseAuthRequest
{
public
AuthTencentCloudRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TENCEN_CLOUD
);
}
@Override
protected
String
getAccessToken
(
String
code
)
{
String
accessTokenUrl
=
UrlBuilder
.
getTencentCloudAccessTokenUrl
(
config
.
getClientId
(),
config
.
getClientSecret
(),
code
);
HttpResponse
response
=
HttpRequest
.
get
(
accessTokenUrl
).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
"Unable to get token from tencent cloud using code ["
+
code
+
"]: "
+
object
.
get
(
"msg"
));
}
return
object
.
getString
(
"access_token"
);
}
@Override
protected
AuthUser
getUserInfo
(
String
accessToken
)
{
HttpResponse
response
=
HttpRequest
.
get
(
UrlBuilder
.
getTencentCloudUserInfoUrl
(
accessToken
)).
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
if
(
object
.
getIntValue
(
"code"
)
!=
0
)
{
throw
new
AuthException
(
object
.
getString
(
"msg"
));
}
object
=
object
.
getJSONObject
(
"data"
);
return
AuthUser
.
builder
()
.
username
(
object
.
getString
(
"name"
))
.
avatar
(
"https://dev.tencent.com/"
+
object
.
getString
(
"avatar"
))
.
blog
(
"https://dev.tencent.com/"
+
object
.
getString
(
"path"
))
.
nickname
(
object
.
getString
(
"name"
))
.
company
(
object
.
getString
(
"company"
))
.
location
(
object
.
getString
(
"location"
))
.
gender
(
AuthUserGender
.
getRealGender
(
object
.
getString
(
"sex"
)))
.
email
(
object
.
getString
(
"email"
))
.
remark
(
object
.
getString
(
"slogan"
))
.
accessToken
(
accessToken
)
.
source
(
AuthSource
.
TENCEN_CLOUD
)
.
build
();
}
}
src/main/java/me/zhyd/oauth/request/BaseAuthRequest.java
浏览文件 @
579c6ece
...
...
@@ -73,6 +73,12 @@ public abstract class BaseAuthRequest implements AuthRequest {
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
QQ:
break
;
case
WECHAT:
...
...
src/main/java/me/zhyd/oauth/utils/UrlBuilder.java
浏览文件 @
579c6ece
...
...
@@ -41,7 +41,11 @@ public class UrlBuilder {
private
static
final
String
CODING_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
CODING_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
CODING_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}"
;
private
static
final
String
CODING_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user"
;
private
static
final
String
TENCENT_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}"
;
private
static
final
String
TENCENT_USER_INFO_PATTERN
=
"{0}?access_token={1}"
;
private
static
final
String
TENCENT_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&response_type=code&redirect_uri={2}&scope=user"
;
private
static
final
String
OSCHINA_ACCESS_TOKEN_PATTERN
=
"{0}?client_id={1}&client_secret={2}&grant_type=authorization_code&code={3}&redirect_uri={4}&dataType=json"
;
private
static
final
String
OSCHINA_USER_INFO_PATTERN
=
"{0}?access_token={1}&dataType=json"
;
...
...
@@ -283,6 +287,39 @@ public class UrlBuilder {
return
MessageFormat
.
format
(
CODING_AUTHORIZE_PATTERN
,
ApiUrlConst
.
CODING_AUTHORIZE_URL
,
clientId
,
redirectUrl
);
}
/**
* 获取腾讯云开发者平台 token的接口地址
*
* @param clientId coding应用的App Key
* @param clientSecret coding应用的App Secret
* @param code coding授权前的code,用来换token
* @return full url
*/
public
static
String
getTencentCloudAccessTokenUrl
(
String
clientId
,
String
clientSecret
,
String
code
)
{
return
MessageFormat
.
format
(
TENCENT_ACCESS_TOKEN_PATTERN
,
ApiUrlConst
.
TENCENT_ACCESS_TOKEN_URL
,
clientId
,
clientSecret
,
code
);
}
/**
* 获取腾讯云开发者平台用户详情的接口地址
*
* @param token coding 应用的token
* @return full url
*/
public
static
String
getTencentCloudUserInfoUrl
(
String
token
)
{
return
MessageFormat
.
format
(
TENCENT_USER_INFO_PATTERN
,
ApiUrlConst
.
TENCENT_USER_INFO_URL
,
token
);
}
/**
* 获取腾讯云开发者平台授权地址
*
* @param clientId coding 应用的Client ID
* @param redirectUrl coding 应用授权成功后的回调地址
* @return full url
*/
public
static
String
getTencentCloudAuthorizeUrl
(
String
clientId
,
String
redirectUrl
)
{
return
MessageFormat
.
format
(
TENCENT_AUTHORIZE_PATTERN
,
ApiUrlConst
.
TENCENT_AUTHORIZE_URL
,
clientId
,
redirectUrl
);
}
/**
* 获取oschina token的接口地址
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录