# Class IdToken (1.39.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.39.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdToken)
- [1.38.2](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.38.2/com.google.api.client.auth.openidconnect.IdToken)
- [1.37.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.37.0/com.google.api.client.auth.openidconnect.IdToken)
- [1.36.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.36.0/com.google.api.client.auth.openidconnect.IdToken)
- [1.34.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.34.1/com.google.api.client.auth.openidconnect.IdToken)
- [1.33.3](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.33.3/com.google.api.client.auth.openidconnect.IdToken)
- [1.32.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.32.1/com.google.api.client.auth.openidconnect.IdToken)

    public class IdToken extends JsonWebSignature

Beta   

ID token as described in [ID Token](http://openid.net/specs/openid-connect-basic-1_0-27.html#id_token).

Use [#parse(JsonFactory, String)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdToken#com_google_api_client_auth_openidconnect_IdToken_parse_com_google_api_client_json_JsonFactory_java_lang_String_) to parse an ID token from a string. Then, use the
`verify` methods to verify the ID token as required by the specification.

Implementation is not thread-safe.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [JsonWebToken](https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.json.webtoken.JsonWebToken.html) \> com.google.api.client.json.webtoken.JsonWebSignature \> IdToken

## Inherited Members

com.google.api.client.json.webtoken.JsonWebSignature.getHeader() com.google.api.client.json.webtoken.JsonWebSignature.getSignatureBytes() com.google.api.client.json.webtoken.JsonWebSignature.getSignedContentBytes() com.google.api.client.json.webtoken.JsonWebSignature.parse(com.google.api.client.json.JsonFactory,java.lang.String) com.google.api.client.json.webtoken.JsonWebSignature.parser(com.google.api.client.json.JsonFactory) com.google.api.client.json.webtoken.JsonWebSignature.signUsingRsaSha256(java.security.PrivateKey,com.google.api.client.json.JsonFactory,com.google.api.client.json.webtoken.JsonWebSignature.Header,com.google.api.client.json.webtoken.JsonWebToken.Payload) com.google.api.client.json.webtoken.JsonWebSignature.verifySignature() com.google.api.client.json.webtoken.JsonWebSignature.verifySignature(java.security.PublicKey) com.google.api.client.json.webtoken.JsonWebSignature.verifySignature(javax.net.ssl.X509TrustManager) com.google.api.client.json.webtoken.JsonWebToken.getPayload() com.google.api.client.json.webtoken.JsonWebToken.toString() [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### parse(JsonFactory jsonFactory, String idTokenString)

    public static IdToken parse(JsonFactory jsonFactory, String idTokenString)

Parses the given ID token string and returns the parsed ID token.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `jsonFactory` | `com.google.api.client.json.JsonFactory` JSON factory |
| `idTokenString` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` ID token string |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdToken` | parsed ID token |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

## Constructors

### IdToken(JsonWebSignature.Header header, IdToken.Payload payload, byte\[\] signatureBytes, byte\[\] signedContentBytes)

    public IdToken(JsonWebSignature.Header header, IdToken.Payload payload, byte[] signatureBytes, byte[] signedContentBytes)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `header` | `com.google.api.client.json.webtoken.JsonWebSignature.Header` header |
| `payload` | `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdToken.Payload` payload |
| `signatureBytes` | `byte[]` bytes of the signature |
| `signedContentBytes` | `byte[]` bytes of the signature content |

## Methods

### getPayload()

    public IdToken.Payload getPayload()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdToken.Payload` |   |

**Overrides** com.google.api.client.json.webtoken.JsonWebToken.getPayload()

### verifyAudience(Collection\<String\> trustedClientIds)

    public final boolean verifyAudience(Collection<String> trustedClientIds)

Returns whether the audience in the payload contains only client IDs that are trusted as
specified in step 2 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `trustedClientIds` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` list of trusted client IDs |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### verifyExpirationTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

    public final boolean verifyExpirationTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

Returns whether the Payload#getExpirationTimeSeconds is valid relative to the current
time, allowing for a clock skew as specified in step 5 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `currentTimeMillis` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` current time in milliseconds (typically System#currentTimeMillis()) |
| `acceptableTimeSkewSeconds` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` seconds of acceptable clock skew |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### verifyIssuedAtTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

    public final boolean verifyIssuedAtTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

Returns whether the Payload#getIssuedAtTimeSeconds is valid relative to the current
time, allowing for a clock skew as specified in step 6 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `currentTimeMillis` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` current time in milliseconds (typically System#currentTimeMillis()) |
| `acceptableTimeSkewSeconds` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` seconds of acceptable clock skew |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### verifyIssuer(String expectedIssuer)

    public final boolean verifyIssuer(String expectedIssuer)

Returns whether the issuer in the payload matches the given expected issuer as specified in
step 1 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expectedIssuer` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` expected issuer |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### verifyIssuer(Collection\<String\> expectedIssuer)

    public final boolean verifyIssuer(Collection<String> expectedIssuer)

Returns whether the issuer in the payload matches the given expected issuer as specified in
step 1 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation). When an issuer is migrating to a new issuer string the expected issuer has
multiple aliases, so multiple are permitted here.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `expectedIssuer` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### verifyTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

    public final boolean verifyTime(long currentTimeMillis, long acceptableTimeSkewSeconds)

Returns whether the Payload#getExpirationTimeSeconds and Payload#getIssuedAtTimeSeconds are valid relative to the current time, allowing for a clock
skew as specified in steps 5 and 6 of [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `currentTimeMillis` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` current time in milliseconds (typically System#currentTimeMillis()) |
| `acceptableTimeSkewSeconds` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` seconds of acceptable clock skew |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |