查看 Apigee Edge 說明文件。
前往
Apigee X說明文件。 資訊

結果
可讓您新增或更新與存取權杖相關聯的自訂屬性。自訂屬性 可能包括部門名稱、客戶 ID 或工作階段 ID其他參考資訊 自訂權杖和 授權碼。
而只能新增或修改自訂屬性。您無法依據這項政策變更以下欄位: 範圍、status、expiration_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 |
政策的內部名稱。 視需要使用 |
不適用 | 必填 |
continueOnError |
如果設為「 如果設為 |
false | 選用 |
enabled |
如要強制執行政策,請設為 設為 |
true | 選用 |
async |
此屬性已淘汰。 |
false | 已淘汰 |
<DisplayName>元素
除 name
屬性外,一併使用
管理 UI Proxy 編輯器,使用不同的自然語言名稱。
<DisplayName>Policy Display Name</DisplayName>
預設 |
不適用 如果省略這個元素,政策的 |
---|---|
存在必要性 | 選用 |
類型 | 字串 |
<AccessToken>元素
識別存取權杖所在的變數。舉例來說,如果存取權杖是
做為查詢參數附加在要求訊息中
request.queryparam.access_token
。您可以使用任何參照
產生下一個符記或者,也可以傳入常值權杖字串 (極少有大小寫之分)。
<AccessToken ref="request.queryparam.access_token"></AccessToken>
預設: | 不適用 |
所在地: | 必填 |
類型: | 字串 |
屬性
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
參考資料 |
存取權杖變數。通常擷取自流程變數。 |
不適用 | 選用 |
<Attributes>元素
存取權杖設定檔中的一組屬性,會修改或擴充。
預設: | 不適用 |
所在地: | 必填 |
類型: | 不適用 |
<Attributes>/<Attribute>元素
要更新的個別屬性。
名稱屬性可識別要存取權杖設定檔的自訂屬性 已更新。本例說明如何使用參照的變數值和靜態值。
<Attributes> <Attribute name="department.id" ref="request.queryparam.department_id"></Attribute> <Attribute name="foo">bar</Attribute> </Attributes>
預設: | 不適用 |
所在地: | 選用 |
類型: | 不適用 |
屬性
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
名稱 | 要新增或變更的個人資料屬性名稱。 | 不適用 | |
參考資料 |
要指派給設定檔屬性的值。 |
不適用 | 選用 |
流程變數
成功後,將設定下列流程變數:
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>