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

@ -32,6 +32,8 @@ type Provider struct {
Method string `xorm:"varchar(100)" json:"method"` Method string `xorm:"varchar(100)" json:"method"`
ClientId string `xorm:"varchar(100)" json:"clientId"` ClientId string `xorm:"varchar(100)" json:"clientId"`
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"` ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
ClientId2 string `xorm:"varchar(100)" json:"clientId2"`
ClientSecret2 string `xorm:"varchar(100)" json:"clientSecret2"`
Host string `xorm:"varchar(100)" json:"host"` Host string `xorm:"varchar(100)" json:"host"`
Port int `json:"port"` Port int `json:"port"`

View File

@ -257,7 +257,8 @@ class ProviderEditPage extends React.Component {
</Select> </Select>
</Col> </Col>
</Row> </Row>
{this.state.provider.type === "WeCom" || this.state.provider.type === "WeChat" ? ( {
this.state.provider.type !== "WeCom" ? null : (
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}> <Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Method"), i18next.t("provider:Method - Tooltip"))} : {Setting.getLabel(i18next.t("provider:Method"), i18next.t("provider:Method - Tooltip"))} :
@ -272,7 +273,8 @@ class ProviderEditPage extends React.Component {
</Select> </Select>
</Col> </Col>
</Row> </Row>
) : null} )
}
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}> <Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{this.getClientIdLabel()} {this.getClientIdLabel()}
@ -293,6 +295,32 @@ class ProviderEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
{
this.state.provider.type !== "WeChat" ? null : (
<React.Fragment>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("provider:Client ID 2"), i18next.t("provider:Client ID 2 - Tooltip"))}
</Col>
<Col span={22} >
<Input value={this.state.provider.clientId2} onChange={e => {
this.updateProviderField('clientId2', e.target.value);
}} />
</Col>
</Row>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t("provider:Client secret 2"), i18next.t("provider:Client secret 2 - Tooltip"))}
</Col>
<Col span={22} >
<Input value={this.state.provider.clientSecret2} onChange={e => {
this.updateProviderField('clientSecret2', e.target.value);
}} />
</Col>
</Row>
</React.Fragment>
)
}
{this.state.provider.category === "Storage" ? ( {this.state.provider.category === "Storage" ? (
<div> <div>
<Row style={{marginTop: '20px'}} > <Row style={{marginTop: '20px'}} >

View File

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

View File

@ -232,7 +232,7 @@
"Link copied to clipboard successfully": "Link copied to clipboard successfully", "Link copied to clipboard successfully": "Link copied to clipboard successfully",
"Metadata": "Metadata", "Metadata": "Metadata",
"Metadata - Tooltip": "Metadata - Tooltip", "Metadata - Tooltip": "Metadata - Tooltip",
"Method": "方", "Method": "方",
"Method - Tooltip": "登录行为,二维码或者静默授权登录", "Method - Tooltip": "登录行为,二维码或者静默授权登录",
"Name": "名称", "Name": "名称",
"Parse": "Parse", "Parse": "Parse",