From 8e628876ba998bda52a897378c7b6b1a75e710f3 Mon Sep 17 00:00:00 2001
From: denghuafeng <254001996@qq.com>
Date: Mon, 24 Oct 2022 16:09:32 +0800
Subject: [PATCH] =?UTF-8?q?add:=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E5=88=86=E7=A6=BB=E3=80=81=E5=BE=AE=E4=BF=A1=E5=B0=8F?=
=?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=8E=A5=E5=8F=A3=E9=93=BE=E6=8E=A5=E5=92=8C?=
=?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BF=A1=E6=81=AF=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../zhyd/oauth/config/AuthDefaultSource.java | 2 +-
.../oauth/request/AuthDefaultRequest.java | 27 +++++++++++++++++++
.../me/zhyd/oauth/request/AuthRequest.java | 18 +++++++++++++
.../oauth/request/AuthWeChatMpRequest.java | 13 ++++++---
5 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/pom.xml b/pom.xml
index 30ceda3..138d296 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
diff --git a/src/main/java/me/zhyd/oauth/request/AuthRequest.java b/src/main/java/me/zhyd/oauth/request/AuthRequest.java index e4bd718..9a23a95 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthRequest.java @@ -5,6 +5,7 @@ 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; /** * JustAuth {@code Request}公共接口,所有平台的{@code Request}都需要实现该接口 @@ -43,6 +44,23 @@ public interface AuthRequest { throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED); } + /** + * 获取授权token + * @param authCallback 用于接收回调参数的实体 + * @return 返回登录成功后的token信息 + */ + default AuthResponse authToken(AuthCallback authCallback) { + throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED); + } + + /** + * 获取用户信息 + * @param authToken 授权token信息 + * @return 返回登录成功后的用户信息 + */ + default AuthResponse userInfo(AuthToken authToken) { + throw new AuthException(AuthResponseStatus.NOT_IMPLEMENTED); + } /** * 第三方登录 * diff --git a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java index 94fcba8..740a6bd 100644 --- a/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java +++ b/src/main/java/me/zhyd/oauth/request/AuthWeChatMpRequest.java @@ -101,12 +101,17 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest { JSONObject accessTokenObject = JSONObject.parseObject(response); this.checkResponse(accessTokenObject); - + /* @JsonAlias({"session_key"}) + private String sessionKey; + private String openid; + private String unionid;*/ + //sessionKey return AuthToken.builder() - .accessToken(accessTokenObject.getString("access_token")) - .refreshToken(accessTokenObject.getString("refresh_token")) + .accessToken(accessTokenObject.getString("session_key")) + .refreshToken(accessTokenObject.getString("session_key")) .expireIn(accessTokenObject.getIntValue("expires_in")) .openId(accessTokenObject.getString("openid")) + .unionId(accessTokenObject.getString("unionid")) .scope(accessTokenObject.getString("scope")) .build(); } @@ -140,7 +145,7 @@ public class AuthWeChatMpRequest extends AuthDefaultRequest { return UrlBuilder.fromBaseUrl(source.accessToken()) .queryParam("appid", config.getClientId()) .queryParam("secret", config.getClientSecret()) - .queryParam("code", code) + .queryParam("js_code", code) .queryParam("grant_type", "authorization_code") .build(); } -- Gitee