SetOAuthV2Info 政策

您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。
info

結果

可讓您新增或更新與存取權杖相關聯的自訂屬性。自訂屬性可能包括部門名稱、顧客 ID 或工作階段 ID。另請參閱自訂憑證和授權碼。

你只能新增或修改自訂屬性。您無法使用這項政策變更範圍、狀態、expires_in、developer_email、client_id、org_name 或 refresh_count 等欄位。如果屬性已存在,這項政策會更新該屬性。如果不存在,政策會新增該屬性。所參照的存取權杖必須有效且處於核准狀態。

範例

基本範例

以下是更新 OAuth 2.0 存取權杖的範例政策。以下範例會尋找名為 access_token 的查詢參數,在要求訊息中找出存取權杖。當用戶端應用程式提供存取權杖時,下列政策會在查詢參數中找出存取權杖。然後更新存取權杖的設定檔。這會在設定檔中新增名為 department.id 的自訂屬性。

<SetOAuthV2Info name="SetOAuthV2Info"> 
  <AccessToken ref="request.queryparam.access_token"></AccessToken>
  <Attributes>
    <Attribute name="department.id" ref="request.queryparam.department_id"></Attribute>
  </Attributes>
</SetOAuthV2Info>

元素參照

元素參考資料說明 SetOAuthV2 政策的元素和屬性。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SetOAuthV2Info async="false" continueOnError="false" enabled="true" name="SetOAuthV2Info-1">    
    <DisplayName>Set OAuth v2.0 Info 1</DisplayName>
    <AccessToken ref={some-variable}></AccessToken>
    <Attributes/>
</SetOAuthV2Info>
</xml>

<SetOAuthV2Info> 屬性

<SetOAuthV2Info async="false" continueOnError="false" enabled="true" name="Set-OAuth-v20-Info-1">

下表說明所有政策父項元素的共同屬性:

屬性 說明 預設 存在必要性
name

政策的內部名稱。name 屬性的值可以 包含英文字母、數字、空格、連字號、底線和半形句號。此值不能 超過 255 個半形字元

視需要使用 <DisplayName> 元素,為政策加上標籤: 管理使用者介面 Proxy 編輯器,使用不同的自然語言名稱。

不適用 必填
continueOnError

如果設為「false」,系統會在政策失敗時傳回錯誤。這是可預期的情況 大多數政策的行為

如果設為 true,即使政策已發生,流程執行作業仍會繼續執行 失敗。

false 選用
enabled

如要強制執行政策,請設為 true。

設為 false 即可停用政策。這項政策不會 仍會強制執行 政策。

true 選用
async

此屬性已淘汰。

false 已淘汰

&lt;DisplayName&gt;元素

除 name 屬性外,一併使用 管理 UI Proxy 編輯器,使用不同的自然語言名稱。

<DisplayName>Policy Display Name</DisplayName>
預設

不適用

如果省略這個元素,政策的 name 屬性值會是

存在必要性 選用
類型 字串

<AccessToken> 元素

指出存取權杖所在的變數。舉例來說,如果存取權杖以查詢參數的形式附加至要求訊息,請指定 request.queryparam.access_token。您可以使用任何參照權杖的有效變數。或者,也可以傳入字面值權杖字串 (極少數情況)。

 <AccessToken ref="request.queryparam.access_token"></AccessToken>
預設值: N/A
外觀狀態: 必填
類型: 字串

屬性

屬性 說明 預設 存在必要性
ref

存取權杖變數。通常是從流程變數擷取。

N/A 選用

<Attributes> 元素

存取權杖設定檔中的一組屬性,將會修改或擴增。

預設值: N/A
外觀狀態: 必填
類型: N/A

<Attributes>/<Attribute> 元素

要更新的個別屬性。

name 屬性會識別要更新的存取權杖設定檔自訂屬性。這個範例說明如何使用參照變數值和靜態價值。

  <Attributes>
    <Attribute name="department.id" ref="request.queryparam.department_id"></Attribute>
    <Attribute name="foo">bar</Attribute>
  </Attributes>
預設值: N/A
外觀狀態: 選用
類型: N/A

屬性

屬性 說明 預設 存在必要性
名稱 要新增或變更的設定檔屬性名稱。 N/A
ref

要指派給設定檔屬性的值。

N/A 選用

流程變數

成功後,系統會設定下列流程變數:

  • oauthv2accesstoken.{policyName}.access_token
  • oauthv2accesstoken.{policyName}.client_id
  • oauthv2accesstoken.{policyName}.refresh_count
  • oauthv2accesstoken.{policyName}.organization_name
  • oauthv2accesstoken.{policyName}.expires_in //--in seconds
  • oauthv2accesstoken.{policyName}.refresh_token_expires_in //--in seconds
  • oauthv2accesstoken.{policyName}.issued_at
  • oauthv2accesstoken.{policyName}.status
  • oauthv2accesstoken.{policyName}.api_product_list
  • oauthv2accesstoken.{policyName}.token_type
  • oauthv2accesstoken.{policyName}.{custom_attribute_name}

結構定義

每個政策類型都由 XML 架構 (.xsd) 定義。如需參考,請前往 GitHub 查看政策架構。

錯誤參考資料

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause
steps.oauth.v2.access_token_expired 500 The access token sent to the policy is expired.
steps.oauth.v2.invalid_access_token 500 The access token sent to the policy is invalid.
steps.oauth.v2.InvalidAPICallAsNoApiProductMatchFound 401 Please see this Apigee Community post for information about troubleshooting this error.

Deployment errors

Refer to the message reported in the UI for information about deployment errors.

Fault variables

These variables are set when this policy triggers an error at runtime.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name = "invalid_access_token"
oauthV2.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. oauthV2.SetTokenInfo.failed = true
oauthV2.policy_name.fault.name policy_name is the user-specified name of the policy that threw the fault. oauthV2.SetTokenInfo.fault.name = invalid_access_token
oauthv2.policy_name.fault.cause policy_name is the user-specified name of the policy that threw the fault. oauthV2.SetTokenInfo.cause = Invalid Access Token

Example error response

{
  "fault": {
    "faultstring": "Invalid Access Token",
    "detail": {
      "errorcode": "keymanagement.service.invalid_access_token"
    }
  }
}

Example fault rule

<FaultRule name=SetOAuthV2Info Faults">
    <Step>
        <Name>AM-InvalidTokenResponse</Name>
        <Condition>(fault.name = "invalid_access_token")</Condition>
    </Step>
    <Condition>(oauthV2.failed = true) </Condition>
</FaultRule>

相關主題