---
title: Decoding attributes
description: The readToken method inspects the cookie (or query parameters, depending on the configuration of the agent instance) and decodes the OpenToken, returning a Collection of attributes or null if no token is found or an error is encountered. In the case of an error, a TokenException is thrown.
component: java
page_id: java:setup:pf_java_ik_decoding_attributes
canonical_url: https://docs.pingidentity.com/integrations/java/setup/pf_java_ik_decoding_attributes.html
revdate: June 21, 2024
section_ids:
  sample-code: Sample code
---

# Decoding attributes

The `readToken` method inspects the cookie (or query parameters, depending on the configuration of the agent instance) and decodes the `OpenToken`, returning a `Collection` of attributes or `null` if no token is found or an error is encountered. In the case of an error, a `TokenException` is thrown.

The following example code shows how to use the `readToken` method:

|   |                                                                                                                                                                                   |
| - | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|   | This code is the same for both the Java native and Apache commons multimap methods described in [Reading and writing OpenTokens](pf_java_ik_reading_and_writing_opentokens.html). |

## Sample code

```
try {
   //See the "Reading and writing OpenTokens" topic for sample code
   //that instantiates and configures an Agent instance

Map userInfo = agent.readToken(request);
if(userInfo != null) {
    String username = (String)userInfo.get(Agent.TOKEN_SUBJECT);
}
}
catch(TokenException e) {
   // Handle exception
}
```
