Skip to content

Commit

Permalink
feat: support mobile login with WeChat Official Accounts (#383)
Browse files Browse the repository at this point in the history
* fix: adjust the accessToken field

Signed-off-by: 0x2a <stevesough@gmail.com>

* fix: missing name and owner

Signed-off-by: 0x2a <stevesough@gmail.com>

* feat: support mobile login with WeChat

Signed-off-by: 0x2a <stevesough@gmail.com>
  • Loading branch information
Steve0x2a committed Dec 20, 2021
1 parent 8f0995c commit 99ef329
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions idp/wechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (idp *WeChatIdProvider) GetUserInfo(token *oauth2.Token) (*UserInfo, error)

userInfo := UserInfo{
Id: id,
Username: wechatUserInfo.Nickname,
DisplayName: wechatUserInfo.Nickname,
AvatarUrl: wechatUserInfo.Headimgurl,
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/ProviderEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class ProviderEditPage extends React.Component {
</Select>
</Col>
</Row>
{this.state.provider.type === "WeCom" ? (
{this.state.provider.type === "WeCom" || this.state.provider.type === "WeChat" ? (
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Method"), i18next.t("provider:Method - Tooltip"))} :
Expand Down
10 changes: 9 additions & 1 deletion web/src/auth/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +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"
},
Facebook: {
scope: "email,public_profile",
Expand Down Expand Up @@ -198,7 +200,13 @@ 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") {
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`;
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`;
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
}
} else if (provider.type === "Facebook") {
return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "DingTalk") {
Expand Down

0 comments on commit 99ef329

Please sign in to comment.