Logo
Section 1 / 2

创建和获取所有连接

学习如何使用 Auth0 API 创建连接以及获取所有连接。

导入

创建和获取所有连接

学习如何使用 Auth0 API 创建连接以及获取所有连接。

...
创建连接并获取所有连接端点

创建连接是配置 Auth0 租户以处理应用程序用户身份验证的关键步骤。在本课程中,我们将探讨在 Auth0 中创建连接所需的步骤,包括可用的连接类型,以及如何根据特定的身份验证需求进行配置。

...

参数名称类型必填项描述
name字符串必填定义连接的名称。该字符串长度不得超过 128 个字符,且必须以字母开头和结尾。
strategy字符串必填定义连接的标识符。
display_name字符串可选定义连接的显示名称。
enabled_clients数组可选定义通过此连接启用的客户端 ID 列表。
realms数组可选定义可以使用此连接的领域(realms)。
password_complexity_options字符串可选定义密码复杂度选项。
1// 导入所需库 2const fetch = require('node-fetch'); 3 4const endpointUrl = new URL('https://{{DOMAIN}}/api/v2/connections'); 5 6const headerParameters = { 7 'Content-Type': 'application/json', 8 'Authorization': 'Bearer {{ACCESS_TOKEN}}', 9}; 10 11const bodyParameters = JSON.stringify({ 12 name: `Sample-Connection-${Math.floor(Math.random()*99999)}`, 13 strategy: 'auth0', 14 enabled_clients: [ 15 '{{CLIENT_ID}}' 16 ], 17}); 18 19const options = { 20 method: 'POST', 21 headers: headerParameters, 22 body: bodyParameters, 23}; 24 25async function createConnection() { 26 try { 27 const response = await fetch(endpointUrl, options); 28 printResponse(response); 29 } catch (error) { 30 printError(error); 31 } 32} 33 34createConnection();

字段名描述
name包含创建的连接名称。
display_name包含连接的显示名称。
id包含连接的 ID。
strategy包含连接的标识符。
realms包含连接所属的领域。
enabled_clients包含通过该连接启用的客户端列表。

参数名称类型必填项描述
per_page整数可选定义响应中每页返回的结果数量。
fields字符串可选用于过滤响应中包含的字段。
include_fields布尔值可选用于确认过滤后的字段是否应包含在响应中。
include_totals布尔值可选用于确认是否应在响应中包含汇总统计信息。
1// 导入所需库 2const fetch = require('node-fetch'); 3 4const endpointUrl = new URL('https://{{DOMAIN}}/api/v2/connections'); 5 6const headerParameters = { 7 'Content-Type': 'application/json', 8 'Authorization': 'Bearer {{ACCESS_TOKEN}}', 9}; 10 11// 定义查询参数 12const queryParameters = new URLSearchParams({ 13 "per_page": 5, 14 "include_totals": true 15}); 16 17const options = { 18 method: 'GET', 19 headers: headerParameters, 20}; 21 22async function getAllConnection() { 23 try { 24 endpointUrl.search = queryParameters; 25 const response = await fetch(endpointUrl, options); 26 printResponse(response); 27 } catch (error) { 28 printError(error); 29 } 30} 31 32getAllConnection();

字段名描述
name包含列出的连接名称。
display_name包含连接的显示名称。
id包含连接的 ID。
strategy包含连接的标识符。
realms包含连接所属的领域。
enabled_clients包含通过该连接启用的客户端列表。

客户端

获取、更新和删除连接