跳轉到主要內容
在建立用戶端之前,您需要先於 Vantage API 中完成授權,詳細資訊請參閱「Authentication」。

建立用戶端

若要建立用戶端,您必須傳送一個 POST 請求,並在標頭中加入 Authorization = Bearer <access token>,將該請求送往 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/,且在請求本文中包含以下參數:
ParameterDescription
clientId用戶端的識別碼。
clientName用戶端名稱(例如您的應用程式名稱)。
allowOfflineAccess指定是否在發出 access token 的同時產生 refresh token,使應用程式可以在不需使用者介入的情況下自動更新 access token。預設為 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 types)。
allowedCorsOrigins指定是否使用預設的跨來源資源共用(CORS)機制。
allowedScopes定義在 token 中應傳遞的一組資源與使用者資料。scope 的值必須完全等於 “openid permissions publicapi.all”
postLogoutRedirectUris登出後允許重新導向的 URI 清單。
redirectUris授權 token 重新導向所允許的網站或應用程式 URL 白名單。可以為 URL 指定前綴;若前綴相符,則任何該前綴下的 URL 都會被允許,例如:[ “https://myDomain.”, “https://myApp.myDomain.com/oauth-signin.html” ]。
accessTokenLifetime定義已簽發的 access token 允許存取 Vantage 的時間期間。access token 的預設有效期間為 24 小時。
refreshTokenLifetime定義自簽發第一個 access token 起算,在此絕對時間期間內已簽發的 refresh token 可用於更新 access token。refresh token 的預設有效期間為 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}' 
  ]
}
伺服器的回應中將包含新建立用戶端的描述資訊。

建立 Secret

每個用戶端都可以有多個 secrets。這讓用戶端在目前 secret 到期時,可以開始使用新的 secret,而不必刪除舊的。依預設,用戶端 secret 的有效期限為六個月。 若要建立 secret,您需要傳送一個 POST 請求,並在標頭中設定 Authorization = Bearer <access token>,將其送往 {baseUrl}/api/adminapi2/v1/tenants/{tenantId}/clients/{clientId}/secrets/,且在請求本文中包含以下參數:
ParameterDescription
description用戶端 secret 的描述。這可以是簡短註解,以協助您區分不同的 secrets。此為選填參數。
start time指定 secret 的開始時間。
expiration指定 secret 的到期時間(介於 1 天到 3 年之間)。例如:“2021-09-07T13:03:38.380Z”。預設情況下,此時間會設定為自建立 secret 之時起剛好六個月之後。
範例請求:

適用於 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)。