Class: Google::APIClient::ClientSecrets Deprecated
- Inherits:
- 
      Object
      
        - Object
- Google::APIClient::ClientSecrets
 
- Defined in:
- lib/google/api_client/client_secrets.rb
Overview
Use google-auth-library-ruby instead
Manages the persistence of client configuration data and secrets. Format inspired by the Google API Python client.
Instance Attribute Summary collapse
- 
  
    
      #access_token  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute access_token. 
- 
  
    
      #authorization_uri  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute authorization_uri. 
- 
  
    
      #client_id  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute client_id. 
- 
  
    
      #client_secret  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute client_secret. 
- 
  
    
      #expires_at  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute expires_at. 
- 
  
    
      #expires_in  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute expires_in. 
- 
  
    
      #flow  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute flow. 
- 
  
    
      #id_token  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute id_token. 
- 
  
    
      #issued_at  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute issued_at. 
- 
  
    
      #javascript_origins  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute javascript_origins. 
- 
  
    
      #redirect_uris  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute redirect_uris. 
- 
  
    
      #refresh_token  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute refresh_token. 
- 
  
    
      #token_credential_uri  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute token_credential_uri. 
Class Method Summary collapse
- 
  
    
      .load(filename = nil)  ⇒ Google::APIClient::ClientSecrets 
    
    
  
  
  
  
  
  
  
  
  
    Reads client configuration from a file. 
Instance Method Summary collapse
- 
  
    
      #initialize(options = {})  ⇒ ClientSecrets 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Initialize OAuth client settings. 
- #to_authorization ⇒ Object
- #to_hash ⇒ Object
- 
  
    
      #to_json  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Serialize back to the original JSON form. 
Constructor Details
#initialize(options = {}) ⇒ ClientSecrets
Initialize OAuth client settings.
| 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # File 'lib/google/api_client/client_secrets.rb', line 82 def initialize(={}) # Client auth configuration @flow = [:flow] || .keys.first.to_s || 'web' fdata = [@flow.to_sym] || [@flow] @client_id = fdata[:client_id] || fdata["client_id"] @client_secret = fdata[:client_secret] || fdata["client_secret"] @redirect_uris = fdata[:redirect_uris] || fdata["redirect_uris"] @redirect_uris ||= [fdata[:redirect_uri] || fdata["redirect_uri"]].compact @javascript_origins = ( fdata[:javascript_origins] || fdata["javascript_origins"] ) @javascript_origins ||= [fdata[:javascript_origin] || fdata["javascript_origin"]].compact @authorization_uri = fdata[:auth_uri] || fdata["auth_uri"] @authorization_uri ||= fdata[:authorization_uri] @token_credential_uri = fdata[:token_uri] || fdata["token_uri"] @token_credential_uri ||= fdata[:token_credential_uri] # Associated token info @access_token = fdata[:access_token] || fdata["access_token"] @refresh_token = fdata[:refresh_token] || fdata["refresh_token"] @id_token = fdata[:id_token] || fdata["id_token"] @expires_in = fdata[:expires_in] || fdata["expires_in"] @expires_at = fdata[:expires_at] || fdata["expires_at"] @issued_at = fdata[:issued_at] || fdata["issued_at"] end | 
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def access_token @access_token end | 
#authorization_uri ⇒ Object (readonly)
Returns the value of attribute authorization_uri
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def @authorization_uri end | 
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def client_id @client_id end | 
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def client_secret @client_secret end | 
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def expires_at @expires_at end | 
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def expires_in @expires_in end | 
#flow ⇒ Object (readonly)
Returns the value of attribute flow
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def flow @flow end | 
#id_token ⇒ Object (readonly)
Returns the value of attribute id_token
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def id_token @id_token end | 
#issued_at ⇒ Object (readonly)
Returns the value of attribute issued_at
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def issued_at @issued_at end | 
#javascript_origins ⇒ Object (readonly)
Returns the value of attribute javascript_origins
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def javascript_origins @javascript_origins end | 
#redirect_uris ⇒ Object (readonly)
Returns the value of attribute redirect_uris
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def redirect_uris @redirect_uris end | 
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def refresh_token @refresh_token end | 
#token_credential_uri ⇒ Object (readonly)
Returns the value of attribute token_credential_uri
| 109 110 111 | # File 'lib/google/api_client/client_secrets.rb', line 109 def token_credential_uri @token_credential_uri end | 
Class Method Details
.load(filename = nil) ⇒ Google::APIClient::ClientSecrets
Reads client configuration from a file
| 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # File 'lib/google/api_client/client_secrets.rb', line 56 def self.load(filename=nil) if filename && File.directory?(filename) search_path = File.(filename) filename = nil end while filename == nil search_path ||= File.('.') if File.exists?(File.join(search_path, 'client_secrets.json')) filename = File.join(search_path, 'client_secrets.json') elsif search_path == '/' || search_path =~ /[a-zA-Z]:[\/\\]/ raise ArgumentError, 'No client_secrets.json filename supplied ' + 'and/or could not be found in search path.' else search_path = File.(File.join(search_path, '..')) end end data = File.open(filename, 'r') { |file| JSON.load(file.read) } return self.new(data) end | 
Instance Method Details
#to_authorization ⇒ Object
| 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | # File 'lib/google/api_client/client_secrets.rb', line 149 def gem 'signet', '>= 0.4.0' require 'signet/oauth_2/client' # NOTE: Do not rely on this default value, as it may change = Signet::OAuth2::Client.new .client_id = self.client_id .client_secret = self.client_secret . = ( self. || 'https://accounts.google.com/o/oauth2/auth' ) .token_credential_uri = ( self.token_credential_uri || 'https://accounts.google.com/o/oauth2/token' ) .redirect_uri = self.redirect_uris.first # These are supported, but unlikely. .access_token = self.access_token .refresh_token = self.refresh_token .id_token = self.id_token .expires_in = self.expires_in .issued_at = self.issued_at if self.issued_at .expires_at = self.expires_at if self.expires_at return end | 
#to_hash ⇒ Object
| 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | # File 'lib/google/api_client/client_secrets.rb', line 124 def to_hash { self.flow => ({ 'client_id' => self.client_id, 'client_secret' => self.client_secret, 'redirect_uris' => self.redirect_uris, 'javascript_origins' => self.javascript_origins, 'auth_uri' => self., 'token_uri' => self.token_credential_uri, 'access_token' => self.access_token, 'refresh_token' => self.refresh_token, 'id_token' => self.id_token, 'expires_in' => self.expires_in, 'expires_at' => self.expires_at, 'issued_at' => self.issued_at }).inject({}) do |accu, (k, v)| # Prunes empty values from JSON output. unless v == nil || (v.respond_to?(:empty?) && v.empty?) accu[k] = v end accu end } end | 
#to_json ⇒ String
Serialize back to the original JSON form
| 120 121 122 | # File 'lib/google/api_client/client_secrets.rb', line 120 def to_json return Json.dump(to_hash) end |