auth-tool-cloudbase

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Overview

概述

Configure CloudBase authentication providers: Anonymous, Username/Password, SMS, Email, WeChat, Google, and more.
Prerequisites: CloudBase environment ID (
env
)

配置CloudBase身份认证提供商:匿名、用户名/密码、短信、邮箱、微信、Google等。
前提条件:CloudBase环境ID(
env

Authentication Scenarios

认证场景

1. Get Login Strategy

1. 获取登录策略

Query current login configuration:
js
{
    "params": { "EnvId": `env` },
    "service": "lowcode",
    "action": "DescribeLoginStrategy"
}
Returns
LoginStrategy
object or
false
if not configured.

查询当前登录配置:
js
{
    "params": { "EnvId": `env` },
    "service": "lowcode",
    "action": "DescribeLoginStrategy"
}
返回
LoginStrategy
对象,若未配置则返回
false

2. Anonymous Login

2. 匿名登录

  1. Get
    LoginStrategy
    (see Scenario 1)
  2. Set
    LoginStrategy.AnonymousLogin = true
    (on) or
    false
    (off)
  3. Update:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

  1. 获取
    LoginStrategy
    (参见场景1)
  2. 设置
    LoginStrategy.AnonymousLogin = true
    (开启)或
    false
    (关闭)
  3. 更新配置:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

3. Username/Password Login

3. 用户名/密码登录

  1. Get
    LoginStrategy
    (see Scenario 1)
  2. Set
    LoginStrategy.UserNameLogin = true
    (on) or
    false
    (off)
  3. Update:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

  1. 获取
    LoginStrategy
    (参见场景1)
  2. 设置
    LoginStrategy.UserNameLogin = true
    (开启)或
    false
    (关闭)
  3. 更新配置:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

4. SMS Login

4. 短信登录

  1. Get
    LoginStrategy
    (see Scenario 1)
  2. Modify:
    • Turn on:
      LoginStrategy.PhoneNumberLogin = true
    • Turn off:
      LoginStrategy.PhoneNumberLogin = false
    • Config (optional):
      js
      LoginStrategy.SmsVerificationConfig = {
          Type: 'default',      // 'default' or 'apis'
          Method: 'methodName',
          SmsDayLimit: 30       // -1 = unlimited
      }
  3. Update:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

  1. 获取
    LoginStrategy
    (参见场景1)
  2. 修改配置:
    • 开启
      LoginStrategy.PhoneNumberLogin = true
    • 关闭
      LoginStrategy.PhoneNumberLogin = false
    • 配置(可选):
      js
      LoginStrategy.SmsVerificationConfig = {
          Type: 'default',      // 'default'或'apis'
          Method: 'methodName',
          SmsDayLimit: 30       // -1 = 无限制
      }
  3. 更新配置:
js
{
    "params": { "EnvId": `env`, ...LoginStrategy },
    "service": "lowcode",
    "action": "ModifyLoginStrategy"
}

5. Email Login

5. 邮箱登录

Turn on (Tencent Cloud email):
js
{
    "params": {
        "EnvId": `env`,
        "Id": "email",
        "On": "TRUE",
        "EmailConfig": { "On": "TRUE", "SmtpConfig": {} }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}
Turn off:
js
{
    "params": { "EnvId": `env`, "Id": "email", "On": "FALSE" },
    "service": "tcb",
    "action": "ModifyProvider"
}
Turn on (custom SMTP):
js
{
    "params": {
        "EnvId": `env`,
        "Id": "email",
        "On": "TRUE",
        "EmailConfig": {
            "On": "FALSE",
            "SmtpConfig": {
                "AccountPassword": "password",
                "AccountUsername": "username",
                "SecurityMode": "SSL",
                "SenderAddress": "sender@example.com",
                "ServerHost": "smtp.qq.com",
                "ServerPort": 465
            }
        }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}

开启(腾讯云邮箱)
js
{
    "params": {
        "EnvId": `env`,
        "Id": "email",
        "On": "TRUE",
        "EmailConfig": { "On": "TRUE", "SmtpConfig": {} }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}
关闭
js
{
    "params": { "EnvId": `env`, "Id": "email", "On": "FALSE" },
    "service": "tcb",
    "action": "ModifyProvider"
}
开启(自定义SMTP)
js
{
    "params": {
        "EnvId": `env`,
        "Id": "email",
        "On": "TRUE",
        "EmailConfig": {
            "On": "FALSE",
            "SmtpConfig": {
                "AccountPassword": "password",
                "AccountUsername": "username",
                "SecurityMode": "SSL",
                "SenderAddress": "sender@example.com",
                "ServerHost": "smtp.qq.com",
                "ServerPort": 465
            }
        }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}

6. WeChat Login

6. 微信登录

  1. Get WeChat config:
js
{
    "params": { "EnvId": `env` },
    "service": "tcb",
    "action": "GetProviders"
}
Filter by
Id == "wx_open"
, save as
WeChatProvider
.
  1. Get credentials from WeChat Open Platform:
    • AppID
    • AppSecret
  2. Update:
js
{
    "params": {
        "EnvId": `env`,
        "Id": "wx_open",
        "On": "TRUE",  // "FALSE" to disable
        "Config": {
            ...WeChatProvider.Config,
            ClientId: `AppID`,
            ClientSecret: `AppSecret`
        }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}

  1. 获取微信配置:
js
{
    "params": { "EnvId": `env` },
    "service": "tcb",
    "action": "GetProviders"
}
筛选
Id == "wx_open"
的配置,保存为
WeChatProvider
  1. 微信开放平台获取凭证:
    • AppID
    • AppSecret
  2. 更新配置:
js
{
    "params": {
        "EnvId": `env`,
        "Id": "wx_open",
        "On": "TRUE",  // "FALSE"表示禁用
        "Config": {
            ...WeChatProvider.Config,
            ClientId: `AppID`,
            ClientSecret: `AppSecret`
        }
    },
    "service": "tcb",
    "action": "ModifyProvider"
}

7. Google Login

7. Google登录

  1. Get redirect URI:
js
{
    "params": { "EnvId": `env` },
    "service": "lowcode",
    "action": "DescribeStaticDomain"
}
Save
result.Data.StaticDomain
as
staticDomain
.
  1. Configure at Google Cloud Console:
    • Create OAuth 2.0 Client ID
    • Set redirect URI:
      https://{staticDomain}/__auth/
    • Get
      Client ID
      and
      Client Secret
  2. Enable:
js
{
    "params": {
        "EnvId": `env`,
        "ProviderType": "OAUTH",
        "Id": "google",
        "On": "TRUE",  // "FALSE" to disable
        "Name": { "Message": "Google" },
        "Description": { "Message": "" },
        "Config": {
            "ClientId": `Client ID`,
            "ClientSecret": `Client Secret`,
            "Scope": "email openid profile",
            "AuthorizationEndpoint": "https://accounts.google.com/o/oauth2/v2/auth",
            "TokenEndpoint": "https://oauth2.googleapis.com/token",
            "UserinfoEndpoint": "https://www.googleapis.com/oauth2/v3/userinfo",
            "TokenEndpointAuthMethod": "CLIENT_SECRET_BASIC",
            "RequestParametersMap": {
                "RegisterUserSyncScope": "syncEveryLogin",
                "IsGoogle": "TRUE"
            }
        },
        "Picture": "https://qcloudimg.tencent-cloud.cn/raw/f9131c00dcbcbccd5899a449d68da3ba.png",
        "TransparentMode": "FALSE",
        "ReuseUserId": "TRUE",
        "AutoSignUpWithProviderUser": "TRUE"
    },
    "service": "tcb",
    "action": "ModifyProvider"
}
  1. 获取重定向URI:
js
{
    "params": { "EnvId": `env` },
    "service": "lowcode",
    "action": "DescribeStaticDomain"
}
保存
result.Data.StaticDomain
staticDomain
  1. Google Cloud Console中配置:
    • 创建OAuth 2.0客户端ID
    • 设置重定向URI:
      https://{staticDomain}/__auth/
    • 获取
      Client ID
      Client Secret
  2. 启用配置:
js
{
    "params": {
        "EnvId": `env`,
        "ProviderType": "OAUTH",
        "Id": "google",
        "On": "TRUE",  // "FALSE"表示禁用
        "Name": { "Message": "Google" },
        "Description": { "Message": "" },
        "Config": {
            "ClientId": `Client ID`,
            "ClientSecret": `Client Secret`,
            "Scope": "email openid profile",
            "AuthorizationEndpoint": "https://accounts.google.com/o/oauth2/v2/auth",
            "TokenEndpoint": "https://oauth2.googleapis.com/token",
            "UserinfoEndpoint": "https://www.googleapis.com/oauth2/v3/userinfo",
            "TokenEndpointAuthMethod": "CLIENT_SECRET_BASIC",
            "RequestParametersMap": {
                "RegisterUserSyncScope": "syncEveryLogin",
                "IsGoogle": "TRUE"
            }
        },
        "Picture": "https://qcloudimg.tencent-cloud.cn/raw/f9131c00dcbcbccd5899a449d68da3ba.png",
        "TransparentMode": "FALSE",
        "ReuseUserId": "TRUE",
        "AutoSignUpWithProviderUser": "TRUE"
    },
    "service": "tcb",
    "action": "ModifyProvider"
}

8. Get Publishable Key

8. 获取可发布密钥

Query existing key:
js
{
    "params": { "EnvId": `env`, "KeyType": "publish_key", "PageNumber": 1, "PageSize": 10 },
    "service": "lowcode",
    "action": "DescribeApiKeyTokens"
}
Return
PublishableKey.ApiKey
if exists (filter by
Name == "publish_key"
).
Create new key (if not exists):
js
{
    "params": { "EnvId": `env`, "KeyType": "publish_key", "KeyName": "publish_key" },
    "service": "lowcode",
    "action": "CreateApiKeyToken"
}
查询现有密钥
js
{
    "params": { "EnvId": `env`, "KeyType": "publish_key", "PageNumber": 1, "PageSize": 10 },
    "service": "lowcode",
    "action": "DescribeApiKeyTokens"
}
若存在则返回
PublishableKey.ApiKey
(通过
Name == "publish_key"
筛选)。
创建新密钥(若不存在):
js
{
    "params": { "EnvId": `env`, "KeyType": "publish_key", "KeyName": "publish_key" },
    "service": "lowcode",
    "action": "CreateApiKeyToken"
}
若创建失败,请引导用户访问:"https://tcb.cloud.tencent.com/dev?envId=`env`#/env/apikey"