Class: Google::Auth::DefaultCredentials

Inherits:
Object
  • Object
show all
Extended by:
CredentialsLoader
Defined in:
lib/googleauth.rb

Overview

DefaultCredentials is used to preload the credentials file, to determine which type of credentials should be loaded.

Constant Summary

Constants included from CredentialsLoader

CredentialsLoader::ENV_VAR, CredentialsLoader::NOT_FOUND_ERROR, CredentialsLoader::WELL_KNOWN_ERROR, CredentialsLoader::WELL_KNOWN_PATH

Class Method Summary collapse

Methods included from CredentialsLoader

from_env, from_well_known_path, make_creds, windows?

Class Method Details

.determine_creds_class(json_key_io) ⇒ Object

Reads the input json and determines which creds class to use.



61
62
63
64
65
66
67
68
# File 'lib/googleauth.rb', line 61

def self.determine_creds_class(json_key_io)
  json_key = MultiJson.load(json_key_io.read)
  fail "the json is missing the #{key} field" unless json_key.key?('type')
  type = json_key['type']
  return json_key, ServiceAccountCredentials if type == 'service_account'
  return [json_key, UserRefreshCredentials] if type == 'authorized_user'
  fail "credentials type '#{type}' is not supported"
end

.make_creds(json_key_io, scope = nil) ⇒ Object

override CredentialsLoader#make_creds to use the class determined by loading the json.



55
56
57
58
# File 'lib/googleauth.rb', line 55

def self.make_creds(json_key_io, scope = nil)
  json_key, clz = determine_creds_class(json_key_io)
  clz.new(StringIO.new(MultiJson.dump(json_key)), scope)
end