Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
My_csdo
JustAuth
提交
a1d31018
J
JustAuth
项目概览
My_csdo
/
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,发现更多精彩内容 >>
提交
a1d31018
编写于
12月 30, 2019
作者:
B
beacon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加飞书授权登录
上级
2038f24b
变更
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
浏览文件 @
a1d31018
...
@@ -723,6 +723,27 @@ public enum AuthDefaultSource implements AuthSource {
...
@@ -723,6 +723,27 @@ public enum AuthDefaultSource implements AuthSource {
public
String
userInfo
()
{
public
String
userInfo
()
{
return
"https://api.twitter.com/1.1/users/show.json"
;
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
浏览文件 @
a1d31018
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录