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

🎨 完成小米的自定义 scope

上级 df11fcbd
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 AuthMiScope implements AuthScope {
/**
* {@code scope} 含义,以{@code description} 为准
*/
profile("user/profile", "获取用户的基本信息", true),
OPENID("user/openIdV2", "获取用户的OpenID", true),
PHONE_EMAIL("user/phoneAndEmail", "获取用户的手机号和邮箱", true);
private String scope;
private String description;
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());
}
}
package me.zhyd.oauth.request;
import com.alibaba.fastjson.JSONObject;
import me.zhyd.oauth.utils.HttpUtils;
import com.xkcoding.http.constants.Constants;
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.AuthMiScope;
import me.zhyd.oauth.exception.AuthException;
import me.zhyd.oauth.log.Log;
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.HttpUtils;
import me.zhyd.oauth.utils.UrlBuilder;
import java.text.MessageFormat;
......@@ -128,7 +129,7 @@ public class AuthMiRequest extends AuthDefaultRequest {
.queryParam("response_type", "code")
.queryParam("client_id", config.getClientId())
.queryParam("redirect_uri", config.getRedirectUri())
.queryParam("scope", "user/profile%20user/openIdV2%20user/phoneAndEmail")
.queryParam("scope", this.getScopes(" ", true, AuthMiScope.getDefaultScopes()))
.queryParam("skip_confirm", "false")
.queryParam("state", getRealState(state))
.build();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册