# Class GoogleCredential (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.GoogleCredential)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Auth.OAuth2.GoogleCredential)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Auth.OAuth2.GoogleCredential)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Auth.OAuth2.GoogleCredential)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Auth.OAuth2.GoogleCredential)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Auth.OAuth2.GoogleCredential)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Auth.OAuth2.GoogleCredential)

    public class GoogleCredential : ICredential, IConfigurableHttpClientInitializer, ITokenAccessWithHeaders, ITokenAccess, IOidcTokenProvider, IBlobSigner, IHttpExecuteInterceptor

Credential for authorizing calls using OAuth 2.0.
It is a convenience wrapper that allows handling of different types of
credentials (like [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential), [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential)
or [UserCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential)) in a unified way.


See [GetApplicationDefaultAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefaultAsync_System_Threading_CancellationToken_) for the credential retrieval logic.

<br />

## Inheritance

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

## Implements

[ICredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ICredential), [IConfigurableHttpClientInitializer](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IConfigurableHttpClientInitializer), [ITokenAccessWithHeaders](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ITokenAccessWithHeaders), [ITokenAccess](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ITokenAccess), [IOidcTokenProvider](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.IOidcTokenProvider), [IBlobSigner](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.IBlobSigner), [IHttpExecuteInterceptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor)

## 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](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2)

## Assembly

Google.Apis.Auth.dll

## Properties

### IsCreateScopedRequired

    public virtual bool IsCreateScopedRequired { get; }

<br />


Returns `true` only if this credential supports explicit scopes to be set
via this library but no explicit scopes have been set.
A credential with explicit scopes set
may be created by calling [CreateScoped(IEnumerable\<string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_CreateScoped_System_Collections_Generic_IEnumerable_System_String__).


For accessing Google services, credentials need to be scoped. Credentials
have some default scoping, but this library supports explicit scopes to be set
for certain credentials.

1. [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential) is scoped by default but in some environments it may be scoped explicitly, for instance when running on GKE with Workload Identity or on AppEngine Flex. It's possible to create a [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential) with explicit scopes set by calling [CreateScoped(IEnumerable\<string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_CreateScoped_System_Collections_Generic_IEnumerable_System_String__). If running on an environment that does not accept explicit scoping, for instance GCE where scopes are set on the VM, explicit scopes will be ignored.
2. [UserCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential) is scoped by default, as scopes were obtained during the consent screen. It's not possible to change the default scopes of a [UserCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential).
3. [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential) is not scoped by default but when used without explicit scopes to access a Google service, the service's default scopes will be assumed. It's possible to create a [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential) with explicit scopes set by calling [CreateScoped(IEnumerable\<string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_CreateScoped_System_Collections_Generic_IEnumerable_System_String__)
4. [ImpersonatedCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential) is not scoped by default but when used without explicit scopes to access a Google service, the service's default scopes will be assumed. Note that the scopes of an [SourceCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential#Google_Apis_Auth_OAuth2_ImpersonatedCredential_SourceCredential) have no bearings on the [ImpersonatedCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential) scopes. It's possible to create an [ImpersonatedCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential) with explicit scopes set by calling [CreateScoped(IEnumerable\<string\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_CreateScoped_System_Collections_Generic_IEnumerable_System_String__)

<br />

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

### QuotaProject

    public string QuotaProject { get; }

The ID of the project associated to this credential for the purposes of
quota calculation and billing. May be null.

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

### UnderlyingCredential

    public ICredential UnderlyingCredential { get; }

Gets the underlying credential instance being wrapped.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ICredential` |   |

## Methods

### CreateScoped(IEnumerable\<string\>)

    public virtual GoogleCredential CreateScoped(IEnumerable<string> scopes)

If this library supports setting explicit scopes on this credential,
this method will creates a copy of the credential with the specified scopes.
Otherwise, it returns the same instance.
See [IsCreateScopedRequired](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_IsCreateScopedRequired) for more information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1https://learn.microsoft.com/dotnet/api/system.string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### CreateScoped(params string\[\])

    public GoogleCredential CreateScoped(params string[] scopes)

If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same
instance.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `scopes` | `https://learn.microsoft.com/dotnet/api/system.string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### CreateWithEnvironmentQuotaProject()

    public GoogleCredential CreateWithEnvironmentQuotaProject()

Creates a copy of this credential with the ambient quota project as set in
[QuotaProjectEnvironmentVariable](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleAuthConsts#Google_Apis_Auth_OAuth2_GoogleAuthConsts_QuotaProjectEnvironmentVariable).
If [QuotaProjectEnvironmentVariable](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleAuthConsts#Google_Apis_Auth_OAuth2_GoogleAuthConsts_QuotaProjectEnvironmentVariable) is not set, or if
it is set to the empty value, this method returns this instance.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

**Remarks** The ADC quota project value will be overwritten only if the environment variable is present
and set to a non-empty value.
If the environment variable is not present or if it is present but unset, the credential
returned will maintain whatever quota project value it already had, i.e. the credential's
quota project value will not be unset.

### CreateWithHttpClientFactory(IHttpClientFactory)

    public virtual GoogleCredential CreateWithHttpClientFactory(IHttpClientFactory factory)

Creates a copy of this credential with the specified HTTP client factory.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `factory` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpClientFactory` The HTTP client factory to be used by the new credential. May be null, in which case the default [HttpClientFactory](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.HttpClientFactory) will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### CreateWithQuotaProject(string)

    public virtual GoogleCredential CreateWithQuotaProject(string quotaProject)

Creates a copy of this credential with the specified quota project.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `quotaProject` | `https://learn.microsoft.com/dotnet/api/system.string` The quota project to use for the copy. May be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | A copy of this credential with [QuotaProject](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_QuotaProject) set to `quotaProject`. |

### CreateWithUniverseDomain(string)

    public GoogleCredential CreateWithUniverseDomain(string universeDomain)

If the credential supports custom universe domains this method will create a copy of the
credential with the specified universe domain set.
Otherwise, it throws [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `universeDomain` | `https://learn.microsoft.com/dotnet/api/system.string` The universe domain to use for the credential. May be null, in which case the default universe domain will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### CreateWithUser(string)

    public virtual GoogleCredential CreateWithUser(string user)

If the credential supports Domain Wide Delegation, this method creates a copy of the credential
with the specified user.
Otherwise, it throws [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception).
At the moment only [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential) supports Domain Wide Delegation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `user` | `https://learn.microsoft.com/dotnet/api/system.string` The user that the returned credential will be a delegate for. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | A copy of this credential with the user set to `user`. |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.invalidoperationexception` | When the credential type doesn't support Domain Wide Delegation. |

### FromAccessToken(string, IAccessMethod)

    public static GoogleCredential FromAccessToken(string accessToken, IAccessMethod accessMethod = null)

Create a [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential) directly from the provided access token.
The access token will not be automatically refreshed.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `accessToken` | `https://learn.microsoft.com/dotnet/api/system.string` The access token to use within this credential. |
| `accessMethod` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.IAccessMethod` Optional. The [IAccessMethod](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.IAccessMethod) to use within this credential. If `null`, will default to [BearerToken.AuthorizationHeaderAccessMethod](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.BearerToken.AuthorizationHeaderAccessMethod). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | A credential based on the provided access token. |

### FromComputeCredential(ComputeCredential)

    public static GoogleCredential FromComputeCredential(ComputeCredential computeCredential = null)

Create a [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential) from a [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential).
In general, do not use this method. Call [GetApplicationDefault()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefault) or
[GetApplicationDefaultAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefaultAsync_System_Threading_CancellationToken_), which will provide the most suitable
credentials for the current platform.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `computeCredential` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential` Optional. The compute credential to use in the returned [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential). If `null`, then a new [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential) will be instantiated, using the default [ComputeCredential.Initializer](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential.Initializer). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | A [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential) with an underlying [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential). |

### FromFile(string)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static GoogleCredential FromFile(string path)

Loads credential from the specified file containing JSON credential data.


The file can contain a Service Account key file in JSON format from the Google Developers
Console or a stored user credential using the format supported by the Cloud SDK.

<br />

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The path to the credential file. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | The loaded credentials. |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### FromFileAsync(string, CancellationToken)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static Task<GoogleCredential> FromFileAsync(string path, CancellationToken cancellationToken)

Loads credential from the specified file containing JSON credential data.


The file can contain a Service Account key file in JSON format from the Google Developers
Console or a stored user credential using the format supported by the Cloud SDK.

<br />

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `path` | `https://learn.microsoft.com/dotnet/api/system.string` The path to the credential file. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancellation token for the operation. |

| **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.GoogleCredential` | The loaded credentials. |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### FromJson(string)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static GoogleCredential FromJson(string json)

Loads credential from a string containing JSON credential data.


The string can contain a Service Account key file in JSON format from the Google Developers
Console or a stored user credential using the format supported by the Cloud SDK.

<br />

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `json` | `https://learn.microsoft.com/dotnet/api/system.string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### FromJsonParameters(JsonCredentialParameters)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static GoogleCredential FromJsonParameters(JsonCredentialParameters credentialParameters)

Loads a credential from JSON credential parameters. Fields are a union of credential fields
for all supported types. [JsonCredentialParameters](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.JsonCredentialParameters) for more detailed information
about supported types and corresponding fields.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credentialParameters` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.JsonCredentialParameters` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### FromProgrammaticExternalAccountCredential(ProgrammaticExternalAccountCredential)

    public static GoogleCredential FromProgrammaticExternalAccountCredential(ProgrammaticExternalAccountCredential credential)

Create a [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential) from a [ProgrammaticExternalAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ProgrammaticExternalAccountCredential).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credential` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ProgrammaticExternalAccountCredential` The credential to use in the returned [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential). Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### FromServiceAccountCredential(ServiceAccountCredential)

    public static GoogleCredential FromServiceAccountCredential(ServiceAccountCredential credential)

Creates a `GoogleCredential` wrapping a [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `credential` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

### FromStream(Stream)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static GoogleCredential FromStream(Stream stream)

Loads credential from stream containing JSON credential data.


The stream can contain a Service Account key file in JSON format from the Google Developers
Console or a stored user credential using the format supported by the Cloud SDK.

<br />

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `stream` | `https://learn.microsoft.com/dotnet/api/system.io.stream` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### FromStreamAsync(Stream, CancellationToken)

    [Obsolete("This method is being deprecated because of a potential security risk. Use the methods in the CredentialFactory class instead. A GoogleCredential object can then be created by calling the .ToGoogleCredential() method on the returned specific credential. ")]
    public static Task<GoogleCredential> FromStreamAsync(Stream stream, CancellationToken cancellationToken)

Loads credential from stream containing JSON credential data.


The stream can contain a Service Account key file in JSON format from the Google Developers
Console or a stored user credential using the format supported by the Cloud SDK.

<br />

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `stream` | `https://learn.microsoft.com/dotnet/api/system.io.stream` |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **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.GoogleCredential` |   |

**Remarks** Important: If you accept a credential configuration (credential JSON/File/Stream) from an external source
for authentication to Google Cloud, you must validate it before providing it to any Google API or library.
Providing an unvalidated credential configuration to Google APIs can compromise the security of your
systems and data. For more information, refer to
[Validate credential configurations from external sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).

### GetApplicationDefault()

    public static GoogleCredential GetApplicationDefault()

Synchronously returns the Application Default Credentials which are ambient credentials that identify and authorize
the whole application. See [GetApplicationDefaultAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefaultAsync_System_Threading_CancellationToken_) for details on application default credentials.

This method will block until the credentials are available (or an exception is thrown).
It is highly preferable to call [GetApplicationDefaultAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefaultAsync_System_Threading_CancellationToken_) where possible.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` | The application default credentials. |

### GetApplicationDefaultAsync()

    public static Task<GoogleCredential> GetApplicationDefaultAsync()

Returns the Application Default Credentials which are ambient credentials that identify and authorize
the whole application. See [GetApplicationDefaultAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetApplicationDefaultAsync_System_Threading_CancellationToken_) for more details.

| **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.GoogleCredential` | A task which completes with the application default credentials. |

### GetApplicationDefaultAsync(CancellationToken)

    public static Task<GoogleCredential> GetApplicationDefaultAsync(CancellationToken cancellationToken)

<br />

Returns the Application Default Credentials which are ambient credentials that identify and authorize
the whole application.

The ambient credentials are determined as following order:

1. The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified, it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a service account using the [Google Developers Console](https://console.developers.google.com) in the section APIs \& Auth, in the sub-section Credentials. Create a service account or choose an existing one and select Generate new JSON key. Set the environment variable to the path of the JSON file downloaded.
2. If you have installed the Google Cloud SDK on your machine and have run the command [GCloud Auth Login](https://cloud.google.com/sdk/gcloud/reference/auth/login), your identity can be used as a proxy to test code calling APIs from that machine.
3. If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance will be used.
4. If all previous steps have failed, `InvalidOperationException` is thrown.

<br />

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancellation token for the operation. |

| **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.GoogleCredential` | A task which completes with the application default credentials. |

**Remarks** If the cancellation token is cancelled while the underlying operation is loading Application Default Credentials,
the underlying operation will still be used for any further requests. No actual work is cancelled via this cancellation
token; it just allows the returned task to transition to a cancelled state.

### GetOidcTokenAsync(OidcTokenOptions, CancellationToken)

    public Task<OidcToken> GetOidcTokenAsync(OidcTokenOptions options, CancellationToken cancellationToken = default)

Returns an OIDC token for the given options.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.OidcTokenOptions` The options to create the token from. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The cancellation token that may be used to cancel the request. |

| **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.OidcToken` | The OIDC token. |

### GetUniverseDomain()

    public string GetUniverseDomain()

Returns the universe domain this credential belongs to.

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

**Remarks** Because [GetUniverseDomainAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetUniverseDomainAsync_System_Threading_CancellationToken_) is truly async only once, at most, in the lifetime
of an application, this method exists for convenience.
It can always be safely used for all credential types except for [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential).
For [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential), the universe domain is obtained from the
metadata server, which requires an HTTP call. This value is obtained only once,
the first time it is requested for any instance of [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential).
That first time, this method may block while waiting for the HTTP call to complete.
After that, this method will always be safe to use.
Will never return null.

### GetUniverseDomainAsync(CancellationToken)

    public Task<string> GetUniverseDomainAsync(CancellationToken cancellationToken)

Returns the universe domain this credential belongs to.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.string` |   |

**Remarks** For most credential types, this operation is synchronous and will always
return a completed task.
For [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential), the universe domain is obtained from the
metadata server, which requires an HTTP call. This value is obtained only once,
the first time it is requested for any instance of [ComputeCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ComputeCredential).
Once the universe has been fetched this method will always return a completed task.
The task's result will never be null.
Note that each `cancellationToken` will only apply to the call
that provided it and not to subsequent calls. For instance, even if the first call
to [GetUniverseDomainAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_GetUniverseDomainAsync_System_Threading_CancellationToken_) is cancelled, subsequent
calls may still succeed.

### Impersonate(Initializer)

    public GoogleCredential Impersonate(ImpersonatedCredential.Initializer initializer)

Allows this credential to impersonate the [TargetPrincipal](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential.Initializer#Google_Apis_Auth_OAuth2_ImpersonatedCredential_Initializer_TargetPrincipal).
Only [ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential) and [UserCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential) support impersonation,
so this method will throw [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) if this credential's
[UnderlyingCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential#Google_Apis_Auth_OAuth2_GoogleCredential_UnderlyingCredential) is not of one of those supported types.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredentialhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ImpersonatedCredential.Initializer` Initializer containing the configuration for the impersonated credential. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential` |   |

**Remarks** For impersonation, a credential needs to be scoped to <https://www.googleapis.com/auth/iam>. When using a
[ServiceAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceAccountCredential) as the source credential, this is not a problem, since the credential
can be scoped on demand. When using a [UserCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential) the credential needs to have been obtained
with the required scope, else, when attempting and impersonated request, you'll receive an authorization error.

### SignBlobAsync(byte\[\], CancellationToken)

    public Task<string> SignBlobAsync(byte[] blob, CancellationToken cancellationToken = default)

Returns the base64 encoded signature of the given blob.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `blob` | `System.Byte` The blob to sign. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` The cancellation token. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.string` | The base64 encoded signature. |

## 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_)