Skip to content

Commit 23b8334

Browse files
committed
🐛 Fix a bug.
1 parent be36f3b commit 23b8334

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2GrantType.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,27 @@ public enum Oauth2GrantType {
2525
/**
2626
* Authorization Code Grant
2727
*/
28-
AUTHORIZATION_CODE,
28+
AUTHORIZATION_CODE("authorization_code"),
2929
/**
3030
* Resource Owner Password Credentials Grant
3131
*/
32-
PASSWORD,
32+
PASSWORD("password"),
3333
/**
3434
* Client Credentials Grant
3535
*/
36-
CLIENT_CREDENTIALS,
36+
CLIENT_CREDENTIALS("client_credentials"),
3737
/**
3838
* Refreshing an Access Token
3939
*/
40-
REFRESH_TOKEN
40+
REFRESH_TOKEN("refresh_token");
41+
42+
private final String type;
43+
44+
Oauth2GrantType(String type) {
45+
this.type = type;
46+
}
47+
48+
public String getType() {
49+
return type;
50+
}
4151
}

jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2ResponseType.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ public enum Oauth2ResponseType {
2525
/**
2626
* When authorization code mode or implicit authorization mode is not used, ResponseType needs to be set to {@code none}
2727
*/
28-
NONE,
28+
NONE("none"),
2929
/**
3030
* Authorization Code Grant
3131
*/
32-
CODE,
32+
CODE("code"),
3333
/**
3434
* Implicit Grant
3535
*/
36-
TOKEN
36+
TOKEN("token");
37+
38+
private final String type;
39+
40+
Oauth2ResponseType(String type) {
41+
this.type = type;
42+
}
43+
44+
public String getType() {
45+
return type;
46+
}
3747
}

jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Strategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private String getAuthorizationUrl(OAuthConfig authConfig) {
244244
*/
245245
private String generateAuthorizationCodeGrantUrl(OAuthConfig authConfig) {
246246
Map<String, Object> params = new HashMap<>(6);
247-
params.put("response_type", authConfig.getResponseType());
247+
params.put("response_type", authConfig.getResponseType().getType());
248248
params.put("client_id", authConfig.getClientId());
249249
if (StrUtil.isNotBlank(authConfig.getCallbackUrl())) {
250250
params.put("redirect_uri", authConfig.getCallbackUrl());

jap-oauth2/src/main/java/com/fujieid/jap/oauth2/Oauth2Util.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static void checkOauthConfig(OAuthConfig oAuthConfig) {
138138

139139
if (oAuthConfig.getResponseType() == Oauth2ResponseType.CODE) {
140140
if (oAuthConfig.getGrantType() != Oauth2GrantType.AUTHORIZATION_CODE) {
141-
throw new JapOauth2Exception("Invalid grantType `" + oAuthConfig.getGrantType() + "`. " +
141+
throw new JapOauth2Exception("Invalid grantType `" + oAuthConfig.getGrantType().getType() + "`. " +
142142
"When using authorization code mode, grantType must be `authorization_code`");
143143
}
144144

@@ -168,7 +168,7 @@ public static void checkOauthConfig(OAuthConfig oAuthConfig) {
168168
else {
169169
if (oAuthConfig.getGrantType() != Oauth2GrantType.PASSWORD && oAuthConfig.getGrantType() != Oauth2GrantType.CLIENT_CREDENTIALS) {
170170
throw new JapOauth2Exception("When the response type is none in the oauth2 strategy, a grant type other " +
171-
"than the authorization code must be used: " + oAuthConfig.getGrantType());
171+
"than the authorization code must be used: " + oAuthConfig.getGrantType().getType());
172172
}
173173
if (oAuthConfig.getGrantType() == Oauth2GrantType.PASSWORD) {
174174
if (!StrUtil.isAllNotEmpty(oAuthConfig.getUsername(), oAuthConfig.getPassword())) {

jap-oauth2/src/main/java/com/fujieid/jap/oauth2/token/AccessTokenHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static AccessToken getAccessTokenOfAuthorizationCodeMode(JapHttpRequest
9090

9191
String code = request.getParameter("code");
9292
Map<String, String> params = new HashMap<>(6);
93-
params.put("grant_type", Oauth2GrantType.AUTHORIZATION_CODE.name());
93+
params.put("grant_type", Oauth2GrantType.AUTHORIZATION_CODE.getType());
9494
params.put("code", code);
9595
params.put("client_id", oAuthConfig.getClientId());
9696
params.put("client_secret", oAuthConfig.getClientSecret());
@@ -148,7 +148,7 @@ private static AccessToken getAccessTokenOfImplicitMode(JapHttpRequest request)
148148
*/
149149
private static AccessToken getAccessTokenOfPasswordMode(OAuthConfig oAuthConfig) throws JapOauth2Exception {
150150
Map<String, String> params = new HashMap<>(6);
151-
params.put("grant_type", Oauth2GrantType.PASSWORD.name());
151+
params.put("grant_type", Oauth2GrantType.PASSWORD.getType());
152152
params.put("username", oAuthConfig.getUsername());
153153
params.put("password", oAuthConfig.getPassword());
154154
params.put("client_id", oAuthConfig.getClientId());
@@ -175,7 +175,7 @@ private static AccessToken getAccessTokenOfPasswordMode(OAuthConfig oAuthConfig)
175175
private static AccessToken getAccessTokenOfClientMode(JapHttpRequest request, OAuthConfig oAuthConfig) throws JapOauth2Exception {
176176
throw new JapOauth2Exception("Oauth2Strategy failed to get AccessToken. Grant type of client_credentials type is not supported.");
177177
// Map<String, String> params = Maps.newHashMap();
178-
// params.put("grant_type", Oauth2GrantType.client_credentials.name());
178+
// params.put("grant_type", Oauth2GrantType.CLIENT_CREDENTIALS.getType());
179179
// if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) {
180180
// params.put("scope", String.join(Oauth2Const.SCOPE_SEPARATOR, oAuthConfig.getScopes()));
181181
// }
@@ -192,7 +192,7 @@ private static AccessToken getAccessTokenOfClientMode(JapHttpRequest request, OA
192192

193193
private static AccessToken refreshToken(OAuthConfig oAuthConfig, String refreshToken) {
194194
Map<String, String> params = new HashMap<>(6);
195-
params.put("grant_type", oAuthConfig.getGrantType().name());
195+
params.put("grant_type", oAuthConfig.getGrantType().getType());
196196
params.put("refresh_token", refreshToken);
197197

198198
if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
<properties>
5757
<!-- jap version -->
58-
<revision>1.0.6</revision>
58+
<revision>1.0.7</revision>
5959
<java.version>1.8</java.version>
6060
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6161
<!-- maven -->

0 commit comments

Comments
 (0)