From a85d9797a7c3cddb0bc482d22677dbf876853680 Mon Sep 17 00:00:00 2001 From: "yadong.zhang" Date: Sat, 4 Jul 2020 10:16:16 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=AE=8C=E6=88=90=20Pinterest=20?= =?UTF-8?q?=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=20scope?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/enums/scope/AuthPinterestScope.java | 49 +++++++++++++++++++ .../oauth/request/AuthPinterestRequest.java | 5 +- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/main/java/me/zhyd/oauth/enums/scope/AuthPinterestScope.java diff --git a/src/main/java/me/zhyd/oauth/enums/scope/AuthPinterestScope.java b/src/main/java/me/zhyd/oauth/enums/scope/AuthPinterestScope.java new file mode 100644 index 0000000..ee105f3 --- /dev/null +++ b/src/main/java/me/zhyd/oauth/enums/scope/AuthPinterestScope.java @@ -0,0 +1,49 @@ +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; + +/** + * Pinterest 平台 OAuth 授权范围 + * + * @author yadong.zhang (yadong.zhang0415(a)gmail.com) + * @version 1.0.0 + * @since 1.0.0 + */ +@Getter +@AllArgsConstructor +public enum AuthPinterestScope implements AuthScope { + + /** + * {@code scope} 含义,以{@code description} 为准 + */ + READ_PUBLIC("read_public", "Use GET method on a user’s Pins, boards.", true), + WRITE_PUBLIC("write_public", "Use PATCH, POST and DELETE methods on a user’s Pins and boards.", false), + READ_RELATIONSHIPS("read_relationships", "Use GET method on a user’s follows and followers (on boards, users and interests).", false), + WRITE_RELATIONSHIPS("write_relationships", "Use PATCH, POST and DELETE methods on a user’s follows and followers (on boards, users and interests).", false), + ; + + private String scope; + private String description; + private boolean isDefault; + + public static List getDefaultScopes() { + AuthPinterestScope[] scopes = AuthPinterestScope.values(); + List defaultScopes = new ArrayList<>(); + for (AuthPinterestScope scope : scopes) { + if (scope.isDefault()) { + defaultScopes.add(scope); + } + } + return defaultScopes; + } + + public static List listScope() { + return Arrays.stream(AuthPinterestScope.values()).map(AuthPinterestScope::getScope).collect(Collectors.toList()); + } +} diff --git a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java index dc1d223..ff72d8c 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthPinterestRequest.java @@ -1,14 +1,15 @@ 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.enums.AuthUserGender; +import me.zhyd.oauth.enums.scope.AuthPinterestScope; import me.zhyd.oauth.exception.AuthException; import me.zhyd.oauth.model.AuthCallback; 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.util.Objects; @@ -87,7 +88,7 @@ public class AuthPinterestRequest extends AuthDefaultRequest { .queryParam("response_type", "code") .queryParam("client_id", config.getClientId()) .queryParam("redirect_uri", config.getRedirectUri()) - .queryParam("scope", "read_public") + .queryParam("scope", this.getScopes(",", false, AuthPinterestScope.getDefaultScopes())) .queryParam("state", getRealState(state)) .build(); } -- GitLab