googleauth - Class Google::Auth::APIKeyCredentials (v1.15.0) Stay organized with collections Save and categorize content based on your preferences.
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
Includes
Methods
.from_env
defself.from_env(_scope=nil,options={})->Google::Auth::APIKeyCredentials,nilCreates an APIKeyCredentials from the environment.Checks the ENV['GOOGLE_API_KEY'] variable.
- _scope (String) — The scope to use for OAuth. Not used by API key auth.
- options (Hash) — The options to pass to the credentials instance
- (Google::Auth::APIKeyCredentials, nil) — Credentials if the API key environment variable is present,nil otherwise
.make_creds
defself.make_creds(options={})->Google::Auth::APIKeyCredentialsCreate the APIKeyCredentials.
- options (Hash) — The credentials options
#api_key
defapi_key()->String- (String) — The API key
#apply!
defapply!(a_hash,_opts={})->HashUpdates 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.
- 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 the
BaseClientinterface.
- (Hash) — The modified hash (the same hash passed as the
a_hashargument).
#duplicate
defduplicate(options={})->Google::Auth::APIKeyCredentialsCreates a duplicate of these credentials.
- options (Hash) — Additional options for configuring the credentials
#expires_within?
defexpires_within?(_seconds)->BooleanDetermines if the credentials object has expired.Since API keys don't expire, this always returns false.
- _seconds (Fixnum) — The optional timeout in seconds since the last refresh
- (Boolean) — True if the token has expired, false otherwise.
#initialize
definitialize(options={})->APIKeyCredentialsInitialize the APIKeyCredentials.
- options (Hash) — The credentials options
- (APIKeyCredentials) — a new instance of APIKeyCredentials
- (ArgumentError) — If the API key is nil or empty
#universe_domain
defuniverse_domain()->String- (String) — The universe domain of the universethis API key is for
#universe_domain=
defuniverse_domain=(value)->String- value (String) — The universe domain of the universethis API key is for
- (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.