[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThis policy, applicable to Apigee and Apigee hybrid, allows for adding or updating custom attributes to an existing, valid access token, such as a department name or customer ID.\u003c/p\u003e\n"],["\u003cp\u003eThe policy can only modify custom attributes, and cannot alter standard fields like scope, status, expires_in, or client_id, but will update attributes if they exist, otherwise add new ones.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003e<SetOAuthV2Info>\u003c/code\u003e element is central to the policy, where attributes like \u003ccode\u003ename\u003c/code\u003e, \u003ccode\u003econtinueOnError\u003c/code\u003e, \u003ccode\u003eenabled\u003c/code\u003e, and \u003ccode\u003easync\u003c/code\u003e are configured to control the policy's behavior.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003e<AccessToken>\u003c/code\u003e element specifies the location of the access token, while the \u003ccode\u003e<Attributes>\u003c/code\u003e and nested \u003ccode\u003e<Attribute>\u003c/code\u003e elements define the custom properties to be added or updated.\u003c/p\u003e\n"],["\u003cp\u003eErrors such as \u003ccode\u003esteps.oauth.v2.access_token_expired\u003c/code\u003e or \u003ccode\u003esteps.oauth.v2.invalid_access_token\u003c/code\u003e may occur, with variables like \u003ccode\u003efault.name\u003c/code\u003e and \u003ccode\u003eoauthV2.{policyName}.failed\u003c/code\u003e being set upon such errors for fault rule handling.\u003c/p\u003e\n"]]],[],null,["# SetOAuthV2Info policy\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\n### What\n\nLets you add or update custom attributes associated with an access token. Custom attributes\nmight include things like department name, a customer ID, or a session identifier. See also\n[Customizing Tokens and\nAuthorization Codes](/apigee/docs/api-platform/security/oauth/customizing-access-tokens).\n\nYou can only add or modify custom attributes. You cannot use this policy to change fields like\nscope, status, expires_in, developer_email, client_id, org_name, or refresh_count. If an\nattribute already exists, this policy updates it. If it does not exist, the policy adds it. The\naccess token referenced must be valid and in an approved state.\n\nThis policy is an *Extensible policy* and use of this policy might have cost or\nutilization implications, depending on your Apigee license. For information on policy types\nand usage implications, see\n[Policy types](/apigee/docs/api-platform/reference/policies/reference-overview-policy#policy-types).\n\nSamples\n-------\n\n### Basic example\n\nBelow is an example policy used to update an OAuth 2.0 access token. The example below\nlocates the access token on the request message by looking for a query parameter called\n`access_token`. When an access token is presented by a client app, the policy\nbelow will locate the access token in the query parameter. It will then update the access\ntoken's profile. It adds a custom property called `department.id` to the\nprofile. \n\n```scdoc\n\u003cSetOAuthV2Info name=\"SetOAuthV2Info\"\u003e \n \u003cAccessToken ref=\"request.queryparam.access_token\"\u003e\u003c/AccessToken\u003e\n \u003cAttributes\u003e\n \u003cAttribute name=\"department.id\" ref=\"request.queryparam.department_id\"\u003e\u003c/Attribute\u003e\n \u003c/Attributes\u003e\n\u003c/SetOAuthV2Info\u003e\n```\n| **Note:** If an attribute already exists in the access token profile, then it will be updated with the new value in the policy. If an attribute does not exist, then the attribute will be added to the access token's profile.\n\n*** ** * ** ***\n\nElement Reference\n-----------------\n\nThe element reference describes the elements and attributes of the SetOAuthV2 policy. \n\n```gdscript\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?\u003e\n\u003cSetOAuthV2Info async=\"false\" continueOnError=\"false\" enabled=\"true\" name=\"SetOAuthV2Info-1\"\u003e \n \u003cDisplayName\u003eSet OAuth v2.0 Info 1\u003c/DisplayName\u003e\n \u003cAccessToken ref={some-variable}\u003e\u003c/AccessToken\u003e\n \u003cAttributes/\u003e\n\u003c/SetOAuthV2Info\u003e\n\u003c/xml\u003e\n```\n\n\\\u003cSetOAuthV2Info\\\u003e attributes\n-----------------------------\n\n```text\n\u003cSetOAuthV2Info async=\"false\" continueOnError=\"false\" enabled=\"true\" name=\"Set-OAuth-v20-Info-1\"\u003e\n```\n\nThe following table describes attributes that are common to all policy parent elements:\n\n\\\u003cDisplayName\\\u003e element\n-----------------------\n\nUse in addition to the `name` attribute to label the policy in the\nmanagement UI proxy editor with a different, natural-language name. \n\n```text\n\u003cDisplayName\u003ePolicy Display Name\u003c/DisplayName\u003e\n```\n\n\\\u003cAccessToken\\\u003e element\n-----------------------\n\nIdentifies the variable where the access token is located. For example, if the access token is\nattached to request message as a query parameter, specify\n`request.queryparam.access_token`. You can use any valid variable that references the\ntoken. Or, could pass in the literal token string (rare case). \n\n```scdoc\n \u003cAccessToken ref=\"request.queryparam.access_token\"\u003e\u003c/AccessToken\u003e\n```\n\n### Attributes\n\n\\\u003cAttributes\\\u003e element\n----------------------\n\nA set of attributes in the access token profile that will be modified or augmented.\n\n\\\u003cAttributes\\\u003e/\\\u003cAttribute\\\u003e element\n------------------------------------\n\nAn individual attribute to update.\n\nThe name attribute identifies the custom property of the access token profile to be\nupdated. This example shows how to use a referenced variable value and a static value. \n\n```scdoc\n \u003cAttributes\u003e\n \u003cAttribute name=\"department.id\" ref=\"request.queryparam.department_id\"\u003e\u003c/Attribute\u003e\n \u003cAttribute name=\"foo\"\u003ebar\u003c/Attribute\u003e\n \u003c/Attributes\u003e\n```\n\n### Attributes\n\nFlow variables\n--------------\n\nOn success, the following flow variables will be set:\n\n- `oauthv2accesstoken.{policyName}.access_token`\n- `oauthv2accesstoken.{policyName}.client_id`\n- `oauthv2accesstoken.{policyName}.refresh_count`\n- `oauthv2accesstoken.{policyName}.organization_name`\n- `oauthv2accesstoken.{policyName}.expires_in //--in seconds`\n- `oauthv2accesstoken.{policyName}.refresh_token_expires_in //--in seconds`\n- `oauthv2accesstoken.{policyName}.issued_at`\n- `oauthv2accesstoken.{policyName}.status`\n- `oauthv2accesstoken.{policyName}.api_product_list`\n- `oauthv2accesstoken.{policyName}.token_type`\n- `oauthv2accesstoken.{policyName}.{custom_attribute_name}`\n\nSchema\n------\n\nEach policy type is defined by an XML schema (`.xsd`). For reference, [policy schemas](https://github.com/apigee/api-platform-samples/tree/master/schemas/policy)\nare available on GitHub.\n\nError reference\n---------------\n\n\nThis 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.\nThis information is important to know if you are developing fault rules to\nhandle faults. To learn more, see [What you need to know\nabout policy errors](/apigee/docs/api-platform/fundamentals/what-you-need-know-about-policy-errors) and [Handling\nfaults](/apigee/docs/api-platform/fundamentals/fault-handling).\n\n### Runtime errors\n\nThese errors can occur when the policy executes.\n\n### Deployment errors\n\nRefer to the message reported in the UI for information about deployment errors.\n\n### Fault variables\n\nThese variables are set when this policy triggers an error at runtime.\n| **Note:** You an use these variables to create Fault Rule conditions. For more information, see [What you need to know\n| about policy errors](/apigee/docs/api-platform/fundamentals/what-you-need-know-about-policy-errors).\n\n### Example error response\n\n```scdoc\n{\n \"fault\": {\n \"faultstring\": \"Invalid Access Token\",\n \"detail\": {\n \"errorcode\": \"keymanagement.service.invalid_access_token\"\n }\n }\n}\n```\n\n### Example fault rule\n\n```scdoc\n\u003cFaultRule name=SetOAuthV2Info Faults\"\u003e\n \u003cStep\u003e\n \u003cName\u003eAM-InvalidTokenResponse\u003c/Name\u003e\n \u003cCondition\u003e(fault.name = \"invalid_access_token\")\u003c/Condition\u003e\n \u003c/Step\u003e\n \u003cCondition\u003e(oauthV2.failed = true) \u003c/Condition\u003e\n\u003c/FaultRule\u003e\n```\n\n\u003cbr /\u003e\n\nRelated topics\n--------------\n\n- [OAuthV2 policy](/apigee/docs/api-platform/reference/policies/oauthv2-policy)\n- [OAuth home](/apigee/docs/api-platform/security/oauth/oauth-home)\n- [Customizing Tokens\n and Authorization Codes](/apigee/docs/api-platform/security/oauth/customizing-access-tokens)"]]