Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
justauth
JustAuth
提交
ca8e194c
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看板
未验证
提交
ca8e194c
编写于
2月 26, 2023
作者:
智布道
👁
提交者:
GitHub
2月 26, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #159 from cheng521521/master
添加飞书单元测试
上级
81ea4b16
7a9d6024
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
84 addition
and
0 deletion
+84
-0
src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java
...est/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java
+84
-0
未找到文件。
src/test/java/me/zhyd/oauth/request/AuthFeiShuRequestTest.java
0 → 100644
浏览文件 @
ca8e194c
package
me.zhyd.oauth.request
;
import
com.alibaba.fastjson.JSON
;
import
me.zhyd.oauth.config.AuthConfig
;
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.AuthStateUtils
;
import
org.junit.Assert
;
import
org.junit.Test
;
/**
* @ClassName AuthFeiShuRequestTest
* @Author jackcheng(chen781142032@gamil.com)
* @version 1.0
* @since 1.16.5
* @Date 2022/10/1 11:23
* @Description 飞书第三方登录测试类 先执行authorize()方法获取state以及authorizeUrl,
* 然后在浏览器中打开authorizeUrl,登录成功后会跳转到redirectUri,并且会携带code和state参数
**/
public
class
AuthFeiShuRequestTest
{
@Test
public
void
authorize
()
{
AuthRequest
request
=
new
AuthFeishuRequest
(
AuthConfig
.
builder
()
.
clientId
(
"your App ID"
)
.
clientSecret
(
"your App Secret"
)
.
redirectUri
(
"you set redirect uri"
)
.
build
());
String
state
=
AuthStateUtils
.
createState
();
System
.
out
.
println
(
"state=="
+
state
);
String
authorize
=
request
.
authorize
(
state
);
System
.
out
.
println
(
"authorize=="
+
authorize
);
Assert
.
assertNotNull
(
authorize
);
}
@Test
public
void
getAccessTokenAndUserInfo
()
{
AuthRequest
request
=
new
AuthFeishuRequest
(
AuthConfig
.
builder
()
.
clientId
(
"your App ID"
)
.
clientSecret
(
"your App Secret"
)
.
redirectUri
(
"you set redirect uri"
)
.
build
());
String
state
=
"your state"
;
AuthCallback
callback
=
AuthCallback
.
builder
()
.
code
(
"your code"
)
.
state
(
state
)
.
build
();
AuthToken
accessToken
=
((
AuthFeishuRequest
)
request
).
getAccessToken
(
callback
);
Assert
.
assertNotNull
(
accessToken
);
System
.
out
.
println
(
"token=="
+
accessToken
.
getAccessToken
());
AuthUser
userInfo
=
((
AuthFeishuRequest
)
request
).
getUserInfo
(
accessToken
);
Assert
.
assertNotNull
(
userInfo
);
System
.
out
.
println
(
"userInfo=="
+
JSON
.
toJSONString
(
userInfo
));
}
@Test
public
void
login
()
{
AuthRequest
request
=
new
AuthFeishuRequest
(
AuthConfig
.
builder
()
.
clientId
(
"your App ID"
)
.
clientSecret
(
"your App Secret"
)
.
redirectUri
(
"you set redirect uri"
)
.
build
());
String
state
=
"your state"
;
request
.
authorize
(
state
);
AuthCallback
callback
=
AuthCallback
.
builder
()
.
code
(
"your code"
)
.
state
(
state
)
.
build
();
AuthResponse
response
=
request
.
login
(
callback
);
Assert
.
assertNotNull
(
response
);
AuthUser
user
=
(
AuthUser
)
response
.
getData
();
Assert
.
assertNotNull
(
user
);
System
.
out
.
println
(
JSON
.
toJSONString
(
user
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录