Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
d5a8ffca
J
JustAuth
项目概览
justauth
/
JustAuth
大约 1 年 前同步成功
通知
383
Star
15212
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,发现更多精彩内容 >>
未验证
提交
d5a8ffca
编写于
1月 26, 2020
作者:
智布道
👁
提交者:
GitHub
1月 26, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #61 from githubeacon/master
增加飞书授权登录
上级
c95c118f
a1d31018
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
128 addition
and
1 deletion
+128
-1
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
+22
-1
src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
+106
-0
未找到文件。
src/main/java/me/zhyd/oauth/config/AuthDefaultSource.java
浏览文件 @
d5a8ffca
...
...
@@ -723,6 +723,27 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
return
"https://api.twitter.com/1.1/users/show.json"
;
}
}
},
FEISHU
{
@Override
public
String
authorize
()
{
return
"https://open.feishu.cn/connect/qrconnect/page/sso/"
;
}
@Override
public
String
accessToken
()
{
return
"https://open.feishu.cn/connect/qrconnect/oauth2/access_token/"
;
}
@Override
public
String
userInfo
()
{
return
"https://open.feishu.cn/connect/qrconnect/oauth2/user_info/"
;
}
@Override
public
String
refresh
()
{
return
"https://open.feishu.cn/connect/qrconnect/oauth2/access_token/"
;
}
}
}
src/main/java/me/zhyd/oauth/request/AuthFeishuRequest.java
0 → 100644
浏览文件 @
d5a8ffca
package
me.zhyd.oauth.request
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpResponse
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
me.zhyd.oauth.config.AuthConfig
;
import
me.zhyd.oauth.config.AuthDefaultSource
;
import
me.zhyd.oauth.enums.AuthResponseStatus
;
import
me.zhyd.oauth.exception.AuthException
;
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.GlobalAuthUtil
;
import
me.zhyd.oauth.utils.UrlBuilder
;
/**
* @author beacon
* @since 1.14.0
*/
public
class
AuthFeishuRequest
extends
AuthDefaultRequest
{
public
AuthFeishuRequest
(
AuthConfig
config
)
{
super
(
config
,
AuthDefaultSource
.
FEISHU
);
}
@Override
protected
AuthToken
getAccessToken
(
AuthCallback
authCallback
)
{
JSONObject
requestObject
=
new
JSONObject
();
requestObject
.
put
(
"app_id"
,
config
.
getClientId
());
requestObject
.
put
(
"app_secret"
,
config
.
getClientSecret
());
requestObject
.
put
(
"grant_type"
,
"authorization_code"
);
requestObject
.
put
(
"code"
,
authCallback
.
getCode
());
HttpResponse
httpResponse
=
HttpRequest
.
post
(
source
.
accessToken
()).
body
(
requestObject
.
toJSONString
(),
"application/json"
).
execute
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
httpResponse
.
body
());
this
.
checkResponse
(
jsonObject
);
return
AuthToken
.
builder
()
.
accessToken
(
jsonObject
.
getString
(
"access_token"
))
.
refreshToken
(
jsonObject
.
getString
(
"refresh_token"
))
.
expireIn
(
jsonObject
.
getIntValue
(
"expires_in"
))
.
tokenType
(
jsonObject
.
getString
(
"token_type"
))
.
openId
(
jsonObject
.
getString
(
"open_id"
))
.
build
();
}
@Override
protected
AuthUser
getUserInfo
(
AuthToken
authToken
)
{
String
accessToken
=
authToken
.
getAccessToken
();
HttpResponse
userInfoResponse
=
HttpRequest
.
get
(
source
.
userInfo
()).
header
(
"Authorization"
,
"Bearer "
+
accessToken
).
execute
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
userInfoResponse
.
body
());
return
AuthUser
.
builder
()
.
avatar
(
jsonObject
.
getString
(
"AvatarUrl"
))
.
username
(
jsonObject
.
getString
(
"Mobile"
))
.
email
(
jsonObject
.
getString
(
"Email"
))
.
nickname
(
"Name"
)
.
build
();
}
@Override
public
AuthResponse
refresh
(
AuthToken
authToken
)
{
JSONObject
requestObject
=
new
JSONObject
();
requestObject
.
put
(
"app_id"
,
config
.
getClientId
());
requestObject
.
put
(
"app_secret"
,
config
.
getClientSecret
());
requestObject
.
put
(
"grant_type"
,
"refresh_token"
);
requestObject
.
put
(
"refresh_token"
,
authToken
.
getRefreshToken
());
HttpResponse
httpResponse
=
HttpRequest
.
post
(
source
.
refresh
())
.
body
(
requestObject
.
toJSONString
(),
"application/json"
)
.
execute
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
httpResponse
.
body
());
this
.
checkResponse
(
jsonObject
);
return
AuthResponse
.
builder
()
.
code
(
AuthResponseStatus
.
SUCCESS
.
getCode
())
.
data
(
AuthToken
.
builder
()
.
accessToken
(
jsonObject
.
getString
(
"access_token"
))
.
refreshToken
(
jsonObject
.
getString
(
"refresh_token"
))
.
expireIn
(
jsonObject
.
getIntValue
(
"expires_in"
))
.
tokenType
(
jsonObject
.
getString
(
"token_type"
))
.
openId
(
jsonObject
.
getString
(
"open_id"
))
.
build
())
.
build
();
}
@Override
public
String
authorize
(
String
state
)
{
return
UrlBuilder
.
fromBaseUrl
(
source
.
authorize
())
.
queryParam
(
"app_id"
,
config
.
getClientId
())
.
queryParam
(
"redirect_uri"
,
GlobalAuthUtil
.
urlEncode
(
config
.
getRedirectUri
()))
.
queryParam
(
"state"
,
getRealState
(
state
))
.
build
();
}
/**
* 校验响应内容是否正确
* @param jsonObject 响应内容
*/
private
void
checkResponse
(
JSONObject
jsonObject
){
if
(
jsonObject
.
getIntValue
(
"code"
)
!=
0
){
throw
new
AuthException
(
jsonObject
.
getString
(
"message"
));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录