身份认证:配置管理
配置和管理 CloudBase 认证提供商,启用/禁用登录方式(短信、邮箱、微信、Google、匿名、用户名密码等)
如何使用
查看如何使用提示词了解详细的使用方法。
测试提示词
你可以使用以下提示词来测试:
- "在 CloudBase 控制台帮我配置短信登录方式"
- "在 CloudBase 中启用邮箱验证码登录"
- "在 CloudBase 中配置微信开放平台登录"
- "在 CloudBase 中设置匿名登录功能"
使用 AI 配置和管理身份认证
提示词
rule.md
## Overview
Configure CloudBase authentication providers: Anonymous, Username/Password, SMS, Email, WeChat, Google, and more.
**Prerequisites**: CloudBase environment ID (`env`)
---
## Authentication Scenarios
### 1. Get Login Strategy
Query current login configuration:
```js
{
"params": { "EnvId": `env` },
"service": "lowcode",
"action": "DescribeLoginStrategy"
}
```
Returns `LoginStrategy` object or `false` if not configured.
---
### 2. Anonymous Login
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"
}
```
---
### 3. Username/Password Login
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"
}
```
---
### 4. SMS Login
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"
}
```
---
### 5. Email Login
**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"
}
```
---
### 6. WeChat Login
1. Get WeChat config:
```js
{
"params": { "EnvId": `env` },
"service": "tcb",
"action": "GetProviders"
}
```
Filter by `Id == "wx_open"`, save as `WeChatProvider`.
2. Get credentials from [WeChat Open Platform](https://open.weixin.qq.com/cgi-bin/readtemplate?t=regist/regist_tmpl):
- `AppID`
- `AppSecret`
3. Update:
```js
{
"params": {
"EnvId": `env`,
"Id": "wx_open",
"On": "TRUE", // "FALSE" to disable
"Config": {
...WeChatProvider.Config,
ClientId: `AppID`,
ClientSecret: `AppSecret`
}
},
"service": "tcb",
"action": "ModifyProvider"
}
```
---
### 7. Google Login
1. Get redirect URI:
```js
{
"params": { "EnvId": `env` },
"service": "lowcode",
"action": "DescribeStaticDomain"
}
```
Save `result.Data.StaticDomain` as `staticDomain`.
2. Configure at [Google Cloud Console](https://console.cloud.google.com/apis/credentials):
- Create OAuth 2.0 Client ID
- Set redirect URI: `https://{staticDomain}/__auth/`
- Get `Client ID` and `Client Secret`
3. 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"
}
```