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 viaan 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

defself.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

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

Create the APIKeyCredentials.

Parameter
  • options (Hash) — The credentials options

#api_key

defapi_key()->String
Returns
  • (String) — The API key

#apply!

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

Updates the provided hash with the API Key header.

Theapply! method modifies the provided hash in place, adding thex-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 throughupdater_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 hashwill be modified in place.
  • _opts (Hash) — Additional options (currently not used). Includedfor consistency with theBaseClient interface.
Returns
  • (Hash) — The modified hash (the same hash passed as thea_hashargument).

#duplicate

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

Creates a duplicate of these credentials.

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

#expires_within?

defexpires_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

definitialize(options={})->APIKeyCredentials

Initialize the APIKeyCredentials.

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

#universe_domain

defuniverse_domain()->String
Returns
  • (String) — The universe domain of the universethis API key is for

#universe_domain=

defuniverse_domain=(value)->String
Parameter
  • value (String) — The universe domain of the universethis API key is for
Returns
  • (String) — The universe domain of the universethis API key is for

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.