跳转到主要内容
在创建客户端之前,您需要先完成 Vantage API 的身份验证,详见“Authentication”。

创建客户端

要创建客户端,您需要向 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/ 发送带有 Authorization = Bearer <access token> 头的 POST 请求,并在请求正文中包含以下参数:
ParameterDescription
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指定可使用的授权类型。
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。
示例请求:

适用于 Windows

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}' 
  ]
}
服务器响应将包含新创建的客户端的描述。

创建密钥

每个客户端可以拥有多个密钥。这样,客户端在当前密钥过期后即可开始使用新密钥,而无需删除旧密钥。默认情况下,客户端密钥的有效期为六个月。 要创建密钥,您需要向 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/{clientId}/secrets/ 发送一条 POST 请求,请在请求头中设置 Authorization = Bearer <access token>,并在请求正文中包含以下参数:
参数说明
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}" 
}

适用于 Linux

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)及其有效期(startTimeexpiration)。
重要! 客户端密钥的值仅在创建时可见。请将其保存在安全位置,以避免因密钥丢失而无法通过其密钥访问客户端。之后,您将只能查看客户端密钥值的前三个字符(valueDisplay)。