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::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').

<br />

cf [Application Default Credentials](https://cloud.google.com/docs/authentication/production)

## Inherits

- [Signet::OAuth2::Client](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Signet-OAuth2-Client.md.txt)

## Extended By

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

## Methods

### .make_creds

```ruby
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](https://docs.cloud.google.com/ruby/docs/reference/googleauth/latest/Google-Auth-InitializationError.md.txt)) --- If json_key_io is not an IO object, or if required credential fields (private_key or client_email) are missing

### .unescape

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

```ruby
def apply!(a_hash, opts = {})
```
Extends the base class to use a transient
ServiceAccountJwtHeaderCredentials for certain cases.

### #duplicate

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

```ruby
def enable_self_signed_jwt?() -> Boolean
```
**Returns**

- (Boolean)

### #initialize

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

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

### #needs_access_token?

```ruby
def needs_access_token?() -> Boolean
```
Modifies this logic so it also requires self-signed-jwt to be disabled
**Returns**

- (Boolean)

### #project_id

```ruby
def project_id()
```
Returns the value of attribute project_id.

### #quota_project_id

```ruby
def quota_project_id()
```
Returns the value of attribute quota_project_id.

### #update!

```ruby
def update!(options = {}) -> Google::Auth::ServiceAccountCredentials
```
Destructively updates these credentials


<br />

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
**Returns**

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

## Constants

### TOKEN_CRED_URI

**value:** "<https://www.googleapis.com/oauth2/v4/token".freeze>