Class AuthorizationCodeFlow (1.60.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.

Inheritance

object > AuthorizationCodeFlow

Namespace

GoogleApisAuthOAuth2Flows

Assembly

Google.Apis.Auth.dll

Constructors

AuthorizationCodeFlow(Initializer)

public AuthorizationCodeFlow(AuthorizationCodeFlow.Initializer initializer)

Constructs a new flow using the initializer's properties.

Parameter
NameDescription
initializerAuthorizationCodeFlowInitializer

Properties

AccessMethod

public IAccessMethod AccessMethod { get; }

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

Property Value
TypeDescription
IAccessMethod

AuthorizationServerUrl

public string AuthorizationServerUrl { get; }

Gets the authorization code server URL.

Property Value
TypeDescription
string

ClientSecrets

public ClientSecrets ClientSecrets { get; }

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

Property Value
TypeDescription
ClientSecrets

Clock

public IClock Clock { get; }

Gets the clock.

Property Value
TypeDescription
IClock

DataStore

public IDataStore DataStore { get; }

Gets the data store used to store the credentials.

Property Value
TypeDescription
IDataStore

HttpClient

public ConfigurableHttpClient HttpClient { get; }

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

Property Value
TypeDescription
ConfigurableHttpClient

Scopes

public IEnumerable<string> Scopes { get; }

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

Property Value
TypeDescription
IEnumerablestring

TokenServerUrl

public string TokenServerUrl { get; }

Gets the token server URL.

Property Value
TypeDescription
string

Methods

CreateAuthorizationCodeRequest(string)

public virtual AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)

Creates an authorization code request with the specified redirect URI.

Parameter
NameDescription
redirectUristring
Returns
TypeDescription
AuthorizationCodeRequestUrl

DeleteTokenAsync(string, CancellationToken)

public Task DeleteTokenAsync(string userId, CancellationToken taskCancellationToken)

Asynchronously deletes the user's token using the flow's IDataStore.

Parameters
NameDescription
userIdstring

User identifier.

taskCancellationTokenCancellationToken

Cancellation token to cancel operation.

Returns
TypeDescription
Task

Dispose()

public void Dispose()

ExchangeCodeForTokenAsync(string, string, string, CancellationToken)

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

Asynchronously exchanges code with a token.

Parameters
NameDescription
userIdstring

User identifier.

codestring

Authorization code received from the authorization server.

redirectUristring

Redirect URI which is used in the token request.

taskCancellationTokenCancellationToken

Cancellation token to cancel operation.

Returns
TypeDescription
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
NameDescription
userIdstring

User identifier.

requestTokenRequest

Token request.

taskCancellationTokenCancellationToken

Cancellation token to cancel operation.

Returns
TypeDescription
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.

Parameters
NameDescription
userIdstring

User identifier

taskCancellationTokenCancellationToken

Cancellation token to cancel operation

Returns
TypeDescription
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
NameDescription
userIdstring

User identifier.

refreshTokenstring

Refresh token which is used to get a new access token.

taskCancellationTokenCancellationToken

Cancellation token to cancel operation.

Returns
TypeDescription
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
NameDescription
userIdstring

User identifier.

tokenstring

Access token to be revoked.

taskCancellationTokenCancellationToken

Cancellation token to cancel operation.

Returns
TypeDescription
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
TypeDescription
bool

Extension Method