Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BI8CLL灬
JustAuth
提交
e0242f99
J
JustAuth
项目概览
BI8CLL灬
/
JustAuth
与 Fork 源项目一致
Fork自
justauth / JustAuth
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
e0242f99
编写于
7月 17, 2019
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
集成teambition
上级
59b5ba5a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
150 addition
and
1 deletion
+150
-1
src/main/java/me/zhyd/oauth/config/AuthSource.java
src/main/java/me/zhyd/oauth/config/AuthSource.java
+1
-1
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
...ain/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
+106
-0
src/main/java/me/zhyd/oauth/url/AuthTeambitionUrlBuilder.java
...main/java/me/zhyd/oauth/url/AuthTeambitionUrlBuilder.java
+43
-0
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthSource.java
浏览文件 @
e0242f99
...
...
@@ -442,7 +442,7 @@ public enum AuthSource {
@Override
public
String
userInfo
()
{
return
"https://a
ccount
.teambition.com/users/me"
;
return
"https://a
pi
.teambition.com/users/me"
;
}
};
...
...
src/main/java/me/zhyd/oauth/request/AuthTeambitionRequest.java
0 → 100644
浏览文件 @
e0242f99
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.config.AuthSource
;
import
me.zhyd.oauth.exception.AuthException
;
import
me.zhyd.oauth.model.*
;
import
me.zhyd.oauth.url.AuthTeambitionUrlBuilder
;
/**
* 微信登录
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @since 1.8
*/
public
class
AuthTeambitionRequest
extends
AuthDefaultRequest
{
public
AuthTeambitionRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthSource
.
TEAMBITION
,
new
AuthTeambitionUrlBuilder
());
}
/**
* @param authCallback 回调返回的参数
* @return 所有信息
*/
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
String
accessTokenUrl
=
this
.
urlBuilder
.
getAccessTokenUrl
(
authCallback
.
getCode
());
HttpResponse
response
=
HttpRequest
.
post
(
accessTokenUrl
)
.
form
(
"client_id"
,
config
.
getClientId
())
.
form
(
"client_secret"
,
config
.
getClientSecret
())
.
form
(
"code"
,
authCallback
.
getCode
())
.
form
(
"grant_type"
,
"code"
)
.
execute
();
JSONObject
accessTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
accessTokenObject
);
return
AuthToken
.
builder
()
.
accessToken
(
accessTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
accessTokenObject
.
getString
(
"refresh_token"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
response
=
HttpRequest
.
get
(
this
.
urlBuilder
.
getUserInfoUrl
(
null
))
.
header
(
"Authorization"
,
"OAuth2 "
+
accessToken
)
.
execute
();
JSONObject
object
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
object
);
authToken
.
setUid
(
object
.
getString
(
"_id"
));
return
AuthUser
.
builder
()
.
uuid
(
object
.
getString
(
"_id"
))
.
username
(
object
.
getString
(
"name"
))
.
nickname
(
object
.
getString
(
"name"
))
.
avatar
(
object
.
getString
(
"avatarUrl"
))
.
blog
(
object
.
getString
(
"website"
))
.
location
(
object
.
getString
(
"location"
))
.
email
(
object
.
getString
(
"email"
))
.
gender
(
AuthUserGender
.
UNKNOW
)
.
token
(
authToken
)
.
source
(
AuthSource
.
TEAMBITION
)
.
build
();
}
@Override
public
AuthResponse
refresh
(
AuthToken
oldToken
)
{
String
uid
=
oldToken
.
getUid
();
String
refreshToken
=
oldToken
.
getRefreshToken
();
String
refreshTokenUrl
=
this
.
urlBuilder
.
getRefreshUrl
(
refreshToken
);
HttpResponse
response
=
HttpRequest
.
post
(
refreshTokenUrl
)
.
form
(
"_userId"
,
uid
)
.
form
(
"refresh_token"
,
refreshToken
)
.
execute
();
JSONObject
refreshTokenObject
=
JSONObject
.
parseObject
(
response
.
body
());
this
.
checkResponse
(
refreshTokenObject
);
return
AuthResponse
.
builder
()
.
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
())
.
data
(
AuthToken
.
builder
()
.
accessToken
(
refreshTokenObject
.
getString
(
"access_token"
))
.
refreshToken
(
refreshTokenObject
.
getString
(
"refresh_token"
))
.
build
())
.
build
();
}
/**
* 检查响应内容是否正确
*
* @param object 请求响应内容
*/
private
void
checkResponse
(
JSONObject
object
)
{
if
((
object
.
containsKey
(
"message"
)
&&
object
.
containsKey
(
"name"
)))
{
throw
new
AuthException
(
object
.
getString
(
"name"
)
+
", "
+
object
.
getString
(
"message"
));
}
}
}
src/main/java/me/zhyd/oauth/url/AuthTeambitionUrlBuilder.java
0 → 100644
浏览文件 @
e0242f99
package
me.zhyd.oauth.url
;
import
me.zhyd.oauth.config.AuthSource
;
import
me.zhyd.oauth.url.entity.AuthUserInfoEntity
;
import
java.text.MessageFormat
;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @website https://www.zhyd.me
* @date 2019/7/16 22:22
* @since 1.8
*/
public
class
AuthTeambitionUrlBuilder
extends
AuthDefaultUrlBuilder
{
private
static
final
String
TEAMBITION_AUTHORIZE_PATTERN
=
"{0}?client_id={1}&redirect_uri={2}&state={3}&response_type=code"
;
@Override
public
String
getAccessTokenUrl
(
String
code
)
{
return
AuthSource
.
TEAMBITION
.
accessToken
();
}
@Override
public
String
getUserInfoUrl
(
AuthUserInfoEntity
userInfoEntity
)
{
return
AuthSource
.
TEAMBITION
.
userInfo
();
}
@Override
public
String
getAuthorizeUrl
()
{
return
MessageFormat
.
format
(
TEAMBITION_AUTHORIZE_PATTERN
,
AuthSource
.
TEAMBITION
.
authorize
(),
config
.
getClientId
(),
config
.
getRedirectUri
(),
this
.
getRealState
(
config
.
getState
()));
}
@Override
public
String
getRefreshUrl
(
String
refreshToken
)
{
return
AuthSource
.
TEAMBITION
.
refresh
();
}
@Override
public
String
getRevokeUrl
(
String
accessToken
)
{
return
null
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录