Class: Google::Auth::Extras::StaticCredential

Inherits:
Signet::OAuth2::Client
  • Object
show all
Defined in:
lib/google/auth/extras/static_credential.rb

Overview

This credential uses a static access token.

Defined Under Namespace

Classes: AuthorizationExpired

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token:, quota_project_id: nil) ⇒ StaticCredential

A credential using a static access token.

Parameters:

  • access_token (String)

    The access token to use.

  • quota_project_id (String) (defaults to: nil)

    The project ID used for quota and billing. This project may be different from the project used to create the credentials.



21
22
23
24
25
26
27
28
29
# File 'lib/google/auth/extras/static_credential.rb', line 21

def initialize(access_token:, quota_project_id: nil)
  super(
    access_token: access_token,
    expires_at: TokenInfo.lookup_access_token(access_token).fetch('exp'),
    issued_at: nil,
  )

  @quota_project_id = quota_project_id
end

Instance Attribute Details

#quota_project_idObject (readonly)

Returns the value of attribute quota_project_id.



10
11
12
# File 'lib/google/auth/extras/static_credential.rb', line 10

def quota_project_id
  @quota_project_id
end

Instance Method Details

#fetch_access_tokenObject



31
32
33
34
35
36
# File 'lib/google/auth/extras/static_credential.rb', line 31

def fetch_access_token(*)
  raise RefreshNotSupported
rescue RefreshNotSupported
  # This is a simple trick for getting the cause to be set.
  raise Signet::AuthorizationError, 'Refresh not supported'
end

#inspectObject



38
39
40
41
42
43
44
# File 'lib/google/auth/extras/static_credential.rb', line 38

def inspect
  "#<#{self.class.name}" \
    ' @access_token=[REDACTED]' \
    " @expires_at=#{expires_at.inspect}" \
    " @quota_project_id=#{@quota_project_id.inspect}" \
    '>'
end