🎨 完成京东·宙斯的自定义 scope

This commit is contained in:
yadong.zhang 2020-07-03 18:28:34 +08:00
parent 8440b0606e
commit 2d52e010da
2 changed files with 48 additions and 2 deletions

View File

@ -0,0 +1,45 @@
package me.zhyd.oauth.enums.scope;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 京东平台 OAuth 授权范围
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0.0
* @since 1.0.0
*/
@Getter
@AllArgsConstructor
public enum AuthJdScope implements AuthScope {
/**
* {@code scope} 含义{@code description} 为准
*/
SNSAPI_BASE("snsapi_base", "基础授权", true);
private String scope;
private String description;
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());
}
}

View File

@ -1,18 +1,19 @@
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.cache.AuthStateCache;
import me.zhyd.oauth.config.AuthConfig;
import me.zhyd.oauth.config.AuthDefaultSource;
import me.zhyd.oauth.enums.AuthResponseStatus;
import me.zhyd.oauth.enums.AuthUserGender;
import me.zhyd.oauth.enums.scope.AuthJdScope;
import me.zhyd.oauth.exception.AuthException;
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.GlobalAuthUtils;
import me.zhyd.oauth.utils.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder;
import java.time.LocalDateTime;
@ -136,7 +137,7 @@ public class AuthJdRequest extends AuthDefaultRequest {
.queryParam("app_key", config.getClientId())
.queryParam("response_type", "code")
.queryParam("redirect_uri", config.getRedirectUri())
.queryParam("scope", "snsapi_base")
.queryParam("scope", this.getScopes(" ", true, AuthJdScope.getDefaultScopes()))
.queryParam("state", getRealState(state))
.build();
}