# Class IdTokenVerifier (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.IdTokenVerifier)
- [1.38.2](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.38.2/com.google.api.client.auth.openidconnect.IdTokenVerifier)
- [1.37.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.37.0/com.google.api.client.auth.openidconnect.IdTokenVerifier)
- [1.36.0](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.36.0/com.google.api.client.auth.openidconnect.IdTokenVerifier)
- [1.34.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.34.1/com.google.api.client.auth.openidconnect.IdTokenVerifier)
- [1.33.3](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.33.3/com.google.api.client.auth.openidconnect.IdTokenVerifier)
- [1.32.1](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/1.32.1/com.google.api.client.auth.openidconnect.IdTokenVerifier)

    public class IdTokenVerifier

Thread-safe ID token verifier based on [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation).

Call [#verify(IdToken)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_verify_com_google_api_client_auth_openidconnect_IdToken_) to verify an ID token. This is a light-weight object, so you may
use a new instance for each configuration of expected issuer and trusted client IDs. Sample
usage:

IdTokenVerifier verifier = new IdTokenVerifier.Builder()
.setIssuer("issuer.example.com")
.setAudience(Arrays.asList("myClientId"))
.build();
...
if (!verifier.verify(idToken)) {...}

The verifier validates token signature per current OpenID Connect Spec:
<https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation> By default, method gets a
certificate from well-known location A request to certificate location is performed using com.google.api.client.http.javanet.NetHttpTransport Either or both certificate location and
transport implementation can be overridden via Builder

IdTokenVerifier verifier = new IdTokenVerifier.Builder()
.setIssuer("issuer.example.com")
.setAudience(Arrays.asList("myClientId"))
.setHttpTransportFactory(customHttpTransportFactory)
.build();
...
if (!verifier.verify(idToken)) {...}

not recommended: this check can be disabled with OAUTH_CLIENT_SKIP_SIGNATURE environment variable
set to true. Use [#verifyPayload(IdToken)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_verifyPayload_com_google_api_client_auth_openidconnect_IdToken_) instead.

Note that [#verify(IdToken)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_verify_com_google_api_client_auth_openidconnect_IdToken_) only implements a subset of the verification steps, mostly
just the MUST steps. Please read [ID Token
Validation](http://openid.net/specs/openid-connect-basic-1_0-27.html#id.token.validation) for the full list of verification steps.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> IdTokenVerifier

## Inherited Members

[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.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [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 Fields

### DEFAULT_TIME_SKEW_SECONDS

    public static final long DEFAULT_TIME_SKEW_SECONDS

Default value for seconds of time skew to accept when verifying time (5 minutes).

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

## Constructors

### IdTokenVerifier()

    public IdTokenVerifier()

### IdTokenVerifier(IdTokenVerifier.Builder builder)

    protected IdTokenVerifier(IdTokenVerifier.Builder builder)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `builder` | `https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier.Builder` builder |

## Methods

### getAcceptableTimeSkewSeconds()

    public final long getAcceptableTimeSkewSeconds()

Returns the seconds of time skew to accept when verifying time.

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

### getAudience()

    public final Collection<String> getAudience()

Returns the unmodifiable list of trusted audience client IDs or `null` to suppress the
audience check.

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

### getClock()

    public final Clock getClock()

Returns the clock.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.api.client.util.Clock` |   |

### getIssuer()

    public final String getIssuer()

Returns the first of equivalent expected issuers or `null` if issuer check suppressed.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getIssuers()

    public final Collection<String> getIssuers()

Returns the equivalent expected issuers or `null` if issuer check suppressed.

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

### verify(IdToken idToken)

    public boolean verify(IdToken idToken)

Verifies that the given ID token is valid using the cached public keys.

It verifies:

- The issuer is one of [#getIssuers()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getIssuers__) by calling [IdToken#verifyIssuer(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_verifyIssuer_java_lang_String_).
- The audience is one of [#getAudience()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAudience__) by calling [IdToken#verifyAudience(Collection)](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_verifyAudience_java_util_Collection_java_lang_String__).
- The current time against the issued at and expiration time, using the [#getClock()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getClock__) and allowing for a time skew specified in [#getAcceptableTimeSkewSeconds()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAcceptableTimeSkewSeconds__) , by calling [IdToken#verifyTime(long, long)](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_verifyTime_long_long_).
- This method verifies token signature per current OpenID Connect Spec: <https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation>. By default, method gets a certificate from well-known location. A request to certificate location is performed using com.google.api.client.http.javanet.NetHttpTransport Both certificate location and transport implementation can be overridden via Builder not recommended: this check can be disabled with OAUTH_CLIENT_SKIP_SIGNATURE environment variable set to true. Use [#verifyPayload(IdToken)](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_verifyPayload_com_google_api_client_auth_openidconnect_IdToken_) instead.

Deprecated. This method returns false if network requests to get certificates fail. Use IdTokenVerifier.verfyOrThrow(IdToken) instead to differentiate between potentially retryable
network errors and false verification results.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if verified successfully or `false` if failed |

### verifyOrThrow(IdToken idToken)

    public boolean verifyOrThrow(IdToken idToken)

Verifies that the given ID token is valid using the cached public keys.

It verifies:

- The issuer is one of [#getIssuers()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getIssuers__) by calling [IdToken#verifyIssuer(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_verifyIssuer_java_lang_String_).
- The audience is one of [#getAudience()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAudience__) by calling [IdToken#verifyAudience(Collection)](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_verifyAudience_java_util_Collection_java_lang_String__).
- The current time against the issued at and expiration time, using the [#getClock()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getClock__) and allowing for a time skew specified in [#getAcceptableTimeSkewSeconds()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAcceptableTimeSkewSeconds__) , by calling [IdToken#verifyTime(long, long)](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_verifyTime_long_long_).
- This method verifies token signature per current OpenID Connect Spec: <https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation>. By default, method gets a certificate from well-known location. A request to certificate location is performed using com.google.api.client.http.javanet.NetHttpTransport Both certificate location and transport implementation can be overridden via Builder not recommended: this check can be disabled with OAUTH_CLIENT_SKIP_SIGNATURE environment variable set to true.

Overriding is allowed, but it must call the super implementation.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if verified successfully or `false` if payload validation failed |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` | if verification fails to run. For example, if it fails to get public keys for signature verification. |

### verifyPayload(IdToken idToken)

    protected boolean verifyPayload(IdToken idToken)

Verifies the payload of the given ID token

It verifies:

- The issuer is one of [#getIssuers()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getIssuers__) by calling [IdToken#verifyIssuer(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_verifyIssuer_java_lang_String_).
- The audience is one of [#getAudience()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAudience__) by calling [IdToken#verifyAudience(Collection)](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_verifyAudience_java_util_Collection_java_lang_String__).
- The current time against the issued at and expiration time, using the [#getClock()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getClock__) and allowing for a time skew specified in [#getAcceptableTimeSkewSeconds()](https://docs.cloud.google.com/java/docs/reference/google-oauth-client/latest/com.google.api.client.auth.openidconnect.IdTokenVerifier#com_google_api_client_auth_openidconnect_IdTokenVerifier_getAcceptableTimeSkewSeconds__) , by calling [IdToken#verifyTime(long, long)](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_verifyTime_long_long_).

Overriding is allowed, but it must call the super implementation.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if verified successfully or `false` if failed |