Support WeCom Internal sub type.

This commit is contained in:
Gucheng Wang 2022-01-28 23:57:54 +08:00
parent 479daf4fa4
commit fbc73de3bb
11 changed files with 130 additions and 25 deletions

View File

@ -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"`
SubType string `xorm:"varchar(100)" json:"subType"`
Method string `xorm:"varchar(100)" json:"method"`
ClientId string `xorm:"varchar(100)" json:"clientId"`
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`

View File

@ -91,18 +91,21 @@ class ProviderEditPage extends React.Component {
getAppIdRow() {
let text, tooltip;
if (this.state.provider.category === "SMS" && this.state.provider.type === "Tencent Cloud SMS") {
text = "provider:App ID";
tooltip = "provider:App ID - Tooltip";
text = i18next.t("provider:App ID");
tooltip = i18next.t("provider:App ID - Tooltip");
} else if (this.state.provider.type === "WeCom" && this.state.provider.subType === "Internal") {
text = i18next.t("provider:Agent ID");
tooltip = i18next.t("provider:Agent ID - Tooltip");
} else if (this.state.provider.category === "SMS" && this.state.provider.type === "Volc Engine SMS") {
text = "provider:SMS account";
tooltip = "provider:SMS account - Tooltip";
text = i18next.t("provider:SMS account");
tooltip = i18next.t("provider:SMS account - Tooltip");
} else {
return null;
}
return <Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={(Setting.isMobile()) ? 22 : 2}>
{Setting.getLabel(i18next.t(text), i18next.t(tooltip))} :
{Setting.getLabel(text, tooltip)} :
</Col>
<Col span={22} >
<Input value={this.state.provider.appId} onChange={e => {
@ -205,20 +208,36 @@ class ProviderEditPage extends React.Component {
</Row>
{
this.state.provider.type !== "WeCom" ? null : (
<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>
<React.Fragment>
<Row style={{marginTop: '20px'}} >
<Col style={{marginTop: '5px'}} span={2}>
{Setting.getLabel(i18next.t("provider:Sub type"), i18next.t("provider:Sub type - Tooltip"))} :
</Col>
<Col span={22} >
<Select virtual={false} style={{width: '100%'}} value={this.state.provider.subType} onChange={value => {
this.updateProviderField('subType', value);
}}>
{
Setting.getProviderSubTypeOptions(this.state.provider.type).map((providerSubType, index) => <Option key={index} value={providerSubType.id}>{providerSubType.name}</Option>)
}
</Select>
</Col>
</Row>
<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>
</React.Fragment>
)
}
<Row style={{marginTop: '20px'}} >

View File

@ -437,6 +437,19 @@ export function getProviderTypeOptions(category) {
}
}
export function getProviderSubTypeOptions(type) {
if (type === "WeCom") {
return (
[
{id: 'Internal', name: 'Internal'},
{id: 'Third-party', name: 'Third-party'},
]
);
} else {
return [];
}
}
export function renderLogo(application) {
if (application === null) {
return null;

View File

@ -60,6 +60,7 @@ const authInfo = {
scope: "snsapi_userinfo",
endpoint: "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect",
silentEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize",
internalEndpoint: "https://open.work.weixin.qq.com/wwopen/sso/qrConnect",
},
Lark: {
// scope: "email",
@ -192,7 +193,7 @@ export function getAuthUrl(application, provider, method) {
return "";
}
const endpoint = authInfo[provider.type].endpoint;
let endpoint = authInfo[provider.type].endpoint;
const redirectUri = `${window.location.origin}/callback`;
const scope = authInfo[provider.type].scope;
const state = Util.getQueryParamsToState(application.name, provider.name, method);
@ -220,12 +221,27 @@ export function getAuthUrl(application, provider, method) {
} else if (provider.type === "LinkedIn") {
return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "WeCom") {
if (provider.method === "Silent") {
return `${authInfo[provider.type].silentEndpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") {
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`;
if (provider.subType === "Internal") {
if (provider.method === "Silent") {
endpoint = authInfo[provider.type].silentEndpoint;
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") {
endpoint = authInfo[provider.type].internalEndpoint;
return `${endpoint}?appid=${provider.clientId}&agentid=${provider.appId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`;
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
}
} else if (provider.subType === "Third-party") {
if (provider.method === "Silent") {
endpoint = authInfo[provider.type].silentEndpoint;
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") {
return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`;
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
}
} else {
return `https://error:not-supported-provider-method:${provider.method}`;
return `https://error:not-supported-provider-sub-type:${provider.subType}`;
}
} else if (provider.type === "Lark") {
return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`;

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "Zugangsschlüssel",
"Access key - Tooltip": "Zugriffsschlüssel - Tooltip",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "Eimer",
"Bucket - Tooltip": "Storage bucket name",
"Can not parse Metadata": "Metadaten können nicht analysiert werden",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "Region Endpunkt für Internet",
"Region endpoint for Intranet": "Region Endpunkt für Intranet",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP-ACS-URL",
"SP ACS URL - Tooltip": "SP ACS URL - Tooltip",
"SP Entity ID": "SP Entity ID",
@ -308,6 +314,8 @@
"Signup HTML": "HTML registrieren",
"Signup HTML - Edit": "HTML registrieren - Bearbeiten",
"Signup HTML - Tooltip": "HTML registrieren - Tooltip",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "Vorlagencode",
"Template Code - Tooltip": "Unique string-style identifier",
"Terms of Use": "Nutzungsbedingungen",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "Access key",
"Access key - Tooltip": "Access key - Tooltip",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "Bucket",
"Bucket - Tooltip": "Bucket - Tooltip",
"Can not parse Metadata": "Can not parse Metadata",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP ACS URL",
"SP ACS URL - Tooltip": "SP ACS URL - Tooltip",
"SP Entity ID": "SP Entity ID",
@ -308,6 +314,8 @@
"Signup HTML": "Signup HTML",
"Signup HTML - Edit": "Signup HTML - Edit",
"Signup HTML - Tooltip": "Signup HTML - Tooltip",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "Template Code",
"Template Code - Tooltip": "Template Code - Tooltip",
"Terms of Use": "Terms of Use",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "Clé d'accès",
"Access key - Tooltip": "Touche d'accès - Infobulle",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "Seau",
"Bucket - Tooltip": "Storage bucket name",
"Can not parse Metadata": "Impossible d'analyser les métadonnées",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "Point de terminaison de la région pour Internet",
"Region endpoint for Intranet": "Point de terminaison de la région pour Intranet",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "URL du SP ACS",
"SP ACS URL - Tooltip": "URL SP ACS - infobulle",
"SP Entity ID": "ID de l'entité SP",
@ -308,6 +314,8 @@
"Signup HTML": "Inscription HTML",
"Signup HTML - Edit": "Inscription HTML - Modifier",
"Signup HTML - Tooltip": "Inscription HTML - infobulle",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "Code du modèle",
"Template Code - Tooltip": "Unique string-style identifier",
"Terms of Use": "Conditions d'utilisation",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "アクセスキー",
"Access key - Tooltip": "アクセスキー → ツールチップ",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "バケツ入りバケツ",
"Bucket - Tooltip": "Storage bucket name",
"Can not parse Metadata": "メタデータをパースできません",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "インターネットのリージョンエンドポイント",
"Region endpoint for Intranet": "イントラネットのリージョンエンドポイント",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP ACS URL",
"SP ACS URL - Tooltip": "SP ACS URL - ツールチップ",
"SP Entity ID": "SP ID",
@ -308,6 +314,8 @@
"Signup HTML": "HTMLの登録",
"Signup HTML - Edit": "HTMLの登録 - 編集",
"Signup HTML - Tooltip": "サインアップ HTML - ツールチップ",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "テンプレートコード",
"Template Code - Tooltip": "Unique string-style identifier",
"Terms of Use": "利用規約",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "Access key",
"Access key - Tooltip": "Access key - Tooltip",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "Bucket",
"Bucket - Tooltip": "Storage bucket name",
"Can not parse Metadata": "Can not parse Metadata",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "Region endpoint for Internet",
"Region endpoint for Intranet": "Region endpoint for Intranet",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP ACS URL",
"SP ACS URL - Tooltip": "SP ACS URL - Tooltip",
"SP Entity ID": "SP Entity ID",
@ -308,6 +314,8 @@
"Signup HTML": "Signup HTML",
"Signup HTML - Edit": "Signup HTML - Edit",
"Signup HTML - Tooltip": "Signup HTML - Tooltip",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "Template Code",
"Template Code - Tooltip": "Unique string-style identifier",
"Terms of Use": "Terms of Use",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "Ключ доступа",
"Access key - Tooltip": "Ключ доступа - Подсказка",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "Ведро",
"Bucket - Tooltip": "Storage bucket name",
"Can not parse Metadata": "Невозможно разобрать метаданные",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "Конечная точка региона для Интернета",
"Region endpoint for Intranet": "Конечная точка региона Интранета",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP ACS URL",
"SP ACS URL - Tooltip": "SP ACS URL - Подсказка",
"SP Entity ID": "Идентификатор сущности SP",
@ -308,6 +314,8 @@
"Signup HTML": "Регистрация HTML",
"Signup HTML - Edit": "Регистрация HTML - Редактировать",
"Signup HTML - Tooltip": "Регистрация HTML - Подсказка",
"Sub type": "Sub type",
"Sub type - Tooltip": "Sub type - Tooltip",
"Template Code": "Код шаблона",
"Template Code - Tooltip": "Unique string-style identifier",
"Terms of Use": "Условия использования",

View File

@ -247,6 +247,10 @@
"provider": {
"Access key": "访问密钥",
"Access key - Tooltip": "Access key",
"Agent ID": "Agent ID",
"Agent ID - Tooltip": "Agent ID - Tooltip",
"App ID": "App ID",
"App ID - Tooltip": "App ID - Tooltip",
"Bucket": "存储桶",
"Bucket - Tooltip": "Bucket名称",
"Can not parse Metadata": "无法解析元数据",
@ -293,6 +297,8 @@
"Region endpoint for Internet": "地域节点 (外网)",
"Region endpoint for Intranet": "地域节点 (内网)",
"SAML 2.0 Endpoint (HTTP)": "SAML 2.0 Endpoint (HTTP)",
"SMS account": "SMS account",
"SMS account - Tooltip": "SMS account - Tooltip",
"SP ACS URL": "SP ACS URL",
"SP ACS URL - Tooltip": "SP ACS URL - 工具提示",
"SP Entity ID": "SP 实体 ID",
@ -308,6 +314,8 @@
"Signup HTML": "注册 HTML",
"Signup HTML - Edit": "注册 HTML - 编辑",
"Signup HTML - Tooltip": "注册 HTML - 工具提示",
"Sub type": "子类型",
"Sub type - Tooltip": "子类型",
"Template Code": "模板CODE",
"Template Code - Tooltip": "模板CODE",
"Terms of Use": "使用条款",