module Google::Auth::BaseClient
BaseClient
is a class used to contain common methods that are required by any Credentials
Client, including AwsCredentials, ServiceAccountCredentials
, and UserRefreshCredentials
. This is a superclass of Signet::OAuth2::Client
and has been created to create a generic interface for all credentials clients to use, including ones which do not inherit from Signet::OAuth2::Client
.
Constants
- AUTH_METADATA_KEY
Attributes
logger[RW]
The logger used to log operations on this client, such as token refresh.
Public Instance Methods
apply(a_hash, opts = {})
click to toggle source
Returns a clone of a_hash updated with the authentication token
# File lib/googleauth/base_client.rb, line 45 def apply a_hash, opts = {} a_copy = a_hash.clone apply! a_copy, opts a_copy end
apply!(a_hash, opts = {})
click to toggle source
Updates a_hash updated with the authentication token
# File lib/googleauth/base_client.rb, line 30 def apply! a_hash, opts = {} # fetch the access token there is currently not one, or if the client # has expired fetch_access_token! opts if needs_access_token? token = send token_type a_hash[AUTH_METADATA_KEY] = "Bearer #{token}" logger&.debug do hash = Digest::SHA256.hexdigest token Google::Logging::Message.from message: "Sending auth token. (sha256:#{hash})" end a_hash[AUTH_METADATA_KEY] end
expires_within?()
click to toggle source
# File lib/googleauth/base_client.rb, line 74 def expires_within? raise NoMethodError, "expires_within? not implemented" end
needs_access_token?()
click to toggle source
Whether the id_token or access_token is missing or about to expire.
# File lib/googleauth/base_client.rb, line 52 def needs_access_token? send(token_type).nil? || expires_within?(60) end
notify_refresh_listeners()
click to toggle source
# File lib/googleauth/base_client.rb, line 67 def notify_refresh_listeners listeners = defined?(@refresh_listeners) ? @refresh_listeners : [] listeners.each do |block| block.call self end end
on_refresh(&block)
click to toggle source
# File lib/googleauth/base_client.rb, line 62 def on_refresh &block @refresh_listeners = [] unless defined? @refresh_listeners @refresh_listeners << block end
updater_proc()
click to toggle source
Returns a reference to the apply
method, suitable for passing as a closure
# File lib/googleauth/base_client.rb, line 58 def updater_proc proc { |a_hash, opts = {}| apply a_hash, opts } end
Private Instance Methods
fetch_access_token!()
click to toggle source
# File lib/googleauth/base_client.rb, line 87 def fetch_access_token! raise NoMethodError, "fetch_access_token! not implemented" end
token_type()
click to toggle source
# File lib/googleauth/base_client.rb, line 83 def token_type raise NoMethodError, "token_type not implemented" end