提交 23b8334e 编写于 作者: 智布道's avatar 智布道 👁

🐛 Fix a bug.

上级 be36f3bd
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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());
......
......@@ -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())) {
......
......@@ -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.name());
params.put("grant_type", Oauth2GrantType.AUTHORIZATION_CODE.getType());
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.name());
params.put("grant_type", Oauth2GrantType.PASSWORD.getType());
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.name());
// params.put("grant_type", Oauth2GrantType.CLIENT_CREDENTIALS.getType());
// 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().name());
params.put("grant_type", oAuthConfig.getGrantType().getType());
params.put("refresh_token", refreshToken);
if (ArrayUtil.isNotEmpty(oAuthConfig.getScopes())) {
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册