跳转到主要内容
在创建客户端之前,您需要通过 Vantage API 完成授权,详情请参见 Authentication。

创建客户端

要创建客户端,您需要向 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/ 发送一条带有 Authorization = Bearer <access token> 标头的 POST 请求,并在请求正文中包含以下参数:
Parameter描述
clientId客户端标识符。
clientName客户端名称(例如您的应用名称)。
allowOfflineAccess指定是否在生成访问令牌的同时生成刷新令牌,应用可用其在无需用户干预的情况下自动更新访问令牌。默认值为 False
allowRememberConsent指定用户是否可以选择保存同意决定。默认值为 True
backChannelLogoutSessionRequired指定是否需要 Backchannel Logout 机制。默认值为 True
requireClientSecret指定是否需要客户端密钥。默认值为 True
requireConsent指定是否需要同意界面。默认值为 False
allowNoPkce指定是否允许使用“授权码模式 + 代码交换证明(PKCE)”以外的认证方案。默认值为 False,仅允许使用“授权码模式 + 代码交换证明(PKCE)”。
allowedGrantTypes指定可使用的授权类型。
allowedCorsOrigins指定是否使用默认的跨域资源共享(CORS)机制。
allowedScopes定义应在令牌中传输的资源和用户数据集合。该值必须严格为 “openid permissions publicapi.all”
postLogoutRedirectUris注销后允许重定向的 URI 列表。
redirectUris被允许用于授权令牌重定向的网站或应用 URL 列表。URL 允许使用前缀;如果前缀匹配,则允许任何 URL,例如:[ “https://myDomain.”, “https://myApp.myDomain.com/oauth-signin.html” ]。
重要! 使用 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/ 发送一个带有 Authorization = Bearer <access token> 标头的 POST 请求,并在请求正文中包含以下参数:
ParameterDescription
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)。