1.73.0 (latest) 1.69.0 1.68.0 1.60.0 1.59.0 1.55.0 1.50.0

    public sealed class ProgrammaticExternalAccountCredential : ExternalAccountCredential, IHttpUnsuccessfulResponseHandler, ICredential, IConfigurableHttpClientInitializer, ITokenAccessWithHeaders, ITokenAccess, IHttpExecuteInterceptor

External account credentials that rely on user-provided code to obtain the third-party token.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> [ServiceCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt) \> [ExternalAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt) \> ProgrammaticExternalAccountCredential

## Implements

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

## Inherited Members

[ExternalAccountCredential.Audience](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_Audience) [ExternalAccountCredential.SubjectTokenType](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_SubjectTokenType) [ExternalAccountCredential.ServiceAccountImpersonationUrl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_ServiceAccountImpersonationUrl) [ExternalAccountCredential.WorkforcePoolUserProject](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_WorkforcePoolUserProject) [ExternalAccountCredential.ClientId](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_ClientId) [ExternalAccountCredential.ClientSecret](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_ClientSecret) [ExternalAccountCredential.UniverseDomain](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_UniverseDomain) [ExternalAccountCredential.RequestAccessTokenAsync(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_RequestAccessTokenAsync_System_Threading_CancellationToken_) [ServiceCredential.TokenServerUrl](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_TokenServerUrl) [ServiceCredential.Clock](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_Clock) [ServiceCredential.AccessMethod](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_AccessMethod) [ServiceCredential.HttpClient](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_HttpClient) [ServiceCredential.Scopes](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_Scopes) [ServiceCredential.Token](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_Token) [ServiceCredential.QuotaProject](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_QuotaProject) [ServiceCredential.Initialize(ConfigurableHttpClient)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_Initialize_Google_Apis_Http_ConfigurableHttpClient_) [ServiceCredential.InterceptAsync(HttpRequestMessage, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_InterceptAsync_System_Net_Http_HttpRequestMessage_System_Threading_CancellationToken_) [ServiceCredential.HandleResponseAsync(HandleUnsuccessfulResponseArgs)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_HandleResponseAsync_Google_Apis_Http_HandleUnsuccessfulResponseArgs_) [ServiceCredential.GetAccessTokenForRequestAsync(string, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_GetAccessTokenForRequestAsync_System_String_System_Threading_CancellationToken_) [ServiceCredential.GetAccessTokenWithHeadersForRequestAsync(string, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ServiceCredential.md.txt#Google_Apis_Auth_OAuth2_ServiceCredential_GetAccessTokenWithHeadersForRequestAsync_System_String_System_Threading_CancellationToken_) [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.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.md.txt)

## Assembly

Google.Apis.Auth.dll

## Remarks

This credential type does not validate the credential configuration. A security
risk occurs when a credential configuration configured with malicious urls
is used.
You should validate credential configurations provided by untrusted sources.
See [Security requirements when using credential configurations from an external source](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials) for more details.

## Constructors

### ProgrammaticExternalAccountCredential(Initializer)

    public ProgrammaticExternalAccountCredential(ProgrammaticExternalAccountCredential.Initializer initializer)

Builds a [ProgrammaticExternalAccountCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ProgrammaticExternalAccountCredential.md.txt) instace from the given initializer.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `ProgrammaticExternalAccountCredentialInitializer` |

## Properties

### SubjectTokenProvider

    public ProgrammaticExternalAccountCredential.ISubjectTokenProvider SubjectTokenProvider { get; }

The provider of the third-party token that's included on the STS token exchange request.
Will not be null.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `ProgrammaticExternalAccountCredentialISubjectTokenProvider` |   |

## Methods

### GetSubjectTokenAsyncImpl(CancellationToken)

    protected override Task<string> GetSubjectTokenAsyncImpl(CancellationToken taskCancellationToken)

Gets the subject token to be exchanged for the access token.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `taskCancellationToken` | `CancellationToken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Taskstring` |   |

**Overrides** [ExternalAccountCredential.GetSubjectTokenAsyncImpl(CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.ExternalAccountCredential.md.txt#Google_Apis_Auth_OAuth2_ExternalAccountCredential_GetSubjectTokenAsyncImpl_System_Threading_CancellationToken_)

### ToGoogleCredential()

    public GoogleCredential ToGoogleCredential()

Creates a [GoogleCredential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleCredential.md.txt) from this credential.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `GoogleCredential` |   |

## Extension Method

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