Google API Client Library for .NET  1.10.0
Public Member Functions | Static Protected Attributes | Properties | List of all members
Google.Apis.Auth.OAuth2.UserCredential Class Reference

OAuth 2.0 credential for accessing protected resources using an access token, as well as optionally refreshing the access token when it expires using a refresh token. More...

Inheritance diagram for Google.Apis.Auth.OAuth2.UserCredential:
Google.Apis.Auth.OAuth2.ICredential Google.Apis.Http.IHttpExecuteInterceptor Google.Apis.Http.IHttpUnsuccessfulResponseHandler Google.Apis.Http.IConfigurableHttpClientInitializer Google.Apis.Auth.OAuth2.ITokenAccess

Public Member Functions

 UserCredential (IAuthorizationCodeFlow flow, string userId, TokenResponse token)
 Constructs a new credential instance. More...
 
async Task InterceptAsync (HttpRequestMessage request, CancellationToken taskCancellationToken)
 Default implementation is to try to refresh the access token if there is no access token or if we are 1 minute away from expiration. If token server is unavailable, it will try to use the access token even if has expired. If successful, it will call IAccessMethod.Intercept. More...
 
async Task< bool > HandleResponseAsync (HandleUnsuccessfulResponseArgs args)
 Handles an abnormal response when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the abnormal response can be resolved, you must return true. More...
 
void Initialize (ConfigurableHttpClient httpClient)
 Initializes a HTTP client after it was created. More...
 
virtual async Task< string > GetAccessTokenForRequestAsync (string authUri=null, CancellationToken cancellationToken=default(CancellationToken))
 Gets an access token to authorize a request. Implementations should handle automatic refreshes of the token if they are supported. The authUri might be required by some credential types (e.g. the JWT access token) while other credential types migth just ignore it. More...
 
async Task< bool > RefreshTokenAsync (CancellationToken taskCancellationToken)
 Refreshes the token by calling to Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RefreshTokenAsync. Then it updates the TokenResponse with the new token instance. More...
 
async Task< bool > RevokeTokenAsync (CancellationToken taskCancellationToken)
 Asynchronously revokes the token by calling Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RevokeTokenAsync. More...
 

Static Protected Attributes

static readonly ILogger Logger = ApplicationContext.Logger.ForType<UserCredential>()
 

Properties

TokenResponse Token [get, set]
 Gets or sets the token response which contains the access token. More...
 
IAuthorizationCodeFlow Flow [get]
 Gets the authorization code flow. More...
 
string UserId [get]
 Gets the user identity. More...
 

Detailed Description

OAuth 2.0 credential for accessing protected resources using an access token, as well as optionally refreshing the access token when it expires using a refresh token.

Constructor & Destructor Documentation

Google.Apis.Auth.OAuth2.UserCredential.UserCredential ( IAuthorizationCodeFlow  flow,
string  userId,
TokenResponse  token 
)
inline

Constructs a new credential instance.

Parameters
flowAuthorization code flow.
userIdUser identifier.
tokenAn initial token for the user.

Member Function Documentation

virtual async Task<string> Google.Apis.Auth.OAuth2.UserCredential.GetAccessTokenForRequestAsync ( string  authUri = null,
CancellationToken  cancellationToken = default(CancellationToken) 
)
inlinevirtual

Gets an access token to authorize a request. Implementations should handle automatic refreshes of the token if they are supported. The authUri might be required by some credential types (e.g. the JWT access token) while other credential types migth just ignore it.

Parameters
authUriThe URI the returned token will grant access to.
cancellationTokenThe cancellation token.
Returns
The access token.

Implements Google.Apis.Auth.OAuth2.ITokenAccess.

async Task<bool> Google.Apis.Auth.OAuth2.UserCredential.HandleResponseAsync ( HandleUnsuccessfulResponseArgs  args)
inline

Handles an abnormal response when sending a HTTP request. A simple rule must be followed, if you modify the request object in a way that the abnormal response can be resolved, you must return true.

Parameters
argsHandle response argument which contains properties such as the request, response, current failed try.
Returns
Whether this handler has made a change that requires the request to be resent.

Implements Google.Apis.Http.IHttpUnsuccessfulResponseHandler.

void Google.Apis.Auth.OAuth2.UserCredential.Initialize ( ConfigurableHttpClient  httpClient)
inline

Initializes a HTTP client after it was created.

Implements Google.Apis.Http.IConfigurableHttpClientInitializer.

async Task Google.Apis.Auth.OAuth2.UserCredential.InterceptAsync ( HttpRequestMessage  request,
CancellationToken  taskCancellationToken 
)
inline

Default implementation is to try to refresh the access token if there is no access token or if we are 1 minute away from expiration. If token server is unavailable, it will try to use the access token even if has expired. If successful, it will call IAccessMethod.Intercept.

Implements Google.Apis.Http.IHttpExecuteInterceptor.

async Task<bool> Google.Apis.Auth.OAuth2.UserCredential.RefreshTokenAsync ( CancellationToken  taskCancellationToken)
inline

Refreshes the token by calling to Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RefreshTokenAsync. Then it updates the TokenResponse with the new token instance.

Parameters
taskCancellationTokenCancellation token to cancel an operation.
Returns
true if the token was refreshed.
async Task<bool> Google.Apis.Auth.OAuth2.UserCredential.RevokeTokenAsync ( CancellationToken  taskCancellationToken)
inline

Asynchronously revokes the token by calling Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RevokeTokenAsync.

Parameters
taskCancellationTokenCancellation token to cancel an operation.
Returns
true if the token was revoked successfully.

Property Documentation

IAuthorizationCodeFlow Google.Apis.Auth.OAuth2.UserCredential.Flow
get

Gets the authorization code flow.

TokenResponse Google.Apis.Auth.OAuth2.UserCredential.Token
getset

Gets or sets the token response which contains the access token.

string Google.Apis.Auth.OAuth2.UserCredential.UserId
get

Gets the user identity.


The documentation for this class was generated from the following file: