googleauth - Class Google::Auth::ServiceAccountCredentials (v1.17.3)

Reference documentation and code samples for the googleauth class Google::Auth::ServiceAccountCredentials.

Authenticates requests using Google's Service Account credentials via an OAuth access token.

This class allows authorizing requests for service accounts directly from credentials from a json key file downloaded from the developer console (via 'Generate new Json Key').

cf Application Default Credentials

Methods

.make_creds

def self.make_creds(options = {})

Creates a ServiceAccountCredentials.

Parameters
  • json_key_io (IO, nil) — Optional. An IO object containing the JSON key
  • scope (String, Array<String>, nil) — Optional. The scope(s) to access
  • enable_self_signed_jwt (Boolean, nil) — Optional. Whether to use self-signed JWTs
  • target_audience (String, nil) — Optional. The target audience for ID token requests
  • audience (String, nil) — Optional. Custom token endpoint audience URI
  • token_credential_uri (String, nil) — Optional. Custom token credential URI
  • default_connection (Faraday::Connection, nil) — Optional. The connection object to use
  • connection_builder (Proc, nil) — Optional. A Proc that returns a Faraday connection
Raises
  • (ArgumentError) — If both scope and target_audience are specified
  • (InitializationError) — If json_key_io is not an IO object, or if required credential fields (private_key or client_email) are missing

.unescape

def self.unescape(str) -> String, nil

Handles certain escape sequences that sometimes appear in input. Specifically, interprets the "\n" sequence for newline, and removes enclosing quotes.

Parameter
  • str (String) — The string to unescape
Returns
  • (String, nil) — The unescaped string, or nil if input is nil

#apply!

def apply!(a_hash, opts = {})

Extends the base class to use a transient ServiceAccountJwtHeaderCredentials for certain cases.

#duplicate

def duplicate(options = {})

Creates a duplicate of these credentials without the Signet::OAuth2::Client-specific transient state (e.g. cached tokens)

Parameter
  • options (Hash) —

    Overrides for the credentials parameters. The following keys are recognized in addition to keys in the Signet::OAuth2::Client

    • :enable_self_signed_jwt Whether the self-signed JWT should be used for the authentication
    • project_id the project id to use during the authentication
    • quota_project_id the quota project id to use during the authentication

#enable_self_signed_jwt?

def enable_self_signed_jwt?() -> Boolean
Returns
  • (Boolean)

#initialize

def initialize(options = {}) -> ServiceAccountCredentials
Returns

#needs_access_token?

def needs_access_token?() -> Boolean

Modifies this logic so it also requires self-signed-jwt to be disabled

Returns
  • (Boolean)

#project_id

def project_id()

Returns the value of attribute project_id.

#quota_project_id

def quota_project_id()

Returns the value of attribute quota_project_id.

#update!

def update!(options = {}) -> Google::Auth::ServiceAccountCredentials

Destructively updates these credentials

This method is called by Signet::OAuth2::Client's constructor

Parameter
  • options (Hash) —

    Overrides for the credentials parameters. The following keys are recognized in addition to keys in the Signet::OAuth2::Client

    • :enable_self_signed_jwt Whether the self-signed JWT should be used for the authentication
    • project_id the project id to use during the authentication
    • quota_project_id the quota project id to use during the authentication

Constants

TOKEN_CRED_URI