public class ComputeCredential : ServiceCredential, IHttpExecuteInterceptor, IHttpUnsuccessfulResponseHandler, IOidcTokenProvider, IGoogleCredential, ICredential, IConfigurableHttpClientInitializer, ITokenAccessWithHeaders, ITokenAccess
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.
Implements
IHttpExecuteInterceptor, IHttpUnsuccessfulResponseHandler, IOidcTokenProvider, ICredential, IConfigurableHttpClientInitializer, ITokenAccessWithHeaders, ITokenAccessNamespace
Google.Apis.Auth.OAuth2Assembly
Google.Apis.Auth.dll
Constructors
ComputeCredential()
public ComputeCredential()
Constructs a new Compute credential instance.
ComputeCredential(ComputeCredential.Initializer)
public ComputeCredential(ComputeCredential.Initializer initializer)
Constructs a new Compute credential instance.
Parameter | |
---|---|
Name | Description |
initializer | ComputeCredential.Initializer |
Fields
MetadataServerUrl
public const string MetadataServerUrl = null
The metadata server url. This can be overridden (for the purposes of Compute environment detection and auth token retrieval) using the GCE_METADATA_HOST environment variable.
Field Value | |
---|---|
Type | Description |
String |
Properties
OidcTokenUrl
public string OidcTokenUrl { get; }
Gets the OIDC Token URL.
Property Value | |
---|---|
Type | Description |
String |
Methods
GetOidcTokenAsync(OidcTokenOptions, CancellationToken)
public Task<OidcToken> GetOidcTokenAsync(OidcTokenOptions options, CancellationToken cancellationToken = null)
Returns an OIDC token for the given options.
Parameters | |
---|---|
Name | Description |
options | OidcTokenOptions The options to create the token from. |
cancellationToken | CancellationToken The cancellation token that may be used to cancel the request. |
Returns | |
---|---|
Type | Description |
Task<OidcToken> | The OIDC token. |
IsRunningOnComputeEngine()
public static Task<bool> 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.
Returns | |
---|---|
Type | Description |
Task<Boolean> |
RequestAccessTokenAsync(CancellationToken)
public override Task<bool> RequestAccessTokenAsync(CancellationToken taskCancellationToken)
Requests a new token.
Parameter | |
---|---|
Name | Description |
taskCancellationToken | CancellationToken Cancellation token to cancel operation. |
Returns | |
---|---|
Type | Description |
Task<Boolean> |
|