---
title: OAuth Token object reference
description: "Access the OAuth Token object in Groovy policyCtx?.context.get(\"oauth_token\")."
component: pingaccess
version: 9.0
page_id: pingaccess:reference_guides:pa_oauth_token_object_ref
canonical_url: https://docs.pingidentity.com/pingaccess/9.0/reference_guides/pa_oauth_token_object_ref.html
revdate: June 13, 2024
section_ids:
  purpose: Purpose
  groovy-sample: Groovy sample
  method-summary: Method summary
---

# OAuth Token object reference

Access the OAuth Token object in Groovy `policyCtx?.context.get("oauth_token")`.

## Purpose

The OAuthToken object contains the OAuth *(tooltip: \<div class="paragraph">
\<p>A standard framework that enables an application (OAuth client) to obtain access tokens from an OAuth authorization server for the purpose of retrieving protected resources on a resource server.\</p>
\</div>)* access token and related identity attributes. The OAuthToken instance is available only for OAuth Groovy script rules.

## Groovy sample

```
def scopes = policyCtx?.context.get("oauth_token")?.scopes
def attr = policyCtx?.context.get("oauth_token")?.attributes
def username = policyCtx?.context.get("oauth_token")?.attributes?.get("username")?.get(0)
exc?.request?.header?.add("x-scopes", "$scopes")
exc?.request?.header?.add("x-attributes", "$attr")
exc?.request?.header?.add("x-username", "$username")
pass()
```

## Method summary

| Method                                      | Description                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Instant getExpiresAt()`                    | Contains the expiration instant of the OAuth access token.                                                                                                                                                                                                                                                                                                                                       |
| `Instant getRetrievedAt()`                  | Contains the instant that the OAuth access token was retrieved from PingFederate.                                                                                                                                                                                                                                                                                                                |
| `String getTokenType()`                     | Contains the type of OAuth access token. (Bearer, JSON Web Token (JWT) *(tooltip: \<div class="paragraph">&#xA;\<p>An IETF standard container format for a JSON object used for the secure exchange of content, such as identity or entitlement information. You can find the industry standard in \<a href="https\://datatracker.ietf.org/doc/html/rfc7519">RFC 7519\</a>.\</p>&#xA;\</div>)*). |
| `String getClientId()`                      | Contains the client ID associated with the OAuth access token.                                                                                                                                                                                                                                                                                                                                   |
| `Set getScopes()`                           | Contains the set of scopes associated with the OAuth access token.                                                                                                                                                                                                                                                                                                                               |
| `Map<String, List<String> >getAttributes()` | Contains a map of identity attributes specific to the user.                                                                                                                                                                                                                                                                                                                                      |
