Support WeChat MP at the same time.

This commit is contained in:
Yang Luo
2021-12-20 23:36:28 +08:00
parent 99ef329325
commit 3efbcc739d
4 changed files with 44 additions and 16 deletions

View File

@ -33,8 +33,8 @@ const authInfo = {
WeChat: {
scope: "snsapi_login",
endpoint: "https://open.weixin.qq.com/connect/qrconnect",
slientScope: "snsapi_userinfo",
silentEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize"
mpScope: "snsapi_userinfo",
mpEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize"
},
Facebook: {
scope: "email,public_profile",
@ -200,12 +200,10 @@ export function getAuthUrl(application, provider, method) {
} else if (provider.type === "QQ") {
return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "WeChat") {
if (provider.method === "Silent") {
return `${authInfo[provider.type].silentEndpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${authInfo[provider.type].slientScope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") {
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`;
if (navigator.userAgent.includes("MicroMessenger")) {
return `${authInfo[provider.type].mpEndpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${authInfo[provider.type].mpScope}&response_type=code#wechat_redirect`;
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`;
}
} else if (provider.type === "Facebook") {
return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;