Class: Google::Auth::Credentials
- Inherits:
-
Object
- Object
- Google::Auth::Credentials
- Extended by:
- Forwardable
- Defined in:
- lib/googleauth/credentials.rb
Overview
This class is intended to be inherited by API-specific classes which overrides the SCOPE constant.
Constant Summary collapse
- TOKEN_CREDENTIAL_URI =
"https://oauth2.googleapis.com/token".freeze
- AUDIENCE =
"https://oauth2.googleapis.com/token".freeze
- SCOPE =
[].freeze
- PATH_ENV_VARS =
[].freeze
- JSON_ENV_VARS =
[].freeze
- DEFAULT_PATHS =
[].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
Class Method Summary collapse
-
.default(options = {}) ⇒ Object
Returns the default credentials checking, in this order, the path env evironment variables, json environment variables, default paths.
Instance Method Summary collapse
-
#initialize(keyfile, options = {}) ⇒ Credentials
constructor
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize(keyfile, options = {}) ⇒ Credentials
rubocop:disable Metrics/AbcSize
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/googleauth/credentials.rb', line 58 def initialize keyfile, = {} scope = [:scope] verify_keyfile_provided! keyfile @project_id = ["project_id"] || ["project"] if keyfile.is_a? Signet::OAuth2::Client @client = keyfile @project_id ||= keyfile.project_id if keyfile.respond_to? :project_id elsif keyfile.is_a? Hash hash = stringify_hash_keys keyfile hash["scope"] ||= scope @client = init_client hash, @project_id ||= (hash["project_id"] || hash["project"]) else verify_keyfile_exists! keyfile json = JSON.parse ::File.read(keyfile) json["scope"] ||= scope @project_id ||= (json["project_id"] || json["project"]) @client = init_client json, end CredentialsLoader.warn_if_cloud_sdk_credentials @client.client_id @project_id ||= CredentialsLoader.load_gcloud_project_id @client.fetch_access_token! end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
48 49 50 |
# File 'lib/googleauth/credentials.rb', line 48 def client @client end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
49 50 51 |
# File 'lib/googleauth/credentials.rb', line 49 def project_id @project_id end |
Class Method Details
.default(options = {}) ⇒ Object
Returns the default credentials checking, in this order, the path env evironment variables, json environment variables, default paths. If the previously stated locations do not contain keyfile information, this method defaults to use the application default.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/googleauth/credentials.rb', line 87 def self.default = {} # First try to find keyfile file from environment variables. client = from_path_vars # Second try to find keyfile json from environment variables. client ||= from_json_vars # Third try to find keyfile file from known file paths. client ||= from_default_paths # Finally get instantiated client from Google::Auth client ||= from_application_default client end |