diff --git a/pom.xml b/pom.xml
index acdcdc1..51d2ea3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
org.keycloak
keycloak-services-social-weixin
- 0.3.6
+ 0.3.8
Keycloak Services Social WeiXin
diff --git a/src/main/java/org/keycloak/social/weixin/WeiXinIdentityProviderFactory.java b/src/main/java/org/keycloak/social/weixin/WeiXinIdentityProviderFactory.java
index 3a204dc..723c885 100644
--- a/src/main/java/org/keycloak/social/weixin/WeiXinIdentityProviderFactory.java
+++ b/src/main/java/org/keycloak/social/weixin/WeiXinIdentityProviderFactory.java
@@ -54,6 +54,19 @@ public List getConfigProperties() {
.label("PC 登录 URL")
.helpText("PC 登录 URL 的登录页面,可以配置为一个自定义的前端登录页面,用来展示公众号带参二维码")
.type(ProviderConfigProperty.STRING_TYPE)
- .add().build();
+ .add()
+
+ .property().name(WeiXinIdentityProvider.WMP_APP_ID)
+ .label("小程序 appId")
+ .helpText("小程序的 appid")
+ .type(ProviderConfigProperty.STRING_TYPE)
+ .add()
+ .property().name(WeiXinIdentityProvider.WMP_APP_SECRET)
+ .label("小程序 appSecret")
+ .helpText("小程序的 app secret")
+ .type(ProviderConfigProperty.STRING_TYPE)
+ .add()
+
+ .build();
}
}
diff --git a/src/main/java/org/keycloak/social/weixin/WeixinIdentityCustomAuth.java b/src/main/java/org/keycloak/social/weixin/WeixinIdentityCustomAuth.java
index 110234d..9b3701d 100644
--- a/src/main/java/org/keycloak/social/weixin/WeixinIdentityCustomAuth.java
+++ b/src/main/java/org/keycloak/social/weixin/WeixinIdentityCustomAuth.java
@@ -26,13 +26,18 @@ public WeixinIdentityCustomAuth(KeycloakSession session, OAuth2IdentityProviderC
// TODO: cache mechanism
public String getAccessToken(WechatLoginType wechatLoginType) throws IOException {
+ logger.info("getAccessToken with " + wechatLoginType);
+
var clientId = this.getConfig().getClientId();
var clientSecret = this.getConfig().getClientSecret();
try {
String ua = session.getContext().getRequestHeaders().getHeaderString("user-agent").toLowerCase();
+ logger.info("ua = " + ua);
if (!isWechatBrowser(ua) || WechatLoginType.FROM_PC_QR_CODE_SCANNING.equals(wechatLoginType)) {
+ logger.info("not wechat browser or from pc qr code scanning");
+
clientId = this.getConfig().getConfig().get(WECHAT_MP_APP_ID);
clientSecret = this.getConfig().getConfig().get(WECHAT_MP_APP_SECRET);
}
@@ -44,7 +49,7 @@ public String getAccessToken(WechatLoginType wechatLoginType) throws IOException
logger.info(String.format("getAccessToken by %s%n%s%n", clientId, clientSecret));
var res =
SimpleHttp.doGet(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" +
- "&appid=%s&secret=%s", this.getConfig().getClientId(), this.getConfig().getClientSecret()),
+ "&appid=%s&secret=%s", clientId, clientSecret),
this.session).asString();
logger.info(String.format("res is %s%n", res));
diff --git a/src/main/java/org/keycloak/social/weixin/egress/wechat/mp/AccessTokenRequestBody.java b/src/main/java/org/keycloak/social/weixin/egress/wechat/mp/AccessTokenRequestBody.java
new file mode 100644
index 0000000..a9364dd
--- /dev/null
+++ b/src/main/java/org/keycloak/social/weixin/egress/wechat/mp/AccessTokenRequestBody.java
@@ -0,0 +1,13 @@
+package org.keycloak.social.weixin.egress.wechat.mp;
+
+public class AccessTokenRequestBody {
+ public String grant_type;
+ public String appid;
+ public String secret;
+
+ public AccessTokenRequestBody(String grant_type, String appid, String secret) {
+ this.grant_type = grant_type;
+ this.appid = appid;
+ this.secret = secret;
+ }
+}