本頁內容適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
結果
刪除指定的 OAuth V2 授權碼或存取權杖。
這項政策是可擴充政策,使用這項政策可能會產生費用或影響用量,具體情況取決於您的 Apigee 授權。如要瞭解政策類型和使用方式的影響,請參閱「政策類型」。
範例
刪除存取權杖
以下是刪除 OAuth 2.0 存取權杖的範例政策。以下範例會尋找名為 access_token
的標頭,在要求訊息中找出要刪除的存取權杖。
<DeleteOAuthV2Info name="DeleteAccessToken"> <AccessToken ref="request.header.access_token"></AccessToken> </DeleteOAuthV2Info>
刪除驗證碼
以下是刪除 OAuth 2.0 授權碼的政策範例。以下範例會尋找名為 code
的查詢參數,在要求訊息中找出要刪除的授權碼。
<DeleteOAuthV2Info name="DeleteAuthCode"> <AuthorizationCode ref="request.queryparam.code"></AuthorizationCode> </DeleteOAuthV2Info>
元素參照
元素參照說明 DeleteOAuthV2Info 政策的元素和屬性。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <DeleteOAuthV2Info async="false" continueOnError="false" enabled="true" name="DeleteOAuthV2Info-1"> <DisplayName>Delete OAuth v2.0 Info 1</DisplayName> <AccessToken ref={some-variable}></AccessToken> <!--<AuthorizationCode ref={some-variable}></AuthorizationCode>--> <Attributes/> </DeleteOAuthV2Info
<DeleteOAuthV2Info> 屬性
<DeleteOAuthV2Info async="false" continueOnError="false" enabled="true" name="Delete-OAuth-v20-Info-1">
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
非同步 |
設為 這項設定僅用於內部最佳化。 |
false | 選用 |
continueOnError |
發生失敗時,大多數政策都會傳回錯誤。將此屬性設為 |
false | 選用 |
已啟用 | 決定是否要強制執行政策。如果設為 false ,政策會「關閉」且不會強制執行 (即使政策仍附加至 Flow)。 |
是 | 選用 |
名稱 |
政策的內部名稱。這個名稱會在「步驟」元素中參照,將政策附加至流程。 注意:名稱只能使用以下字元:
|
不適用 | 必填 |
<AccessToken> 元素
指出要刪除的存取權杖所在的變數。舉例來說,如果存取權杖以名為「access_token」的查詢參數形式附加至要求訊息,請指定 request.queryparam.access_token
。您可以使用任何參照權杖的有效變數。或者,也可以傳入常值權杖字串 (極少數情況)。
<AccessToken ref="request.queryparam.access_token"></AccessToken>
預設值: | 不適用 |
外觀狀態: | 您必須使用 <AccessToken> 或 <AuthorizationCode> 其中之一。 |
類型: | 字串 |
屬性
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
ref |
存取權杖變數。通常是從流程變數擷取。例如: |
不適用 | 選用 |
<AuthorizationCode> 元素
找出要刪除授權碼的變數。舉例來說,如果驗證碼以名為「code」的查詢參數形式附加至要求訊息,請指定 request.queryparam.code
。您可以使用任何參照權杖的有效變數。
或者,也可以傳入常值權杖字串 (極少數情況)。
<AuthorizationCode ref="request.queryparam.code"></AuthorizationCode>
預設值: | 不適用 |
外觀狀態: | 您必須使用 <AccessToken> 或 <AuthorizationCode> 其中之一。 |
類型: | 字串 |
屬性
屬性 | 說明 | 預設 | 存在必要性 |
---|---|---|---|
ref |
存取權杖變數。通常是從流程變數擷取。例如: |
不適用 | 選用 |
<DisplayName> 元素
以自然語言為原則命名,方便在 Apigee UI 代理項目編輯器中識別。如果省略這個屬性,系統會使用政策名稱屬性。
<DisplayName>DeleteOAuthV2Info 1</DisplayName>
預設值: | 政策的 name 屬性值。 |
外觀狀態: | 選用 |
類型: | 字串 |
錯誤參考資料
This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee 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.invalid_access_token |
401 |
The access token sent to the policy is invalid. |
steps.oauth.v2.invalid_request-authorization_code_invalid |
401 |
The authorization code sent to the policy is invalid. |
steps.oauth.v2.InvalidAPICallAsNoApiProductMatchFound |
401 |
Please see Oauth2.0 Access Token Verification throws "Invalid API call as no apiproduct match found" error 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.DeleteTokenInfo.failed = true |
oauthV2.policy_name.fault.name |
policy_name is the user-specified name of the policy that threw the fault. | oauthV2.DeleteTokenInfo.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.DeleteTokenInfo.cause = Invalid Access Token |
Example error response
{ "fault": { "faultstring": "Invalid Access Token", "detail": { "errorcode": "keymanagement.service.invalid_access_token" } } }
Example fault rule
<faultrule name="VariableOfNonMsgType"></faultrule><FaultRule name="DeleteOAuthV2Info_Faults"> <Step> <Name>AM-InvalidTokenResponse</Name> </Step> <Condition>(fault.name = "invalid_access_token")</Condition> </FaultRule>
結構定義
每個政策類型都由 XML 架構 (.xsd
) 定義。如需參考,請前往 GitHub 查看政策架構。