googleauth - Class Google::Auth::APIKeyCredentials (v1.15.0)

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

Implementation of Google API Key authentication.

API Keys are text strings. They don't have an associated JSON file.

The end-user is managing their API Keys directly, not via an authentication library.

API Keys provide project information for an API request. API Keys don't reference an IAM principal, they do not expire, and cannot be refreshed.

Inherits

  • Object

Methods

.from_env

  def 
  
 self 
 . 
 from_env 
 ( 
 _scope 
  
 = 
  
 nil 
 , 
  
 options 
  
 = 
  
 {}) 
  
 - 
>  
 Google 
 :: 
 Auth 
 :: 
 APIKeyCredentials 
 , 
  
 nil 
 

Creates an APIKeyCredentials from the environment. Checks the ENV['GOOGLE_API_KEY'] variable.

Parameters
  • _scope(String) — The scope to use for OAuth. Not used by API key auth.
  • options(Hash) — The options to pass to the credentials instance
Returns

.make_creds

  def 
  
 self 
 . 
 make_creds 
 ( 
 options 
  
 = 
  
 {}) 
  
 - 
>  
 Google 
 :: 
 Auth 
 :: 
 APIKeyCredentials 
 

Create the APIKeyCredentials.

Parameter
  • options(Hash) — The credentials options

#api_key

  def 
  
 api_key 
 () 
  
 - 
>  
 String 
 
Returns
  • (String) — The API key

#apply!

  def 
  
 apply! 
 ( 
 a_hash 
 , 
  
 _opts 
  
 = 
  
 {}) 
  
 - 
>  
 Hash 
 

Updates the provided hash with the API Key header.

The apply! method modifies the provided hash in place, adding the x-goog-api-key header with the API Key value.

The API Key is hashed before being logged for security purposes.

NB: this method typically would be called through updater_proc . Some older clients call it directly though, so it has to be public.

Parameters
  • a_hash(Hash) — The hash to which the API Key header should be added. This is typically a hash representing the request headers. This hash will be modified in place.
  • _opts(Hash) — Additional options (currently not used). Included for consistency with the BaseClient interface.
Returns
  • (Hash) — The modified hash (the same hash passed as the a_hash argument).

#duplicate

  def 
  
 duplicate 
 ( 
 options 
  
 = 
  
 {}) 
  
 - 
>  
 Google 
 :: 
 Auth 
 :: 
 APIKeyCredentials 
 

Creates a duplicate of these credentials.

Parameter
  • options(Hash) — Additional options for configuring the credentials

#expires_within?

  def 
  
 expires_within? 
 ( 
 _seconds 
 ) 
  
 - 
>  
 Boolean 
 

Determines if the credentials object has expired. Since API keys don't expire, this always returns false.

Parameter
  • _seconds(Fixnum) — The optional timeout in seconds since the last refresh
Returns
  • (Boolean) — True if the token has expired, false otherwise.

#initialize

  def 
  
 initialize 
 ( 
 options 
  
 = 
  
 {}) 
  
 - 
>  
 APIKeyCredentials 
 

Initialize the APIKeyCredentials.

Parameter
  • options(Hash) — The credentials options
Returns
Raises
  • (ArgumentError) — If the API key is nil or empty

#universe_domain

  def 
  
 universe_domain 
 () 
  
 - 
>  
 String 
 
Returns
  • (String) — The universe domain of the universe this API key is for

#universe_domain=

  def 
  
 universe_domain= 
 ( 
 value 
 ) 
  
 - 
>  
 String 
 
Parameter
  • value(String) — The universe domain of the universe this API key is for
Returns
  • (String) — The universe domain of the universe this API key is for
Create a Mobile Website
View Site in Mobile | Classic
Share by: