Skip to content

Commit

Permalink
feat: support web-auth way for wecom (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: sh1luo <690898835@qq.com>
  • Loading branch information
sh1luo authored and hsluoyz committed Aug 23, 2021
1 parent e50c6cd commit edf621f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
if: github.repository == 'casbin/casdoor' && github.event_name == 'push'
needs: [ frontend, backend ]
steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions object/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Provider struct {
DisplayName string `xorm:"varchar(100)" json:"displayName"`
Category string `xorm:"varchar(100)" json:"category"`
Type string `xorm:"varchar(100)" json:"type"`
Method string `xorm:"varchar(100)" json:"method"`
ClientId string `xorm:"varchar(100)" json:"clientId"`
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`

Expand Down Expand Up @@ -57,6 +58,7 @@ func getMaskedProvider(provider *Provider) *Provider {
DisplayName: provider.DisplayName,
Category: provider.Category,
Type: provider.Type,
Method: provider.Method,
ClientId: provider.ClientId,
}
return p
Expand Down
16 changes: 16 additions & 0 deletions web/src/ProviderEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ class ProviderEditPage extends React.Component {
</Select>
</Col>
</Row>
{this.state.provider.type === "WeCom" ? (
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Method"), i18next.t("provider:Method - Tooltip"))} :
</Col>
<Col span={22} >
<Select virtual={false} style={{width: '100%'}} value={this.state.provider.method} onChange={value => {
this.updateProviderField('method', value);
}}>
{
[{name: "Normal"}, {name: "Silent"}].map((method, index) => <Option key={index} value={method.name}>{method.name}</Option>)
}
</Select>
</Col>
</Row>
) : null}
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{this.getClientIdLabel()}
Expand Down
1 change: 1 addition & 0 deletions web/src/ProviderListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ProviderListPage extends React.Component {
displayName: `New Provider - ${this.state.providers.length}`,
category: "OAuth",
type: "GitHub",
method: "Normal",
clientId: "",
clientSecret: "",
enableSignUp: true,
Expand Down
17 changes: 12 additions & 5 deletions web/src/auth/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const LinkedInAuthScope = "r_liteprofile%20r_emailaddress";
const LinkedInAuthUri = "https://www.linkedin.com/oauth/v2/authorization";
const LinkedInAuthLogo = `${StaticBaseUrl}/img/social_linkedin.png`;

// const WeComAuthScope = "";
const WeComSilentAuthScope = "snsapi_userinfo";
const WeComAuthUri = "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect";
const WeComSilentAuthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize";
const WeComAuthLogo = `${StaticBaseUrl}/img/social_wecom.png`;

// const LarkAuthScope = "";
Expand Down Expand Up @@ -115,12 +116,18 @@ export function getAuthUrl(application, provider, method) {
} else if (provider.type === "Gitee") {
return `${GiteeAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GiteeAuthScope}&response_type=code&state=${state}`;
} else if (provider.type === "LinkedIn") {
return `${LinkedInAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${LinkedInAuthScope}&response_type=code&state=${state}`
return `${LinkedInAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${LinkedInAuthScope}&response_type=code&state=${state}`;
} else if (provider.type === "WeCom") {
return `${WeComAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`
if (provider.method === "Silent") {
return `${WeComSilentAuthUrl}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${WeComSilentAuthScope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") {
return `${WeComAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`;
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
}
} else if (provider.type === "Lark") {
return `${LarkAuthUri}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`
return `${LarkAuthUri}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`;
} else if (provider.type === "GitLab") {
return `${GitLabAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${GitLabAuthScope}`
return `${GitLabAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${GitLabAuthScope}`;
}
}
2 changes: 2 additions & 0 deletions web/src/locales/en/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
"Category - Tooltip": "Unique string-style identifier",
"Type": "Type",
"Type - Tooltip": "Unique string-style identifier",
"Method": "Method",
"Method - Tooltip": "Login behaviors, QR code or silent authorization",
"Client ID": "Client ID",
"Client ID - Tooltip": "Unique string-style identifier",
"Client secret": "Client secret",
Expand Down

0 comments on commit edf621f

Please sign in to comment.