1.17.8 (latest) 1.17.7 1.16.2 1.15.1 1.14.0 1.13.1 1.12.2 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.

<br />

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

- [Google::Auth::BaseClient](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-BaseClient.md.txt)

## Methods

### .from_env

```ruby
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**

- ([Google::Auth::APIKeyCredentials](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-APIKeyCredentials.md.txt), nil) --- Credentials if the API key environment variable is present, nil otherwise

### .make_creds

```ruby
def self.make_creds(options = {}) -> Google::Auth::APIKeyCredentials
```
Create the APIKeyCredentials.
**Parameter**

- **options** (Hash) --- The credentials options
**Returns**

- ([Google::Auth::APIKeyCredentials](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-APIKeyCredentials.md.txt))

### #api_key

```ruby
def api_key() -> String
```
**Returns**

- (String) --- The API key

### #apply!

```ruby
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.

<br />

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

```ruby
def duplicate(options = {}) -> Google::Auth::APIKeyCredentials
```
Creates a duplicate of these credentials.
**Parameter**

- **options** (Hash) --- Additional options for configuring the credentials
**Returns**

- ([Google::Auth::APIKeyCredentials](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-APIKeyCredentials.md.txt))

### #expires_within?

```ruby
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

```ruby
def initialize(options = {}) -> APIKeyCredentials
```
Initialize the APIKeyCredentials.
**Parameter**

- **options** (Hash) --- The credentials options
**Returns**

- ([APIKeyCredentials](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-APIKeyCredentials.md.txt)) --- a new instance of APIKeyCredentials
**Raises**

- (ArgumentError) --- If the API key is nil or empty

### #universe_domain

```ruby
def universe_domain() -> String
```
**Returns**

- (String) --- The universe domain of the universe this API key is for

### #universe_domain=

```ruby
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