C# Class Google.PowerShell.Common.AuthenticateWithSdkCredentialsExecutor

OAuth 2.0 credential for accessing protected resources using an access token. This class will get the access token from "gcloud auth print-access-token".
Inheritance: ICredential, IHttpExecuteInterceptor, IHttpUnsuccessfulResponseHandler
Mostra file Open project: GoogleCloudPlatform/google-cloud-powershell Class Usage Examples

Public Methods

Method Description
GetAccessTokenForRequestAsync ( string authUri = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
HandleResponseAsync ( Google.Apis.Http.HandleUnsuccessfulResponseArgs args ) : Task

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.

Initialize ( Google.Apis.Http.ConfigurableHttpClient httpClient ) : void
InterceptAsync ( HttpRequestMessage request, CancellationToken taskCancellationToken ) : Task

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.

RefreshTokenAsync ( CancellationToken taskCancellationToken ) : Task

Refreshes the token by calling to ActiveUserConfig.GetActiveUserToken

RevokeTokenAsync ( CancellationToken taskCancellationToken ) : Task

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

Method Details

GetAccessTokenForRequestAsync() public method

public GetAccessTokenForRequestAsync ( string authUri = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
authUri string
cancellationToken System.Threading.CancellationToken
return Task

HandleResponseAsync() public method

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.
public HandleResponseAsync ( Google.Apis.Http.HandleUnsuccessfulResponseArgs args ) : Task
args Google.Apis.Http.HandleUnsuccessfulResponseArgs
return Task

Initialize() public method

public Initialize ( Google.Apis.Http.ConfigurableHttpClient httpClient ) : void
httpClient Google.Apis.Http.ConfigurableHttpClient
return void

InterceptAsync() public method

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.
public InterceptAsync ( HttpRequestMessage request, CancellationToken taskCancellationToken ) : Task
request System.Net.Http.HttpRequestMessage
taskCancellationToken System.Threading.CancellationToken
return Task

RefreshTokenAsync() public method

Refreshes the token by calling to ActiveUserConfig.GetActiveUserToken
public RefreshTokenAsync ( CancellationToken taskCancellationToken ) : Task
taskCancellationToken System.Threading.CancellationToken
return Task

RevokeTokenAsync() public method

Asynchronously revokes the token by calling Google.Apis.Auth.OAuth2.Flows.IAuthorizationCodeFlow.RevokeTokenAsync.
public RevokeTokenAsync ( CancellationToken taskCancellationToken ) : Task
taskCancellationToken System.Threading.CancellationToken Cancellation token to cancel an operation.
return Task