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

🔥 优化代码

上级 272d1ac8
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 边度平台 OAuth 授权范围 * 边度平台 OAuth 授权范围
* *
...@@ -32,18 +27,4 @@ public enum AuthBaiduScope implements AuthScope { ...@@ -32,18 +27,4 @@ public enum AuthBaiduScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthBaiduScope[] scopes = AuthBaiduScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthBaiduScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthBaiduScope.values()).map(AuthBaiduScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Coding平台 OAuth 授权范围 * Coding平台 OAuth 授权范围
* *
...@@ -33,18 +28,4 @@ public enum AuthCodingScope implements AuthScope { ...@@ -33,18 +28,4 @@ public enum AuthCodingScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthCodingScope[] scopes = AuthCodingScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthCodingScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthCodingScope.values()).map(AuthCodingScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Facebook 平台 OAuth 授权范围 * Facebook 平台 OAuth 授权范围
* *
...@@ -42,18 +37,4 @@ public enum AuthFacebookScope implements AuthScope { ...@@ -42,18 +37,4 @@ public enum AuthFacebookScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthFacebookScope[] scopes = AuthFacebookScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthFacebookScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthFacebookScope.values()).map(AuthFacebookScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Gitee 平台 OAuth 授权范围 * Gitee 平台 OAuth 授权范围
* *
...@@ -38,18 +33,4 @@ public enum AuthGiteeScope implements AuthScope { ...@@ -38,18 +33,4 @@ public enum AuthGiteeScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthGiteeScope[] scopes = AuthGiteeScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthGiteeScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthGiteeScope.values()).map(AuthGiteeScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 边度平台 OAuth 授权范围 * 边度平台 OAuth 授权范围
* *
...@@ -56,18 +51,4 @@ public enum AuthGithubScope implements AuthScope { ...@@ -56,18 +51,4 @@ public enum AuthGithubScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthGithubScope[] scopes = AuthGithubScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthGithubScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthGithubScope.values()).map(AuthGithubScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Gitlab 平台 OAuth 授权范围 * Gitlab 平台 OAuth 授权范围
* *
...@@ -39,18 +34,4 @@ public enum AuthGitlabScope implements AuthScope { ...@@ -39,18 +34,4 @@ public enum AuthGitlabScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthGitlabScope[] scopes = AuthGitlabScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthGitlabScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthGitlabScope.values()).map(AuthGitlabScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,7 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,7 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -286,20 +285,6 @@ public enum AuthGoogleScope implements AuthScope { ...@@ -286,20 +285,6 @@ public enum AuthGoogleScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthGoogleScope[] scopes = AuthGoogleScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthGoogleScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthGoogleScope.values()).map(AuthGoogleScope::getScope).collect(Collectors.toList());
}
public static List<String> getAdminDirectoryScopes() { public static List<String> getAdminDirectoryScopes() {
return Arrays.stream(new AuthGoogleScope[]{ return Arrays.stream(new AuthGoogleScope[]{
......
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 华为平台 OAuth 授权范围 * 华为平台 OAuth 授权范围
* *
...@@ -48,18 +43,4 @@ public enum AuthHuaweiScope implements AuthScope { ...@@ -48,18 +43,4 @@ public enum AuthHuaweiScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthHuaweiScope[] scopes = AuthHuaweiScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthHuaweiScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthHuaweiScope.values()).map(AuthHuaweiScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 京东平台 OAuth 授权范围 * 京东平台 OAuth 授权范围
* *
...@@ -28,18 +23,4 @@ public enum AuthJdScope implements AuthScope { ...@@ -28,18 +23,4 @@ public enum AuthJdScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthJdScope[] scopes = AuthJdScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthJdScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthJdScope.values()).map(AuthJdScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 酷家乐平台 OAuth 授权范围 * 酷家乐平台 OAuth 授权范围
* *
...@@ -30,18 +25,4 @@ public enum AuthKujialeScope implements AuthScope { ...@@ -30,18 +25,4 @@ public enum AuthKujialeScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthKujialeScope[] scopes = AuthKujialeScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthKujialeScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthKujialeScope.values()).map(AuthKujialeScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 领英平台 OAuth 授权范围 * 领英平台 OAuth 授权范围
* *
...@@ -45,18 +40,4 @@ public enum AuthLinkedinScope implements AuthScope { ...@@ -45,18 +40,4 @@ public enum AuthLinkedinScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthLinkedinScope[] scopes = AuthLinkedinScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthLinkedinScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthLinkedinScope.values()).map(AuthLinkedinScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 小米平台 OAuth 授权范围 * 小米平台 OAuth 授权范围
* *
...@@ -30,18 +25,4 @@ public enum AuthMiScope implements AuthScope { ...@@ -30,18 +25,4 @@ public enum AuthMiScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthMiScope[] scopes = AuthMiScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthMiScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthMiScope.values()).map(AuthMiScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 微软平台 OAuth 授权范围 * 微软平台 OAuth 授权范围
* *
...@@ -69,18 +64,4 @@ public enum AuthMicrosoftScope implements AuthScope { ...@@ -69,18 +64,4 @@ public enum AuthMicrosoftScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthMicrosoftScope[] scopes = AuthMicrosoftScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthMicrosoftScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthMicrosoftScope.values()).map(AuthMicrosoftScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Pinterest 平台 OAuth 授权范围 * Pinterest 平台 OAuth 授权范围
* *
...@@ -32,18 +27,4 @@ public enum AuthPinterestScope implements AuthScope { ...@@ -32,18 +27,4 @@ public enum AuthPinterestScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthPinterestScope[] scopes = AuthPinterestScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthPinterestScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthPinterestScope.values()).map(AuthPinterestScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* QQ 平台 OAuth 授权范围 * QQ 平台 OAuth 授权范围
* *
...@@ -37,18 +32,4 @@ public enum AuthQqScope implements AuthScope { ...@@ -37,18 +32,4 @@ public enum AuthQqScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthQqScope[] scopes = AuthQqScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthQqScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthQqScope.values()).map(AuthQqScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 人人平台 OAuth 授权范围 * 人人平台 OAuth 授权范围
* *
...@@ -57,18 +52,4 @@ public enum AuthRenrenScope implements AuthScope { ...@@ -57,18 +52,4 @@ public enum AuthRenrenScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthRenrenScope[] scopes = AuthRenrenScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthRenrenScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthRenrenScope.values()).map(AuthRenrenScope::getScope).collect(Collectors.toList());
}
} }
...@@ -9,5 +9,17 @@ package me.zhyd.oauth.enums.scope; ...@@ -9,5 +9,17 @@ package me.zhyd.oauth.enums.scope;
*/ */
public interface AuthScope { public interface AuthScope {
/**
* 获取字符串 {@code scope},对应为各平台实际使用的 {@code scope}
*
* @return String
*/
String getScope(); String getScope();
/**
* 判断当前 {@code scope} 是否为各平台默认启用的
*
* @return boolean
*/
boolean isDefault();
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* Stackoverflow 平台 OAuth 授权范围 * Stackoverflow 平台 OAuth 授权范围
* *
...@@ -31,18 +26,4 @@ public enum AuthStackoverflowScope implements AuthScope { ...@@ -31,18 +26,4 @@ public enum AuthStackoverflowScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthStackoverflowScope[] scopes = AuthStackoverflowScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthStackoverflowScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthStackoverflowScope.values()).map(AuthStackoverflowScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 微信公众平台 OAuth 授权范围 * 微信公众平台 OAuth 授权范围
* *
...@@ -28,18 +23,4 @@ public enum AuthWechatMpScope implements AuthScope { ...@@ -28,18 +23,4 @@ public enum AuthWechatMpScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthWechatMpScope[] scopes = AuthWechatMpScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthWechatMpScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthWechatMpScope.values()).map(AuthWechatMpScope::getScope).collect(Collectors.toList());
}
} }
...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope; ...@@ -3,11 +3,6 @@ package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 微博平台 OAuth 授权范围 * 微博平台 OAuth 授权范围
* *
...@@ -36,18 +31,4 @@ public enum AuthWeiboScope implements AuthScope { ...@@ -36,18 +31,4 @@ public enum AuthWeiboScope implements AuthScope {
private String description; private String description;
private boolean isDefault; private boolean isDefault;
public static List<AuthScope> getDefaultScopes() {
AuthWeiboScope[] scopes = AuthWeiboScope.values();
List<AuthScope> defaultScopes = new ArrayList<>();
for (AuthWeiboScope scope : scopes) {
if (scope.isDefault()) {
defaultScopes.add(scope);
}
}
return defaultScopes;
}
public static List<String> listScope() {
return Arrays.stream(AuthWeiboScope.values()).map(AuthWeiboScope::getScope).collect(Collectors.toList());
}
} }
...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.StringUtils; import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -105,7 +106,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest { ...@@ -105,7 +106,7 @@ public class AuthBaiduRequest extends AuthDefaultRequest {
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("display", "popup") .queryParam("display", "popup")
.queryParam("scope", this.getScopes(" ", true, AuthBaiduScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthBaiduScope.values())))
.build(); .build();
} }
......
...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -88,7 +89,7 @@ public class AuthCodingRequest extends AuthDefaultRequest { ...@@ -88,7 +89,7 @@ public class AuthCodingRequest extends AuthDefaultRequest {
.queryParam("response_type", "code") .queryParam("response_type", "code")
.queryParam("client_id", config.getClientId()) .queryParam("client_id", config.getClientId())
.queryParam("redirect_uri", config.getRedirectUri()) .queryParam("redirect_uri", config.getRedirectUri())
.queryParam("scope", this.getScopes(" ", true, AuthCodingScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthCodingScope.values())))
.queryParam("state", getRealState(state)) .queryParam("state", getRealState(state))
.build(); .build();
} }
......
...@@ -6,7 +6,6 @@ import me.zhyd.oauth.cache.AuthStateCache; ...@@ -6,7 +6,6 @@ import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig; import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthSource; import me.zhyd.oauth.config.AuthSource;
import me.zhyd.oauth.enums.AuthResponseStatus; import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.scope.AuthScope;
import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.log.Log; import me.zhyd.oauth.log.Log;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
...@@ -15,7 +14,6 @@ import me.zhyd.oauth.model.AuthToken; ...@@ -15,7 +14,6 @@ import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.*; import me.zhyd.oauth.utils.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -277,16 +275,13 @@ public abstract class AuthDefaultRequest implements AuthRequest { ...@@ -277,16 +275,13 @@ public abstract class AuthDefaultRequest implements AuthRequest {
* @return String * @return String
* @since 1.16.7 * @since 1.16.7
*/ */
protected String getScopes(String separator, boolean encode, List<AuthScope> defaultScopes) { protected String getScopes(String separator, boolean encode, List<String> defaultScopes) {
List<String> scopes = config.getScopes(); List<String> scopes = config.getScopes();
if (null == scopes || scopes.isEmpty()) { if (null == scopes || scopes.isEmpty()) {
if (null == defaultScopes || defaultScopes.isEmpty()) { if (null == defaultScopes || defaultScopes.isEmpty()) {
return ""; return "";
} }
scopes = new ArrayList<>(); scopes = defaultScopes;
for (AuthScope defaultScope : defaultScopes) {
scopes.add(defaultScope.getScope());
}
} }
if (null == separator) { if (null == separator) {
// 默认为空格 // 默认为空格
......
...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -106,7 +107,7 @@ public class AuthFacebookRequest extends AuthDefaultRequest { ...@@ -106,7 +107,7 @@ public class AuthFacebookRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthFacebookScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthFacebookScope.values())))
.build(); .build();
} }
} }
...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -84,7 +85,7 @@ public class AuthGiteeRequest extends AuthDefaultRequest { ...@@ -84,7 +85,7 @@ public class AuthGiteeRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(" ", true, AuthGiteeScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthGiteeScope.values())))
.build(); .build();
} }
} }
...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -84,7 +85,7 @@ public class AuthGithubRequest extends AuthDefaultRequest { ...@@ -84,7 +85,7 @@ public class AuthGithubRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(" ", true, AuthGithubScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthGithubScope.values())))
.build(); .build();
} }
......
...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -10,6 +10,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -89,7 +90,7 @@ public class AuthGitlabRequest extends AuthDefaultRequest { ...@@ -89,7 +90,7 @@ public class AuthGitlabRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes("+", false, AuthGitlabScope.getDefaultScopes())) .queryParam("scope", this.getScopes("+", false, AuthScopeUtils.getDefaultScopes(AuthGitlabScope.values())))
.build(); .build();
} }
......
...@@ -11,6 +11,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -11,6 +11,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -76,7 +77,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest { ...@@ -76,7 +77,7 @@ public class AuthGoogleRequest extends AuthDefaultRequest {
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("access_type", "offline") .queryParam("access_type", "offline")
.queryParam("scope", this.getScopes(" ", false, AuthGoogleScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", false, AuthScopeUtils.getDefaultScopes(AuthGoogleScope.values())))
.build(); .build();
} }
......
...@@ -11,6 +11,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -11,6 +11,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -132,7 +133,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest { ...@@ -132,7 +133,7 @@ public class AuthHuaweiRequest extends AuthDefaultRequest {
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("access_type", "offline") .queryParam("access_type", "offline")
.queryParam("scope", this.getScopes(" ", true, AuthHuaweiScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthHuaweiScope.values())))
.build(); .build();
} }
......
...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -137,7 +138,7 @@ public class AuthJdRequest extends AuthDefaultRequest { ...@@ -137,7 +138,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
.queryParam("app_key", config.getClientId()) .queryParam("app_key", config.getClientId())
.queryParam("response_type", "code") .queryParam("response_type", "code")
.queryParam("redirect_uri", config.getRedirectUri()) .queryParam("redirect_uri", config.getRedirectUri())
.queryParam("scope", this.getScopes(" ", true, AuthJdScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthJdScope.values())))
.queryParam("state", getRealState(state)) .queryParam("state", getRealState(state))
.build(); .build();
} }
......
...@@ -11,6 +11,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -11,6 +11,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -41,7 +42,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest { ...@@ -41,7 +42,7 @@ public class AuthKujialeRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthKujialeScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthKujialeScope.values())))
.build(); .build();
} }
......
...@@ -14,6 +14,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -14,6 +14,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -199,7 +200,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest { ...@@ -199,7 +200,7 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(" ", false, AuthLinkedinScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", false, AuthScopeUtils.getDefaultScopes(AuthLinkedinScope.values())))
.build(); .build();
} }
......
...@@ -14,6 +14,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -14,6 +14,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -127,7 +128,7 @@ public class AuthMiRequest extends AuthDefaultRequest { ...@@ -127,7 +128,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("skip_confirm", "false") .queryParam("skip_confirm", "false")
.queryParam("scope", this.getScopes(" ", true, AuthMiScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthMiScope.values())))
.build(); .build();
} }
......
...@@ -14,6 +14,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -14,6 +14,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -125,7 +126,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest { ...@@ -125,7 +126,7 @@ public class AuthMicrosoftRequest extends AuthDefaultRequest {
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("response_mode", "query") .queryParam("response_mode", "query")
.queryParam("scope", this.getScopes(" ", true, AuthMicrosoftScope.getDefaultScopes())) .queryParam("scope", this.getScopes(" ", true, AuthScopeUtils.getDefaultScopes(AuthMicrosoftScope.values())))
.build(); .build();
} }
......
...@@ -9,6 +9,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -9,6 +9,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -85,7 +86,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest { ...@@ -85,7 +86,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthPinterestScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthPinterestScope.values())))
.build(); .build();
} }
......
...@@ -12,10 +12,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -12,10 +12,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.*;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
import java.util.Map; import java.util.Map;
...@@ -130,7 +127,7 @@ public class AuthQqRequest extends AuthDefaultRequest { ...@@ -130,7 +127,7 @@ public class AuthQqRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthQqScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthQqScope.values())))
.build(); .build();
} }
} }
...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -123,7 +124,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest { ...@@ -123,7 +124,7 @@ public class AuthRenrenRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthRenrenScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthRenrenScope.values())))
.build(); .build();
} }
} }
...@@ -12,6 +12,7 @@ import me.zhyd.oauth.exception.AuthException; ...@@ -12,6 +12,7 @@ import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.model.AuthCallback; import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -87,7 +88,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest { ...@@ -87,7 +88,7 @@ public class AuthStackOverflowRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthStackoverflowScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthStackoverflowScope.values())))
.build(); .build();
} }
......
...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -12,6 +12,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.AuthScopeUtils;
import me.zhyd.oauth.utils.GlobalAuthUtils; import me.zhyd.oauth.utils.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder; import me.zhyd.oauth.utils.UrlBuilder;
...@@ -124,7 +125,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest { ...@@ -124,7 +125,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest {
.queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri())) .queryParam("redirect_uri", GlobalAuthUtils.urlEncode(config.getRedirectUri()))
.queryParam("response_type", "code") .queryParam("response_type", "code")
.queryParam("state", getRealState(state).concat("#wechat_redirect")) .queryParam("state", getRealState(state).concat("#wechat_redirect"))
.queryParam("scope", this.getScopes(",", false, AuthWechatMpScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWechatMpScope.values())))
.build(); .build();
} }
......
...@@ -13,10 +13,7 @@ import me.zhyd.oauth.model.AuthCallback; ...@@ -13,10 +13,7 @@ import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthResponse;
import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.utils.HttpUtils; import me.zhyd.oauth.utils.*;
import me.zhyd.oauth.utils.IpUtils;
import me.zhyd.oauth.utils.StringUtils;
import me.zhyd.oauth.utils.UrlBuilder;
/** /**
...@@ -97,7 +94,7 @@ public class AuthWeiboRequest extends AuthDefaultRequest { ...@@ -97,7 +94,7 @@ public class AuthWeiboRequest extends AuthDefaultRequest {
@Override @Override
public String authorize(String state) { public String authorize(String state) {
return UrlBuilder.fromBaseUrl(super.authorize(state)) return UrlBuilder.fromBaseUrl(super.authorize(state))
.queryParam("scope", this.getScopes(",", false, AuthWeiboScope.getDefaultScopes())) .queryParam("scope", this.getScopes(",", false, AuthScopeUtils.getDefaultScopes(AuthWeiboScope.values())))
.build(); .build();
} }
......
package me.zhyd.oauth.utils;
import me.zhyd.oauth.enums.scope.AuthScope;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Scope 工具类,提供对 scope 类的统一操作
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.15.7
*/
public class AuthScopeUtils {
/**
* 获取 {@link me.zhyd.oauth.enums.scope.AuthScope} 数组中所有的被标记为 {@code default} 的 scope
*
* @param scopes scopes
* @return List
*/
public static List<String> getDefaultScopes(AuthScope[] scopes) {
if (null == scopes || scopes.length == 0) {
return null;
}
return Arrays.stream(scopes)
.filter((AuthScope::isDefault))
.map(AuthScope::getScope)
.collect(Collectors.toList());
}
/**
* 从 {@link me.zhyd.oauth.enums.scope.AuthScope} 数组中获取实际的 scope 字符串
*
* @param scopes 可变参数,支持传任意 {@link me.zhyd.oauth.enums.scope.AuthScope}
* @return List
*/
public static List<String> getScopes(AuthScope... scopes) {
if (null == scopes || scopes.length == 0) {
return null;
}
return Arrays.stream(scopes).map(AuthScope::getScope).collect(Collectors.toList());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册