在创建客户端之前,您需要先在 Vantage API 中完成身份验证,详情请参阅“Authentication”部分。
要创建客户端,您需要向 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/ 发送一个携带 Authorization = Bearer <access token> 请求头的 POST 请求,请求正文中包含以下参数:
| Parameter | Description |
|---|
clientId | 客户端的标识符。 |
clientName | 客户端名称(例如您的应用名称)。 |
allowOfflineAccess | 指定是否在颁发访问令牌的同时生成刷新令牌,应用可以使用刷新令牌在无需用户干预的情况下自动更新访问令牌。默认设置为 False。 |
allowRememberConsent | 指定用户是否可以选择保存其授权决定。默认设置为 True。 |
backChannelLogoutSessionRequired | 指定是否需要使用 Backchannel Logout 机制。默认设置为 True。 |
requireClientSecret | 指定是否需要客户端密钥。默认设置为 True。 |
requireConsent | 指定是否需要授权界面。默认设置为 False。 |
allowNoPkce | 指定是否允许使用 Authorization Code Flow with Proof Key for Code Exchange (PKCE) 认证方案。默认设置为 False,此时仅允许使用 Authorization Code Flow with Proof Key for Code Exchange (PKCE) 认证方案。 |
allowedGrantTypes | 指定可以使用的授权类型(grant type)。 |
allowedCorsOrigins | 指定是否使用默认的跨来源资源共享(CORS)机制。 |
allowedScopes | 定义在令牌中应传递的一组资源和用户数据。scope 的值必须严格为 “openid permissions publicapi.all”。 |
postLogoutRedirectUris | 注销后允许重定向到的 URI 列表。 |
redirectUris | 被列入白名单、用于授权令牌重定向的网站或应用 URL 列表。允许为 URL 指定前缀。如果前缀匹配,则允许任意 URL,例如:[ “https://myDomain.”, “https://myApp.myDomain.com/oauth-signin.html” ]。 |
accessTokenLifetime | 定义已颁发访问令牌在多长时间内允许用户访问 Vantage。访问令牌的默认有效期为 24 小时。 |
refreshTokenLifetime | 定义从首次颁发访问令牌开始计算,在多长的绝对时间内已颁发的刷新令牌可以用于续期访问令牌。刷新令牌的默认有效期为 30 天。 |
重要! 当使用 Resource Owner Password Credentials 进行认证时,必须将 allowRopc 参数设置为 TRUE。请注意,此认证方案假定用户将其凭据发送给应用程序,因此建议仅在已对受信任的机密客户端进行身份验证的情况下使用 ROPC。
示例请求:
curl --location --request POST "{baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/"
-H "accept: application/json" \
-H "Authorization: Bearer {token}"
{
"clientId": "{clientId}",
"clientName": "{clientName}",
"allowOfflineAccess": true,
"allowRememberConsent": true,
"backChannelLogoutSessionRequired": true,
"requireClientSecret": true,
"requireConsent": false,
"allowNoPkce": true,
"allowedGrantTypes": [
"{allowedGrantTypes}"
],
"allowedCorsOrigins": [
"{allowedCorsOrigins}"
],
"allowedScopes": [
"openid",
"permissions",
"publicapi.all"
]
"postLogoutRedirectUris": [
"{postLogoutRedirectUris}"
],
"redirectUris": [
"{redirectUris}"
]
}
适用于 Linux
curl --location --request POST '{baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/'
-H 'accept: application/json' \
-H 'Authorization: Bearer {token}'
{
'clientId': '{clientId}',
'clientName': '{clientName}',
'allowOfflineAccess': true,
'allowRememberConsent': true,
'backChannelLogoutSessionRequired': true,
'requireClientSecret': true,
'requireConsent': false,
'allowNoPkce': true,
'allowedGrantTypes': [
'{allowedGrantTypes}'
],
'allowedCorsOrigins': [
'{allowedCorsOrigins}'
],
'allowedScopes': [
'openid',
'permissions',
'publicapi.all'
]
'postLogoutRedirectUris': [
'{postLogoutRedirectUris}'
],
'redirectUris': [
'{redirectUris}'
]
}
服务器的响应中将包含新创建客户端的详细信息。
每个客户端可以拥有多个密钥。这样,当当前密钥过期时,客户端可以开始使用新的密钥,而无需删除旧密钥。默认情况下,客户端密钥在六个月后过期。
要创建密钥,您需要发送一个带有 Authorization = Bearer <access token> 请求头的 POST 请求到 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/{clientId}/secrets/,并在请求正文中包含以下参数:
| Parameter | Description |
|---|
description | 客户端密钥的描述。可以是一个简短注释,用于帮助您区分不同的密钥。该参数为可选参数。 |
start time | 指定密钥的开始时间。 |
expiration | 指定密钥的到期时间(介于 1 天到 3 年之间)。例如:“2021-09-07T13:03:38.380Z”。默认情况下,该时间被设置为自密钥创建之日起正好六个月。 |
请求示例:
适用于 Windows
curl --location --request POST "{baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/{clientId}/secrets/"
-H "accept: application/json" \
-H "Authorization: Bearer {token}"
-H "Content-Type: application/json-patch+json" \
-d
{
"description": "{description}",
"startTime": "{startTime}"
"expiration": "{expiration}"
}
curl --location --request POST '{baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/{clientId}/secrets/'
-H 'accept: application/json' \
-H 'Authorization: Bearer {token}'
-H 'Content-Type: application/json-patch+json' \
-d
{
'description': '{description}',
'startTime': '{startTime}'
'expiration': '{expiration}'
}
服务器对您的请求的响应将包含一个客户端密钥 (value) 及其有效期 (startTime、expiration) 。
客户端密钥的值仅在创建时可见。请将其存储在安全的位置,以避免因丢失该密钥而无法访问客户端。之后,您只能查看客户端密钥值的前三个字符 (valueDisplay) 。