OAuth V2 정책 취소

이 페이지는 ApigeeApigee Hybrid에 적용됩니다.

Apigee Edge 문서 보기

개요

개발자 앱 ID, 앱 최종 사용자 ID 또는 둘 다와 연결된 OAuth2 액세스 토큰을 취소합니다.

이 정책은 확장 가능한 정책이며, 이 정책을 사용하면 Apigee 라이선스에 따라 비용 또는 사용률이 영향을 받을 수 있습니다. 정책 유형 및 사용 영향에 대한 자세한 내용은 정책 유형을 참조하세요.

OAuthv2 정책을 사용하여 OAuth 2.0 액세스 토큰을 생성합니다. Apigee 생성 토큰 형식은 다음과 같습니다.

{
  "issued_at" : "1421847736581",
  "application_name" : "a68d01f8-b15c-4be3-b800-ceae8c456f5a",
  "scope" : "READ",
  "status" : "approved",
  "api_product_list" : "[PremiumWeatherAPI]",
  "expires_in" : "3599", //--in seconds
  "developer.email" : "tesla@weathersample.com",
  "organization_id" : "0",
  "token_type" : "BearerToken",
  "client_id" : "k3nJyFJIA3p62DWOkLO6OJNi87GYXFmP",
  "access_token" : "7S22UqXGJDTuUADGzJzjXzXSaGJL",
  "organization_name" : "myorg",
  "refresh_token_expires_in" : "0", //--in seconds
  "refresh_count" : "0"
}

application_name 요소에는 토큰과 연결된 개발자 앱 ID가 포함됩니다.

기본적으로 Apigee는 토큰에 최종 사용자 ID를 포함하지 않습니다. OAuthv2 정책<AppEndUser> 요소를 추가하면 Apigee가 최종 사용자 ID를 포함하도록 구성할 수 있습니다.

<OAuthV2 name="GenerateAccessTokenClient">
    <Operation>GenerateAccessToken</Operation>
    ...
    <AppEndUser>request.queryparam.app_enduser</AppEndUser>
</OAuthV2>

이 예시에서는 최종 사용자 ID를 app_enduser라는 쿼리 매개변수의 OAuthv2 정책에 전달합니다. 그러면 최종 사용자 ID가 app_enduser 요소의 토큰에 포함됩니다.

{
 "issued_at" : "1421847736581",
 "application_name" : "a68d01f8-b15c-4be3-b800-ceae8c456f5a",
 "scope" : "READ",
 "app_enduser" : "6ZG094fgnjNf02EK",
 "status" : "approved",
 "api_product_list" : "[PremiumWeatherAPI]",
 "expires_in" : "3599", //--in seconds
 "developer.email" : "tesla@weathersample.com",
 "organization_id" : "0",
 "token_type" : "BearerToken",
 "client_id" : "k3nJyFJIA3p62DWOkLO6OJNi87GYXFmP",
 "access_token" : "7S22UqXGJDTuUADGzJzjXzXSaGJL",
 "organization_name" : "myorg",
 "refresh_token_expires_in" : "0", //--in seconds
 "refresh_count" : "0"
}

개발자 앱 ID로 취소

개발자 앱 ID와 연결된 OAuth2 액세스 토큰을 취소합니다. Apigee에서 생성한 모든 OAuth2 액세스 토큰에는 토큰과 연결된 개발자 앱의 ID가 포함됩니다. 그러면 앱 ID에 따라 토큰을 취소할 수 있습니다.

특정 개발자의 앱 ID 목록을 가져오려면 다음을 사용합니다.

앱 최종 사용자 ID로 취소

특정 앱 최종 사용자의 ID에 연결된 OAuth2 액세스 토큰을 취소합니다. 이 토큰은 토큰이 발급된 사용자의 ID와 연결됩니다.

기본적으로 OAuth 액세스 토큰에는 최종 사용자 ID 필드가 없습니다. 최종 사용자 ID별로 OAuth 2.0 액세스 토큰 취소를 사용 설정하려면 위와 같이 토큰에 사용자 ID가 포함되도록 OAuthv2 정책을 구성해야 합니다.

메서드: organizations.developers.get을 사용하여 앱 최종 사용자 ID를 가져옵니다.

샘플

다음 샘플에서는 OAuth V2 정책 취소를 사용하여 OAuth2 액세스 토큰을 취소합니다.

개발자 앱 ID

개발자 앱 ID로 액세스 토큰을 취소하려면 정책에서 <AppId> 요소를 사용합니다.

다음 예시는 app_id라는 쿼리 매개변수에서 액세스 토큰의 개발자 앱 ID를 찾으려고 합니다.

<RevokeOAuthV2 continueOnError="false" enabled="true" name="MyRevokeTokenPolicy">
  <DisplayName>Revoke OAuth v2.0-1</DisplayName>
  <AppId ref="request.queryparam.app_id"></AppId>
</RevokeOAuthV2>

개발자 앱 ID가 지정되면 정책은 액세스 토큰을 취소합니다.

이전 타임스탬프 취소

특정 날짜와 시간 이전에 생성된 개발자 앱 ID로 액세스 토큰을 취소하려면 정책의 <RevokeBeforeTimestamp> 요소를 사용합니다. <RevokeBeforeTimestamp>는 UTC 에포크 시간을 밀리초 단위로 지정합니다. 이 시간 이전에 발급된 모든 토큰은 취소됩니다.

다음 예시는 2019년 7월 1일 이전에 만든 개발자 앱의 액세스 토큰을 취소합니다.

<RevokeOAuthV2 continueOnError="false" enabled="true" name="MyRevokeTokenPolicy">
  <DisplayName>Revoke OAuth v2.0-1</DisplayName>
  <AppId ref="request.queryparam.app_id"></AppId>
  <RevokeBeforeTimestamp>1561939200000</RevokeBeforeTimestamp>
</RevokeOAuthV2>

<RevokeBeforeTimestamp> 요소는 1970년 1월 1일 자정(UTC) 이후부터 경과된 밀리초 수를 나타내는 64비트(긴) 정수를 취합니다.


요소 참조

요소 참조는 RevokeOAuthV2 정책의 요소 및 속성을 설명합니다.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RevokeOAuthV2 continueOnError="false" enabled="true" name="GetOAuthV2Info-1">
  <DisplayName>Get OAuth v2.0 Info 1</DisplayName>
  <AppId ref="variable"></AppId>
  <EndUserId ref="variable"></EndUserId>
  <RevokeBeforeTimestamp ref="variable"></RevokeBeforeTimestamp>
  <Cascade>false</Cascade>
</RevokeOAuthV2>

<RevokeOAuthV2> 속성

<RevokeOAuthV2 continueOnError="false" enabled="true" name="Revoke-OAuth-v20-1">

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails.

false Optional
enabled

Set to true to enforce the policy.

Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<AppId> 요소

취소할 토큰의 개발자 앱 ID를 지정합니다. 앱 ID나 리터럴 앱 ID가 포함된 변수를 전달합니다.

<AppId>appIdString</AppId>

or:

<AppId ref="request.queryparam.app_id"></AppId>
기본값

request.formparam.app_id(x-www-form-urlencoded 형식으로 요청 본문에 지정됨)

접속 상태

선택사항

유형 문자열
유효한 값

앱 ID 문자열이 포함된 흐름 변수 또는 리터럴 문자열

<Cascade> 요소

true이고 기존의 비공개 액세스 토큰이 있는 경우 <AppId> 또는 <EndUserId>가 일치하면 갱신 토큰과 액세스 토큰이 모두 취소됩니다. JWT 액세스 토큰이 있는 경우 액세스 토큰과 함께 발급된 갱신 토큰만 취소됩니다. 기본적으로 JWT 액세스 토큰은 취소할 수 없습니다. false인 경우 액세스 토큰만 취소되고 갱신 토큰은 변경되지 않습니다. 비공개 액세스 토큰에만 동일한 동작이 적용됩니다. JWT 액세스 토큰은 취소할 수 없습니다.

<Cascade>false<Cascade>
기본값

거짓

접속 상태

선택사항

유형 불리언
유효한 값 true 또는 false

<EndUserId> 요소

취소할 토큰의 앱 최종 사용자 ID를 지정합니다. 사용자 ID나 리터럴 토큰 문자열이 포함된 변수를 전달합니다.

<EndUserId>userIdString</EndUserId>

or:

<EndUserId ref="request.queryparam.access_token"></EndUserId>
기본값

request.formparam.enduser_id(x-www-form-urlencoded 형식으로 요청 본문에 지정됨)

접속 상태

선택사항

유형 문자열
유효한 값

사용자 ID 문자열이 포함된 흐름 변수나 리터럴 문자열

<RevokeBeforeTimestamp> 요소

타임스탬프 이전에 발행된 토큰을 취소합니다. 이 요소는 <AppId><EndUserId>와 함께 작동하여 특정 시간 전에 토큰을 취소할 수 있습니다. 기본값은 정책이 실행되는 시간입니다.

<RevokeBeforeTimestamp>timeStampString</RevokeBeforeTimestamp>

or:

<RevokeBeforeTimestamp ref="request.queryparam.revoke_since_timestamp"></RevokeBeforeTimestamp>
기본값

정책이 실행되는 타임스탬프입니다.

접속 상태

선택사항

유형 1970년 1월 1일 자정(UTC) 이후 경과된 밀리초 수를 나타내는 64비트 정수입니다.
유효한 값

타임스탬프가 포함된 흐름 변수 또는 리터럴 타임스탬프. 타임스탬프는 미래 날짜일 수 없으며 2014년 1월 1일 이전일 수 없습니다.

흐름 변수

RevokeOAuthV2 정책은 흐름 변수를 설정하지 않습니다.

오류 참조

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. The error names shown below are the strings that are assigned to the fault.name variable when an error occurs. See the Fault variables section below for more details.

Fault code HTTP status Cause
steps.oauth.v2.InvalidFutureTimestamp 500 Timestamp cannot be in the future.
steps.oauth.v2.InvalidEarlyTimestamp 500 Timestamp cannot be earlier than January 1, 2014.
steps.oauth.v2.InvalidTimestamp 500 Timestamp is invalid.
steps.oauth.v2.EmptyAppAndEndUserId 500 Both AppdId and EndUserId cannot be empty.

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 Matches "IPDeniedAccess"
oauthV2.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. oauthV2.GetTokenInfo.failed = true
oauthV2.policy_name.fault.name policy_name is the user-specified name of the policy that threw the fault. oauthV2.GetToKenInfo.fault.name = invalid_client-invalid_client_id
oauthV2.policy_name.fault.cause policy_name is the user-specified name of the policy that threw the fault. oauthV2.GetTokenInfo.cause = ClientID is Invalid

Example error response

{
   "fault":{
      "faultstring":"Timestamp is in the future.",
      "detail":{
         "errorcode":"steps.oauth.v2.InvalidFutureTimestamp"
      }
   }
}

Example fault rule

<FaultRule name="RevokeOAuthV2 Faults">
    <Step>
        <Name>AM-InvalidTimestamp</Name>
    </Step>
    <Condition>(fault.name = "InvalidFutureTimestamp")</Condition>
</FaultRule>

관련 주제