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

Credential for authorizing calls using OAuth 2.0. It is a convenience wrapper that allows handling of different types of credentials (like ServiceAccountCredential, ComputeCredential or UserCredential) in a unified way. More...

Inheritance diagram for Google.Apis.Auth.OAuth2.GoogleCredential:
Google.Apis.Http.IConfigurableHttpClientInitializer Google.Apis.Auth.OAuth2.ITokenAccess

Classes

class  ServiceAccountGoogleCredential
 Wraps ServiceAccountCredential as GoogleCredential. We need this subclass because wrapping ServiceAccountCredential (unlike other wrapped credential types) requires special handling for IsCreateScopedRequired and CreateScoped members.
 

Public Member Functions

virtual GoogleCredential CreateScoped (IEnumerable< string > scopes)
 If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same instance. More...
 
GoogleCredential CreateScoped (params string[] scopes)
 If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same instance. More...
 

Static Public Member Functions

static Task< GoogleCredentialGetApplicationDefaultAsync ()
 
static GoogleCredential FromStream (Stream stream)
 Loads credential from stream containing JSON credential data. More...
 

Protected Attributes

readonly ICredential credential
 The underlying credential being wrapped by this object. More...
 

Properties

virtual bool IsCreateScopedRequired [get]
 

Detailed Description

Credential for authorizing calls using OAuth 2.0. It is a convenience wrapper that allows handling of different types of credentials (like ServiceAccountCredential, ComputeCredential or UserCredential) in a unified way.

See GetApplicationDefaultAsync for the credential retrieval logic.

Member Function Documentation

virtual GoogleCredential Google.Apis.Auth.OAuth2.GoogleCredential.CreateScoped ( IEnumerable< string >  scopes)
inlinevirtual

If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same instance.

GoogleCredential Google.Apis.Auth.OAuth2.GoogleCredential.CreateScoped ( params string[]  scopes)
inline

If the credential supports scopes, creates a copy with the specified scopes. Otherwise, it returns the same instance.

static GoogleCredential Google.Apis.Auth.OAuth2.GoogleCredential.FromStream ( Stream  stream)
inlinestatic

Loads credential from stream containing JSON credential data.

The stream can contain a Service Account key file in JSON format from the Google Developers Console or a stored user credential using the format supported by the Cloud SDK.

static Task<GoogleCredential> Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync ( )
inlinestatic

Returns the Application Default Credentials which are ambient credentials that identify and authorize the whole application.

The ambient credentials are determined as following order:

  1. The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified, it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a service account using the Google Developers Console in the section APIs & Auth, in the sub-section Credentials. Create a service account or choose an existing one and select Generate new JSON key. Set the environment variable to the path of the JSON file downloaded.
  2. If you have installed the Google Cloud SDK on your machine and have run the command GCloud Auth Login, your identity can be used as a proxy to test code calling APIs from that machine.
  3. If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance will be used.
  4. If all previous steps have failed, InvalidOperationException is thrown.

Member Data Documentation

readonly ICredential Google.Apis.Auth.OAuth2.GoogleCredential.credential
protected

The underlying credential being wrapped by this object.

Property Documentation

virtual bool Google.Apis.Auth.OAuth2.GoogleCredential.IsCreateScopedRequired
get

Returns true only if this credential type has no scopes by default and requires a call to o:CreateScoped before use.

Credentials need to have scopes in them before they can be used to access Google services. Some Credential types have scopes built-in, and some don't. This property indicates whether the Credential type has scopes built-in.

  1. ComputeCredential has scopes built-in. Nothing additional is required.
  2. UserCredential has scopes built-in, as they were obtained during the consent screen. Nothing additional is required.
  3. ServiceAccountCredential does not have scopes built-in by default. Caller should invoke o:CreateScoped to add scopes to the credential.

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