Class: Google::Auth::ClientId
- Inherits:
-
Object
- Object
- Google::Auth::ClientId
- Defined in:
- lib/googleauth/client_id.rb
Overview
Representation of an application's identity for user authorization flows.
Constant Summary collapse
- INSTALLED_APP =
Toplevel JSON key for the an installed app configuration. Must include client_id and client_secret subkeys if present.
"installed".freeze
- WEB_APP =
Toplevel JSON key for the a webapp configuration. Must include client_id and client_secret subkeys if present.
"web".freeze
- CLIENT_ID =
JSON key for the client ID within an app configuration.
"client_id".freeze
- CLIENT_SECRET =
JSON key for the client secret within an app configuration.
"client_secret".freeze
- MISSING_TOP_LEVEL_ELEMENT_ERROR =
An error message raised when none of the expected toplevel properties can be found.
"Expected top level property 'installed' or 'web' to be present.".freeze
Class Attribute Summary collapse
-
.default ⇒ Object
Returns the value of attribute default.
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
Text identifier of the client ID.
-
#secret ⇒ String
readonly
Secret associated with the client ID.
Class Method Summary collapse
-
.from_file(file) ⇒ Google::Auth::ClientID
Constructs a Client ID from a JSON file downloaded from the Google Developers Console.
-
.from_hash(config) ⇒ Google::Auth::ClientID
Constructs a Client ID from a previously loaded JSON file.
Instance Method Summary collapse
-
#initialize(id, secret) ⇒ ClientId
constructor
Initialize the Client ID.
Constructor Details
#initialize(id, secret) ⇒ ClientId
Direct instantiation is discouraged to avoid embedding IDs
and secrets in source. See #from_file to load from
client_secrets.json
files.
Initialize the Client ID. Both id and secret must be non-nil.
66 67 68 69 70 71 |
# File 'lib/googleauth/client_id.rb', line 66 def initialize id, secret raise "Client id can not be nil" if id.nil? raise "Client secret can not be nil" if secret.nil? @id = id @secret = secret end |
Class Attribute Details
.default ⇒ Object
Returns the value of attribute default.
52 53 54 |
# File 'lib/googleauth/client_id.rb', line 52 def default @default end |
Instance Attribute Details
#id ⇒ String (readonly)
Text identifier of the client ID
43 44 45 |
# File 'lib/googleauth/client_id.rb', line 43 def id @id end |
#secret ⇒ String (readonly)
Secret associated with the client ID
49 50 51 |
# File 'lib/googleauth/client_id.rb', line 49 def secret @secret end |
Class Method Details
.from_file(file) ⇒ Google::Auth::ClientID
Constructs a Client ID from a JSON file downloaded from the Google Developers Console.
81 82 83 84 85 86 87 88 |
# File 'lib/googleauth/client_id.rb', line 81 def self.from_file file raise "File can not be nil." if file.nil? File.open file.to_s do |f| json = f.read config = MultiJson.load json from_hash config end end |
.from_hash(config) ⇒ Google::Auth::ClientID
Constructs a Client ID from a previously loaded JSON file. The hash structure should match the expected JSON format.
98 99 100 101 102 103 |
# File 'lib/googleauth/client_id.rb', line 98 def self.from_hash config raise "Hash can not be nil." if config.nil? raw_detail = config[INSTALLED_APP] || config[WEB_APP] raise MISSING_TOP_LEVEL_ELEMENT_ERROR if raw_detail.nil? ClientId.new raw_detail[CLIENT_ID], raw_detail[CLIENT_SECRET] end |