Apigee는 OAuth 액세스 토큰, 갱신 토큰, 승인 코드를 생성하고 인증된 앱에 배포합니다. Apigee는 생성 시 이러한 토큰과 코드를 저장합니다.
이후에 Apigee가 이러한 토큰 또는 코드가 포함된 인바운드 API 요청을 받으면 Apigee는 저장된 정보를 사용하여 요청을 승인합니다.
Apigee는 이러한 OAuth 아티팩트를 생성할 때 토큰 또는 코드에 메타데이터를 연결합니다. 예를 들어 액세스 토큰은 만료 시간, 관련 앱 및 개발자, 기타 정보를 정의하는 이름/값 쌍과 연결되어 있습니다.
커스텀 메타데이터를 액세스 토큰에 첨부하는 것이 유용한 경우도 있습니다. 예를 들어 토큰에 사용자 이름, 그룹 멤버십, 사용자의 역할, 고객 ID, 세션 식별자, 기타 임의 정보를 추가하려고 할 수 있습니다. Apigee에서는 이러한 데이터를 '커스텀 속성'이라고 합니다. 이후에는 토큰이 API 요청의 범위 내에서 확인되면 해당 데이터는 컨텍스트 변수를 통해 API 프록시에서 사용할 수 있게 됩니다. API 프록시는 토큰에 연결된 커스텀 데이터를 기반으로 세분화된 승인 또는 라우팅 결정을 내릴 수 있습니다.
임의 데이터를 토큰에 연결하려면 OAuthV2 정책의 <Attributes> 요소를 사용합니다. 커스텀 속성의 이름과 값을 지정할 수 있습니다. 예를 들어 다음은 토큰을 생성하고 'tenant_list'라는 커스텀 속성을 토큰에 연결하는 정책 구성입니다.
여러 커스텀 속성을 지정할 수 있으며 생성 시 승인 코드(<Operation>GenerateAuthorizationCode</Operation>) 또는 토큰(<Operation>GenerateAccessToken</Operation>)에 암시적으로 연결할 수 있습니다.
display가 true(기본값)로 설정된 경우 커스텀 속성이 응답으로 반환되며 이 속성은 앱에서 보거나 최종 사용자에게 전달될 수 있습니다.
display가 false로 설정된 경우 커스텀 속성은 데이터 저장소에 저장되지만 응답 메시지에 반환되지 않습니다. 어느 경우든 토큰이 확인된 후에는 API 프록시 내의 정책에서 커스텀 데이터를 사용할 수 있습니다.
OAuthV2/VerifyAccessToken에 대한 호출이 있으면 Apigee는 토큰 저장소에서 토큰을 검색하여 확인합니다. 그런 다음 Apigee는 토큰에 대한 정보가 포함된 컨텍스트 변수 집합을 채웁니다. 예를 들면 다음과 같습니다.
organization_name
developer.id
developer.app.name
client_id
grant_type
token_type
access_token
issued_at
expires_in //--초 후
status
scope
apiproduct.name*
토큰에 커스텀 속성이 있는 경우 accesstoken.{custom_attribute}이라는 이름을 가진 컨텍스트 변수로 커스텀 속성을 사용할 수 있습니다. 예를 들어 위에 표시된 정책에서 토큰이 발급된다고 가정해 보겠습니다. 이러한 토큰을 확인하면 토큰이 생성된 시점에 저장된 값이 포함된 accesstoken.tenant_list이라는 컨텍스트 변수가 추가로 생성됩니다.
그러면 정책 또는 조건이 이러한 변수를 참조하여 저장된 값에 따라 동작을 수정할 수 있습니다.
런타임 시 커스텀 속성 설정 및 업데이트
API 호출이 Apigee에서 처리되는 동안 API 프록시는 런타임 시 액세스 토큰과 연결된 메타데이터를 업데이트해야 할 수 있습니다. 이를 위해 Apigee는 토큰 속성을 가져오고 설정하는 정책을 제공합니다. 자세한 내용은 Get OAuth V2 Info 정책 및 Set OAuth V2 Info 정책을 참조하세요.
In each of these policies, the AccessToken element should refer to a variable that
contains the access token.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-18(UTC)"],[[["\u003cp\u003eThis content covers OAuth access tokens, refresh tokens, and authorization codes generated and managed by Apigee and Apigee hybrid.\u003c/p\u003e\n"],["\u003cp\u003eApigee attaches metadata to OAuth artifacts upon generation, including details like expiration time, associated app/developer, and other relevant information.\u003c/p\u003e\n"],["\u003cp\u003eCustom attributes can be added to access tokens or authorization codes using the \u003ccode\u003e<Attributes>\u003c/code\u003e element in the OAuthV2 policy, allowing for the inclusion of arbitrary data.\u003c/p\u003e\n"],["\u003cp\u003eDuring runtime verification, Apigee populates context variables with token information, including any custom attributes, accessible via \u003ccode\u003eaccesstoken.{custom_attribute}\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAPI proxies have the ability to update the metadata of an access token at runtime using the "Get OAuth V2 Info" and "Set OAuth V2 Info" policies provided by Apigee.\u003c/p\u003e\n"]]],[],null,["# Customizing Tokens and Authorization Codes\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nAbout token and authorization code metadata\n-------------------------------------------\n\nApigee generates OAuth access tokens, refresh tokens, and authorization codes, and\ndispenses them to authenticated apps. At generation time, Apigee stores those tokens and codes.\nLater, when Apigee receives inbound API requests bearing these tokens or codes, Apigee uses the\nstored information to authorize the requests.\n\nWhen Apigee generates these OAuth artifacts, it also attaches metadata to the token or code. For\nexample, an access token is associated to name/value pairs that define expiration time, the\nassociated app and developer, and other information.\n\nThe JSON representation of an Apigee access token looks like the following: \n\n```transact-sql\n{\n \"issued_at\" : \"1372170159093\",\n \"application_name\" : \"ccd1803b-b557-4520-bd62-ddd3abf8e501\",\n \"scope\" : \"READ\",\n \"status\" : \"approved\",\n \"api_product_list\" : \"[Product1,Product2]\",\n \"api_product_list_json\" : [\"Product1\", \"Product2\"],\n \"expires_in\" : \"3599\", //--in seconds\n \"developer.email\" : \"joe@weathersample.com\",\n \"organization_id\" : \"0\",\n \"refresh_token\" : \"82XMXgDyHTpFyXOaApj8C2AGIPnN2IZe\",\n \"client_id\" : \"deAVedE0W9Z9U35PAMaAJYphBJCGdrND\",\n \"access_token\" : \"shTUmeI1geSKin0TODcGLXBNe9vp\",\n \"organization_name\" : \"apifactory\",\n \"refresh_count\" : \"0\"\n}\n```\n\nAdding custom attributes to OAuth tokens and authorization codes\n----------------------------------------------------------------\n\nSometimes it's useful to attach custom metadata to an access token. For example, you might wish\nto add a user name, group memberships or roles for a user, a customer ID, a session identifier,\nor other arbitrary information to a token. In Apigee, these data are called \"custom\nattributes.\" Subsequently, when the token is verified within the scope of an API request, that\ndata is made available to the API proxy via context variables. An API proxy could make\nfine-grained authorization or routing decisions based on the custom data that is attached to the\ntoken.\n\nTo attach arbitrary data to a token, use the `\u003cAttributes\u003e` element in\n[the OAuthV2 policy](/apigee/docs/api-platform/reference/policies/oauthv2-policy). You can\nspecify the name and value of the custom attribute. For example, here is a\npolicy configuration that generates a token and attaches a custom attribute called \"tenant_list\"\nto the token: \n\n```carbon\n\u003cOAuthV2 name=\"GenerateAccessToken\"\u003e\n \u003cOperation\u003eGenerateAccessToken\u003c/Operation\u003e\n \u003cExpiresIn\u003e600000\u003c/ExpiresIn\u003e\n \u003cGenerateResponse /\u003e\n \u003cSupportedGrantTypes\u003e\n \u003cGrantType\u003eclient_credentials\u003c/GrantType\u003e\n \u003c/SupportedGrantTypes\u003e\n \u003cGrantType\u003erequest.queryparam.grant_type\u003c/GrantType\u003e\n \u003cAttributes\u003e \n \u003cAttribute name=\"tenant_list\" ref=\"tenant_list_retrieved_from_external_service\" display=\"false\"/\u003e\n \u003c/Attributes\u003e\n\u003c/OAuthV2\u003e\n```\n\nYou can specify multiple custom attributes, and you can attach them implicitly to either an\nauthorization code (`\u003cOperation\u003eGenerateAuthorizationCode\u003c/Operation\u003e`) or\na token (`\u003cOperation\u003eGenerateAccessToken\u003c/Operation\u003e`) at the time of\ngeneration.\n\nWhen `display` is set to `true` (the default), custom attributes are\nreturned in the response, where they may be viewable by the app, or passed on to the end user.\nWhen `display` is set to `false`, custom attributes are stored in the data\nstore, but are not returned in the response message. In either case, the custom data is available\nto the policies within the API Proxy, after the token has been verified.\n\nFor more information about the `display` option, see\n[Displaying or hiding custom attributes in the response](/apigee/docs/api-platform/reference/policies/oauthv2-policy#attributesattribute-displayingorhidingcustomattributesintheresponse).\n\nGetting custom access token attributes at runtime\n-------------------------------------------------\n\nWhen there is a call to [`OAuthV2/VerifyAccessToken`](/apigee/docs/api-platform/reference/policies/oauthv2-policy),\nApigee verifies the token by looking it up in the token store. Apigee then populates a\nset of context variables containing information about the token. These include:\n\n- `organization_name`\n- `developer.id`\n- `developer.app.name`\n- `client_id`\n- `grant_type`\n- `token_type`\n- `access_token`\n- `issued_at`\n- `expires_in` //--in seconds\n- `status`\n- `scope`\n- `apiproduct.name*`\n\nIf there are any custom attributes on the token, those custom attributes are made available in\na context variable with the name `accesstoken.{custom_attribute}`. For example,\nsuppose a token is issued from the policy shown above. After verifying such a token, there would\nbe an additional context variable named `accesstoken.tenant_list`, containing the\nvalue that was stored at the time the token was generated.\n\nPolicies or conditions can then refer to these variables and modify behavior based on the\nvalues stored within.\n\nSetting and updating custom attributes at\nruntime\n-------------------------------------------------\n\nIn some situations, you will want your API Proxy to update the metadata associated to an\naccess token at runtime while an API call is being processed on Apigee. To help with this,\nApigee provides policies for getting and setting token attributes. For more information, see\n[Get OAuth V2 Info\npolicy](/apigee/docs/api-platform/reference/policies/get-oauth-v2-info-policy) and [Set OAuth\nV2 Info policy](/apigee/docs/api-platform/reference/policies/set-oauth-v2-info-policy).\n\n\nIn each of these policies, the `AccessToken` element should refer to a variable that\ncontains the access token."]]