1.73.0 (latest) 1.69.0 1.68.0 1.60.0 1.59.0 1.55.0 1.50.0

    public class AuthorizationCodeFlow : IAuthorizationCodeFlow, IDisposable

Thread-safe OAuth 2.0 authorization code flow that manages and persists end-user credentials.


This is designed to simplify the flow in which an end-user authorizes the application to access their protected
data, and then the application has access to their data based on an access token and a refresh token to refresh
that access token when it expires.

<br />

## Inheritance

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

## Implements

[IAuthorizationCodeFlow](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.md.txt), [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

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

## Derived Types

[GoogleAuthorizationCodeFlow](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow.md.txt)

## Namespace

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

## Assembly

Google.Apis.Auth.dll

## Constructors

### AuthorizationCodeFlow(Initializer)

    public AuthorizationCodeFlow(AuthorizationCodeFlow.Initializer initializer)

Constructs a new flow using the initializer's properties.

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

## Properties

### AccessMethod

    public IAccessMethod AccessMethod { get; }

Gets the method for presenting the access token to the resource server.

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

### AuthorizationServerUrl

    public string AuthorizationServerUrl { get; }

Gets the authorization code server URL.

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

### ClientSecrets

    public ClientSecrets ClientSecrets { get; }

Gets the client secrets which includes the client identifier and its secret.

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

### Clock

    public IClock Clock { get; }

Gets the clock.

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

### DataStore

    public IDataStore DataStore { get; }

Gets the data store used to store the credentials.

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

### HttpClient

    public ConfigurableHttpClient HttpClient { get; }

Gets the HTTP client used to make authentication requests to the server.

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

### Scopes

    public IEnumerable<string> Scopes { get; }

Gets the scopes which indicate the API access your application is requesting.

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

### TokenServerUrl

    public string TokenServerUrl { get; }

Gets the token server URL.

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

## Methods

### CreateAuthorizationCodeRequest(string)

    public virtual AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)

Creates an authorization code request with the specified redirect URI.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `redirectUri` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `AuthorizationCodeRequestUrl` |   |

### CreateAuthorizationCodeTokenRequest(string, string, string)

    protected AuthorizationCodeTokenRequest CreateAuthorizationCodeTokenRequest(string userId, string code, string redirectUri)

Creates a [AuthorizationCodeTokenRequest](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.Requests.AuthorizationCodeTokenRequest.md.txt) for the given parameters.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` |
| `code` | `string` |
| `redirectUri` | `string` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `AuthorizationCodeTokenRequest` |   |

### DeleteTokenAsync(string, CancellationToken)

    public Task DeleteTokenAsync(string userId, CancellationToken taskCancellationToken)

Asynchronously deletes the user's token using the flow's
[IDataStore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Store.IDataStore.md.txt).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Task` |   |

### Dispose()

    public void Dispose()

### ExchangeCodeForTokenAsync(string, AuthorizationCodeTokenRequest, CancellationToken)

    protected Task<TokenResponse> ExchangeCodeForTokenAsync(string userId, AuthorizationCodeTokenRequest authorizationCodeTokenReq, CancellationToken taskCancellationToken)

Executes `authorizationCodeTokenReq` and stores and returns the received token.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` |
| `authorizationCodeTokenReq` | `AuthorizationCodeTokenRequest` |
| `taskCancellationToken` | `CancellationToken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskTokenResponse` |   |

### ExchangeCodeForTokenAsync(string, string, string, CancellationToken)

    public Task<TokenResponse> ExchangeCodeForTokenAsync(string userId, string code, string redirectUri, CancellationToken taskCancellationToken)

Asynchronously exchanges an authorization code for an access token.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier. |
| `code` | `string` Authorization code received from the authorization server. |
| `redirectUri` | `string` Redirect URI which is used in the token request. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskTokenResponse` | Token response which contains the access token. |

### FetchTokenAsync(string, TokenRequest, CancellationToken)

    public Task<TokenResponse> FetchTokenAsync(string userId, TokenRequest request, CancellationToken taskCancellationToken)

Retrieve a new token from the server using the specified request.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier. |
| `request` | `TokenRequest` Token request. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskTokenResponse` | Token response with the new access token. |

### LoadTokenAsync(string, CancellationToken)

    public Task<TokenResponse> LoadTokenAsync(string userId, CancellationToken taskCancellationToken)

Asynchronously loads the user's token using the flow's
[IDataStore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Store.IDataStore.md.txt).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskTokenResponse` | Token response |

### RefreshTokenAsync(string, string, CancellationToken)

    public Task<TokenResponse> RefreshTokenAsync(string userId, string refreshToken, CancellationToken taskCancellationToken)

Asynchronously refreshes an access token using a refresh token.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier. |
| `refreshToken` | `string` Refresh token which is used to get a new access token. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskTokenResponse` | Token response which contains the access token and the input refresh token. |

### RevokeTokenAsync(string, string, CancellationToken)

    public virtual Task RevokeTokenAsync(string userId, string token, CancellationToken taskCancellationToken)

Asynchronously revokes the specified token. This method disconnects the user's account from the OAuth 2.0
application. It should be called upon removing the user account from the site.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userId` | `string` User identifier. |
| `token` | `string` Access token to be revoked. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Task` | `true` if the token was revoked successfully. |

**Remarks** If revoking the token succeeds, the user's credential is removed from the data store and the user MUST
authorize the application again before the application can access the user's private resources.

### ShouldForceTokenRetrieval()

    public virtual bool ShouldForceTokenRetrieval()

Indicates if a new token needs to be retrieved and stored regardless of normal circumstances.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `bool` |   |

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