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, universe_domain: 'googleapis.com') ⇒ 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.

  • universe_domain (String) (defaults to: 'googleapis.com') —

    The universe domain of the credential, reported to gRPC google-cloud clients so they don't raise Gapic::UniverseDomainMismatch. Defaults to googleapis.com.



25
26
27
28
29
30
31
32
33
34
# File 'lib/google/auth/extras/static_credential.rb', line 25

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

  @quota_project_id = quota_project_id
end

Instance Attribute Details

#quota_project_id ⇒ Object (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_token ⇒ Object



36
37
38
39
40
41
# File 'lib/google/auth/extras/static_credential.rb', line 36

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

#inspect ⇒ Object



43
44
45
46
47
48
49
# File 'lib/google/auth/extras/static_credential.rb', line 43

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