# Class TokenResponse (1.73.0)

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

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Auth.OAuth2.Responses.TokenResponse)

    public class TokenResponse

OAuth 2.0 model for a successful access token response as specified in
<http://tools.ietf.org/html/rfc6749#section-5.1>.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> TokenResponse

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Auth.OAuth2.Responses](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses)

## Assembly

Google.Apis.Auth.dll

## Properties

### AccessToken

    [JsonProperty("access_token")]
    public string AccessToken { get; set; }

Gets or sets the access token issued by the authorization server.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ExpiresInSeconds

    [JsonProperty("expires_in")]
    public long? ExpiresInSeconds { get; set; }

Gets or sets the lifetime in seconds of the access token.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int64` |   |

### IdToken

    [JsonProperty("id_token")]
    public string IdToken { get; set; }

Gets or sets the id_token, which is a JSON Web Token (JWT) as specified in <http://tools.ietf.org/html/draft-ietf-oauth-json-web-token>

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### IsStale

    [JsonIgnore]
    public bool IsStale { get; }

Returns true if the token represented by this token response should be refreshed.
Note that this may be true for valid tokens, in which case a pre-emptive refresh is adviced
even if the current token may be used while it continues to be valid.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

**Remarks** See Google.Apis.Auth.OAuth2.Responses.TokenResponse.MayBeUsed(Google.Apis.Util.IClock) for information on when a token is considered valid.
A valid token is considered stale if it's close to expiring, but not so much as to be unusable.

### Issued

    [Obsolete("Use IssuedUtc instead")]
    [JsonProperty(Order = 1)]
    public DateTime Issued { get; set; }

The date and time that this token was issued, expressed in the system time zone.
This property only exists for backward compatibility; it can cause inappropriate behavior around
time zone transitions (e.g. daylight saving transitions).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.datetime` |   |

### IssuedUtc

    [JsonProperty(Order = 2)]
    public DateTime IssuedUtc { get; set; }

The date and time that this token was issued, expressed in UTC.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.datetime` |   |

**Remarks** This should be set by the CLIENT after the token was received from the server.

### RefreshToken

    [JsonProperty("refresh_token")]
    public string RefreshToken { get; set; }

Gets or sets the refresh token which can be used to obtain a new access token.
For example, the value "3600" denotes that the access token will expire in one hour from the time the
response was generated.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Scope

    [JsonProperty("scope")]
    public string Scope { get; set; }

Gets or sets the scope of the access token as specified in <http://tools.ietf.org/html/rfc6749#section-3.3>.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### TokenType

    [JsonProperty("token_type")]
    public string TokenType { get; set; }

Gets or sets the token type as specified in <http://tools.ietf.org/html/rfc6749#section-7.1>.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

## Methods

### FromHttpResponseAsync(HttpResponseMessage, IClock, ILogger)

    public static Task<TokenResponse> FromHttpResponseAsync(HttpResponseMessage response, IClock clock, ILogger logger)

Asynchronously parses a [TokenResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse) instance from the specified [HttpResponseMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `response` | `https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage` The http response from which to parse the token. |
| `clock` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.IClock` The clock used to set the [Issued](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse#Google_Apis_Auth_OAuth2_Responses_TokenResponse_Issued) value of the token. |
| `logger` | `Google.Apis.Logging.ILogger` The logger used to output messages incase of error. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse` | A task containing the [TokenResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse) parsed form the response message. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponseException` | The response was not successful or there is an error parsing the response into valid [TokenResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse) instance. |

### IsExpired(IClock)

    [Obsolete("Please use the TokenResponse.IsStale property instead.")]
    public bool IsExpired(IClock clock)

Returns true if the token is expired or it's going to expire soon.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clock` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.IClock` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

**Remarks** If a token response doens't have at least one of [AccessToken](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse#Google_Apis_Auth_OAuth2_Responses_TokenResponse_AccessToken)
or [IdToken](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse#Google_Apis_Auth_OAuth2_Responses_TokenResponse_IdToken) set then it's considered expired.
If [ExpiresInSeconds](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Responses.TokenResponse#Google_Apis_Auth_OAuth2_Responses_TokenResponse_ExpiresInSeconds) is null, the token is also considered expired.

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)