Hi @Varun Singh You can associate Custom attributes & scope to tokens while generating them in Edge.
Custom Attributes
You can include the attributes into your token by specifying them under section in GenerateAccessToken policy as indicated below -
<OAuthV2 name="GenerateAccessToken">
<Operation>GenerateAccessToken
</Operation>
<ExpiresIn>1000</ExpiresIn>
<GenerateResponse />
<SupportedGrantTypes>
<GrantType>client_credentials</GrantType>
</SupportedGrantTypes>
<GrantType>request.queryparam.grant_type</GrantType>
<Attributes>
<Attribute name="user-agent" ref="request.header.user-agent" display="false"></Attribute>
<Attribute name="custom-attr" ref="request.queryparam.abc" display="false"></Attribute>
</Attributes>
</OAuthV2>
Please see this page for more details on customising the token. Once the token is generated you get or set token properties using the Get or Set OAuth V2 Info policy. You can also do this with the management API calls.
Scope
When Edge generates an access token, it may assign a scope to that token. The scope is determined based on the Product(s) the app is associated to.
However when a client app requests an access token from Apigee Edge, it can optionally specify which scopes it would like to have associated with that token.
For example, the following request asks for the scope “READ”. That is, the client is asking that the authorization server (Edge) generate an access token that has scope “READ” (giving the app authorization to call APIs that have scope “READ”). The app sends a POST request like this:
curl -i -X POST -H Authorization: Basic Mg12YTk2UkEIyIBCrtro1QpIG -H content-type:application/x-www-form-urlencoded [http://myorg-test.apigee.net/oauth/token?grant_type=client_credentials&scope=READ](http://myorg-test.apigee.net/oauth/token?grant_type=client_credentials&scope=READ)
When Edge receives this request it knows which app is making the request and it knows which developer app the client registered (the client ID and client secret keys are encoded in the basic auth header). Because the scope query parameter is included, Edge needs to decide if any of the API products associated with the developer app have scope “READ”. If they do, then an access token is generated with scope “READ”.
What if the client does not attach a scope parameter? In this case, Edge generates a token that includes all of the scopes recognized by the developer app. It’s important to understand that the default behavior is to return an access token that contains the union of all scopes for all of the products included in the developer app. The page here has additional details on working with Scopes.
AFIAK once generated the scope attribute can’t be changed with Set OAuth V2 or via management API. However you can ask for a different scope on the refresh token call.
Hope this helps!