Show / Hide Table of Contents

Class ComputeCredential

Google OAuth 2.0 credential for accessing protected resources using an access token. The Google OAuth 2.0 Authorization Server supports server-to-server interactions such as those between a web application and Google Cloud Storage. The requesting application has to prove its own identity to gain access to an API, and an end-user doesn't have to be involved.

More details about Compute Engine authentication is available at: https://cloud.google.com/compute/docs/authentication.

Inheritance
System.Object
ServiceCredential
ComputeCredential
Implements
ICredential
Google.Apis.Http.IConfigurableHttpClientInitializer
ITokenAccess
Google.Apis.Http.IHttpExecuteInterceptor
Google.Apis.Http.IHttpUnsuccessfulResponseHandler
Inherited Members
ServiceCredential.Logger
ServiceCredential.TokenServerUrl
ServiceCredential.Clock
ServiceCredential.AccessMethod
ServiceCredential.HttpClient
ServiceCredential.Token
ServiceCredential.Initialize(ConfigurableHttpClient)
ServiceCredential.InterceptAsync(HttpRequestMessage, CancellationToken)
ServiceCredential.HandleResponseAsync(HandleUnsuccessfulResponseArgs)
ServiceCredential.GetAccessTokenForRequestAsync(String, CancellationToken)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Google.Apis.Auth.OAuth2
Assembly: Google.Apis.Auth.dll
Syntax
public class ComputeCredential : ServiceCredential, ICredential, IConfigurableHttpClientInitializer, ITokenAccess, IHttpExecuteInterceptor, IHttpUnsuccessfulResponseHandler

Constructors

ComputeCredential()

Constructs a new Compute credential instance.

Declaration
public ComputeCredential()

ComputeCredential(ComputeCredential.Initializer)

Constructs a new Compute credential instance.

Declaration
public ComputeCredential(ComputeCredential.Initializer initializer)
Parameters
Type Name Description
ComputeCredential.Initializer initializer

Fields

MetadataServerUrl

The metadata server url.

Declaration
public const string MetadataServerUrl = "http://169.254.169.254"
Field Value
Type Description
System.String

Methods

IsRunningOnComputeEngine()

Detects if application is running on Google Compute Engine. This is achieved by attempting to contact GCE metadata server, that is only available on GCE. The check is only performed the first time you call this method, subsequent invocations used cached result of the first call.

Declaration
public static Task<bool> IsRunningOnComputeEngine()
Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

RequestAccessTokenAsync(CancellationToken)

Requests a new token.

Declaration
public override Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken)
Parameters
Type Name Description
System.Threading.CancellationToken taskCancellationToken

Cancellation token to cancel operation.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

true if a new token was received successfully.

Overrides
ServiceCredential.RequestAccessTokenAsync(CancellationToken)

Implements

ICredential
Google.Apis.Http.IConfigurableHttpClientInitializer
ITokenAccess
Google.Apis.Http.IHttpExecuteInterceptor
Google.Apis.Http.IHttpUnsuccessfulResponseHandler
Back to top