From 9e6a4c61b0c51c6d67bd6213e6c0019750bcc2cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E5=AD=90=E5=81=A5?= <793705503@qq.com> Date: Thu, 28 May 2020 14:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=BA=E4=BA=BA=E7=BD=91?= =?UTF-8?q?=E8=BF=94=E5=9B=9Etoken=E4=B8=AD=E6=9C=89=E7=AB=96=E7=BA=BF?= =?UTF-8?q?=EF=BC=88|=EF=BC=89=E6=B2=A1=E6=9C=89=E8=BF=9B=E8=A1=8CURL=20En?= =?UTF-8?q?code=E6=93=8D=E4=BD=9C=E5=AF=BC=E8=87=B4=E7=9A=84url=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhyd/oauth/request/AuthRenrenRequest.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java index 889a418..8acf853 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthRenrenRequest.java @@ -13,6 +13,8 @@ import me.zhyd.oauth.model.AuthToken; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.utils.UrlBuilder; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.Objects; import static me.zhyd.oauth.config.AuthDefaultSource.RENREN; @@ -70,13 +72,17 @@ public class AuthRenrenRequest extends AuthDefaultRequest { throw new AuthException("Failed to get token from Renren: " + jsonObject); } - return AuthToken.builder() - .tokenType(jsonObject.getString("token_type")) - .expireIn(jsonObject.getIntValue("expires_in")) - .accessToken(jsonObject.getString("access_token")) - .refreshToken(jsonObject.getString("refresh_token")) - .openId(jsonObject.getJSONObject("user").getString("id")) - .build(); + try { + return AuthToken.builder() + .tokenType(jsonObject.getString("token_type")) + .expireIn(jsonObject.getIntValue("expires_in")) + .accessToken(URLEncoder.encode(jsonObject.getString("access_token"), "UTF-8")) + .refreshToken(URLEncoder.encode(jsonObject.getString("refresh_token"), "UTF-8")) + .openId(jsonObject.getJSONObject("user").getString("id")) + .build(); + } catch (UnsupportedEncodingException e) { + throw new AuthException("Failed to encode token" + e.getMessage()); + } } private String getAvatarUrl(JSONObject userObj) { -- GitLab