Class: Google::APIClient::Storage
- Inherits:
-
Object
- Object
- Google::APIClient::Storage
- Defined in:
- lib/google/api_client/auth/storage.rb
Overview
Represents cached OAuth 2 tokens stored on local disk in a JSON serialized file. Meant to resemble the serialized format google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.file.Storage-class.html
Constant Summary collapse
- AUTHORIZATION_URI =
'https://accounts.google.com/o/oauth2/auth'
- TOKEN_CREDENTIAL_URI =
'https://accounts.google.com/o/oauth2/token'
Instance Attribute Summary collapse
- #authorization ⇒ Signet::OAuth2::Client readonly
-
#store ⇒ Object
Storage object.
Instance Method Summary collapse
-
#authorize ⇒ Object
Loads credentials and authorizes an client.
-
#initialize(store) ⇒ Storage
constructor
Initializes the Storage object.
-
#refresh_authorization ⇒ Object
refresh credentials and save them to store.
-
#write_credentials(authorization = nil) ⇒ Object
Write the credentials to the specified store.
Constructor Details
#initialize(store) ⇒ Storage
Initializes the Storage object.
39 40 41 42 |
# File 'lib/google/api_client/auth/storage.rb', line 39 def initialize(store) @store= store @authorization = nil end |
Instance Attribute Details
#authorization ⇒ Signet::OAuth2::Client (readonly)
33 34 35 |
# File 'lib/google/api_client/auth/storage.rb', line 33 def @authorization end |
#store ⇒ Object
Returns Storage object.
30 31 32 |
# File 'lib/google/api_client/auth/storage.rb', line 30 def store @store end |
Instance Method Details
#authorize ⇒ Object
Loads credentials and authorizes an client.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/google/api_client/auth/storage.rb', line 60 def @authorization = nil cached_credentials = load_credentials if cached_credentials && cached_credentials.size > 0 @authorization = Signet::OAuth2::Client.new(cached_credentials) @authorization.issued_at = Time.at(cached_credentials['issued_at'].to_i) self. if @authorization.expired? end return @authorization end |
#refresh_authorization ⇒ Object
refresh credentials and save them to store
73 74 75 76 |
# File 'lib/google/api_client/auth/storage.rb', line 73 def .refresh! self.write_credentials end |
#write_credentials(authorization = nil) ⇒ Object
Write the credentials to the specified store.
50 51 52 53 54 55 |
# File 'lib/google/api_client/auth/storage.rb', line 50 def write_credentials(=nil) @authorization = if if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token store.write_credentials(credentials_hash) end end |