Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
符节科技
Jap
提交
23b8334e
Jap
项目概览
符节科技
/
Jap
8 个月 前同步成功
通知
90
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Jap
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
23b8334e
编写于
11月 20, 2021
作者:
智布道
👁
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
🐛
Fix a bug.
上级
be36f3bd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
15 deletion
+35
-15
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java
...src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java
+14
-4
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java
.../main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java
+13
-3
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java
.../src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java
+1
-1
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java
...uth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java
+2
-2
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java
.../java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java
+4
-4
pom.xml
pom.xml
+1
-1
未找到文件。
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java
浏览文件 @
23b8334e
...
...
@@ -25,17 +25,27 @@ public enum Oauth2GrantType {
/**
* Authorization Code Grant
*/
AUTHORIZATION_CODE
,
AUTHORIZATION_CODE
(
"authorization_code"
)
,
/**
* Resource Owner Password Credentials Grant
*/
PASSWORD
,
PASSWORD
(
"password"
)
,
/**
* Client Credentials Grant
*/
CLIENT_CREDENTIALS
,
CLIENT_CREDENTIALS
(
"client_credentials"
)
,
/**
* Refreshing an Access Token
*/
REFRESH_TOKEN
REFRESH_TOKEN
(
"refresh_token"
);
private
final
String
type
;
Oauth2GrantType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getType
()
{
return
type
;
}
}
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java
浏览文件 @
23b8334e
...
...
@@ -25,13 +25,23 @@ public enum Oauth2ResponseType {
/**
* When authorization code mode or implicit authorization mode is not used, ResponseType needs to be set to {@code none}
*/
NONE
,
NONE
(
"none"
)
,
/**
* Authorization Code Grant
*/
CODE
,
CODE
(
"code"
)
,
/**
* Implicit Grant
*/
TOKEN
TOKEN
(
"token"
);
private
final
String
type
;
Oauth2ResponseType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getType
()
{
return
type
;
}
}
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java
浏览文件 @
23b8334e
...
...
@@ -244,7 +244,7 @@ public class Oauth2Strategy extends AbstractJapStrategy {
*/
private
String
generateAuthorizationCodeGrantUrl
(
OAuthConfig
authConfig
)
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
6
);
params
.
put
(
"response_type"
,
authConfig
.
getResponseType
());
params
.
put
(
"response_type"
,
authConfig
.
getResponseType
()
.
getType
()
);
params
.
put
(
"client_id"
,
authConfig
.
getClientId
());
if
(
StrUtil
.
isNotBlank
(
authConfig
.
getCallbackUrl
()))
{
params
.
put
(
"redirect_uri"
,
authConfig
.
getCallbackUrl
());
...
...
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java
浏览文件 @
23b8334e
...
...
@@ -138,7 +138,7 @@ public class Oauth2Util {
if
(
oAuthConfig
.
getResponseType
()
==
Oauth2ResponseType
.
CODE
)
{
if
(
oAuthConfig
.
getGrantType
()
!=
Oauth2GrantType
.
AUTHORIZATION_CODE
)
{
throw
new
JapOauth2Exception
(
"Invalid grantType `"
+
oAuthConfig
.
getGrantType
()
+
"`. "
+
throw
new
JapOauth2Exception
(
"Invalid grantType `"
+
oAuthConfig
.
getGrantType
()
.
getType
()
+
"`. "
+
"When using authorization code mode, grantType must be `authorization_code`"
);
}
...
...
@@ -168,7 +168,7 @@ public class Oauth2Util {
else
{
if
(
oAuthConfig
.
getGrantType
()
!=
Oauth2GrantType
.
PASSWORD
&&
oAuthConfig
.
getGrantType
()
!=
Oauth2GrantType
.
CLIENT_CREDENTIALS
)
{
throw
new
JapOauth2Exception
(
"When the response type is none in the oauth2 strategy, a grant type other "
+
"than the authorization code must be used: "
+
oAuthConfig
.
getGrantType
());
"than the authorization code must be used: "
+
oAuthConfig
.
getGrantType
()
.
getType
()
);
}
if
(
oAuthConfig
.
getGrantType
()
==
Oauth2GrantType
.
PASSWORD
)
{
if
(!
StrUtil
.
isAllNotEmpty
(
oAuthConfig
.
getUsername
(),
oAuthConfig
.
getPassword
()))
{
...
...
jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java
浏览文件 @
23b8334e
...
...
@@ -90,7 +90,7 @@ public class AccessTokenHelper {
String
code
=
request
.
getParameter
(
"code"
);
Map
<
String
,
String
>
params
=
new
HashMap
<>(
6
);
params
.
put
(
"grant_type"
,
Oauth2GrantType
.
AUTHORIZATION_CODE
.
nam
e
());
params
.
put
(
"grant_type"
,
Oauth2GrantType
.
AUTHORIZATION_CODE
.
getTyp
e
());
params
.
put
(
"code"
,
code
);
params
.
put
(
"client_id"
,
oAuthConfig
.
getClientId
());
params
.
put
(
"client_secret"
,
oAuthConfig
.
getClientSecret
());
...
...
@@ -148,7 +148,7 @@ public class AccessTokenHelper {
*/
private
static
AccessToken
getAccessTokenOfPasswordMode
(
OAuthConfig
oAuthConfig
)
throws
JapOauth2Exception
{
Map
<
String
,
String
>
params
=
new
HashMap
<>(
6
);
params
.
put
(
"grant_type"
,
Oauth2GrantType
.
PASSWORD
.
nam
e
());
params
.
put
(
"grant_type"
,
Oauth2GrantType
.
PASSWORD
.
getTyp
e
());
params
.
put
(
"username"
,
oAuthConfig
.
getUsername
());
params
.
put
(
"password"
,
oAuthConfig
.
getPassword
());
params
.
put
(
"client_id"
,
oAuthConfig
.
getClientId
());
...
...
@@ -175,7 +175,7 @@ public class AccessTokenHelper {
private
static
AccessToken
getAccessTokenOfClientMode
(
JapHttpRequest
request
,
OAuthConfig
oAuthConfig
)
throws
JapOauth2Exception
{
throw
new
JapOauth2Exception
(
"Oauth2Strategy failed to get AccessToken. Grant type of client_credentials type is not supported."
);
// Map<String, String> params = Maps.newHashMap();
// params.put("grant_type", Oauth2GrantType.
client_credentials.nam
e());
// params.put("grant_type", Oauth2GrantType.
CLIENT_CREDENTIALS.getTyp
e());
// if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) {
// params.put("scope", String.join(Oauth2Const.SCOPE_SEPARATOR, oAuthConfig.getScopes()));
// }
...
...
@@ -192,7 +192,7 @@ public class AccessTokenHelper {
private
static
AccessToken
refreshToken
(
OAuthConfig
oAuthConfig
,
String
refreshToken
)
{
Map
<
String
,
String
>
params
=
new
HashMap
<>(
6
);
params
.
put
(
"grant_type"
,
oAuthConfig
.
getGrantType
().
nam
e
());
params
.
put
(
"grant_type"
,
oAuthConfig
.
getGrantType
().
getTyp
e
());
params
.
put
(
"refresh_token"
,
refreshToken
);
if
(
ArrayUtil
.
isNotEmpty
(
oAuthConfig
.
getScopes
()))
{
...
...
pom.xml
浏览文件 @
23b8334e
...
...
@@ -55,7 +55,7 @@
<properties>
<!-- jap version -->
<revision>
1.0.
6
</revision>
<revision>
1.0.
7
</revision>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<!-- maven -->
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录