1.73.0 (latest) 1.69.0 1.68.0 1.60.0 1.59.0 1.55.0 1.50.0

    public class GoogleWebAuthorizationBroker

A helper utility to manage the authorization code flow.

## Inheritance

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

## 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.md.txt)

## Assembly

Google.Apis.Auth.dll

## Remarks

This class is only suitable for client-side use, as it starts a local browser that requires
user interaction.
Do not use this class when executing on a web server, or any cases where the authenticating
end-user is not able to do directly interact with a launched browser.

## Fields

### Folder

    public static string Folder

The folder which is used by the [FileDataStore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Store.FileDataStore.md.txt).

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

**Remarks** The reason that this is not 'private const' is that a user can change it and store the credentials in a
different location.

## Methods

### AuthorizeAsync(ClientSecrets, IEnumerable\<string\>, string, CancellationToken, IDataStore, ICodeReceiver)

    public static Task<UserCredential> AuthorizeAsync(ClientSecrets clientSecrets, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken, IDataStore dataStore = null, ICodeReceiver codeReceiver = null)

Asynchronously authorizes the specified user.
Requires user interaction; see [GoogleWebAuthorizationBroker](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.md.txt) remarks for more details.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `clientSecrets` | `ClientSecrets` The client secrets. |
| `scopes` | `IEnumerablestring` The scopes which indicate the Google API access your application is requesting. |
| `user` | `string` The user to authorize. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel an operation. |
| `dataStore` | `IDataStore` The data store, if not specified a file data store will be used. |
| `codeReceiver` | `ICodeReceiver` The code receiver, if not specified a local server code receiver will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskUserCredential` | User credential. |

**Remarks** In case no data store is specified, [FileDataStore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Store.FileDataStore.md.txt) will be used by
default.

### AuthorizeAsync(Initializer, IEnumerable\<string\>, string, bool, CancellationToken, IDataStore, ICodeReceiver)

    public static Task<UserCredential> AuthorizeAsync(GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<string> scopes, string user, bool usePkce, CancellationToken taskCancellationToken, IDataStore dataStore = null, ICodeReceiver codeReceiver = null)

The core logic for asynchronously authorizing the specified user.
Requires user interaction; see [GoogleWebAuthorizationBroker](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.md.txt) remarks for more details.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `GoogleAuthorizationCodeFlowInitializer` The authorization code initializer. |
| `scopes` | `IEnumerablestring` The scopes which indicate the Google API access your application is requesting. |
| `user` | `string` The user to authorize. |
| `usePkce` | `bool` If true, PKCE will be used by the authorization flow. Note that using PKCE is recommended for security reasons. See <https://developers.google.com/identity/protocols/oauth2/native-app> for more information. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel an operation. |
| `dataStore` | `IDataStore` The data store, if not specified a file data store will be used. |
| `codeReceiver` | `ICodeReceiver` The code receiver, if not specified a local server code receiver will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskUserCredential` | User credential. |

### AuthorizeAsync(Initializer, IEnumerable\<string\>, string, CancellationToken, IDataStore, ICodeReceiver)

    public static Task<UserCredential> AuthorizeAsync(GoogleAuthorizationCodeFlow.Initializer initializer, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken, IDataStore dataStore = null, ICodeReceiver codeReceiver = null)

The core logic for asynchronously authorizing the specified user.
Requires user interaction; see [GoogleWebAuthorizationBroker](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.md.txt) remarks for more details.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `initializer` | `GoogleAuthorizationCodeFlowInitializer` The authorization code initializer. |
| `scopes` | `IEnumerablestring` The scopes which indicate the Google API access your application is requesting. |
| `user` | `string` The user to authorize. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel an operation. |
| `dataStore` | `IDataStore` The data store, if not specified a file data store will be used. |
| `codeReceiver` | `ICodeReceiver` The code receiver, if not specified a local server code receiver will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskUserCredential` | User credential. |

### AuthorizeAsync(Stream, IEnumerable\<string\>, string, CancellationToken, IDataStore, ICodeReceiver)

    public static Task<UserCredential> AuthorizeAsync(Stream clientSecretsStream, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken, IDataStore dataStore = null, ICodeReceiver codeReceiver = null)

Asynchronously authorizes the specified user.
Requires user interaction; see [GoogleWebAuthorizationBroker](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.md.txt) remarks for more details.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `clientSecretsStream` | `Stream` The client secrets stream. The authorization code flow constructor is responsible for disposing the stream. |
| `scopes` | `IEnumerablestring` The scopes which indicate the Google API access your application is requesting. |
| `user` | `string` The user to authorize. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel an operation. |
| `dataStore` | `IDataStore` The data store, if not specified a file data store will be used. |
| `codeReceiver` | `ICodeReceiver` The code receiver, if not specified a local server code receiver will be used. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `TaskUserCredential` | User credential. |

**Remarks** In case no data store is specified, [FileDataStore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Store.FileDataStore.md.txt) will be used by
default.

### ReauthorizeAsync(UserCredential, CancellationToken, ICodeReceiver)

    public static Task ReauthorizeAsync(UserCredential userCredential, CancellationToken taskCancellationToken, ICodeReceiver codeReceiver = null)

Asynchronously reauthorizes the user. This method should be called if the users want to authorize after
they revoked the token.
Requires user interaction; see [GoogleWebAuthorizationBroker](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker.md.txt) remarks for more details.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `userCredential` | `UserCredential` The current user credential. Its [Token](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Auth.OAuth2.UserCredential.md.txt#Google_Apis_Auth_OAuth2_UserCredential_Token) will be updated. |
| `taskCancellationToken` | `CancellationToken` Cancellation token to cancel an operation. |
| `codeReceiver` | `ICodeReceiver` The code receiver, if not specified a local server code receiver will be used. |

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

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