Class: Google::APIClient::Storage Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/google/api_client/auth/storage.rb

Overview

Deprecated.

Use google-auth-library-ruby instead

Represents cached OAuth 2 tokens stored on local disk in a JSON serialized file. Meant to resemble the serialized format http://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

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ Storage

Initializes the Storage object.

Parameters:

  • store (Object)

    Storage object



41
42
43
44
# File 'lib/google/api_client/auth/storage.rb', line 41

def initialize(store)
  @store= store
  @authorization = nil
end

Instance Attribute Details

#authorizationSignet::OAuth2::Client (readonly)

Returns:

  • (Signet::OAuth2::Client)


34
35
36
# File 'lib/google/api_client/auth/storage.rb', line 34

def authorization
  @authorization
end

#storeObject

Returns Storage object.

Returns:

  • (Object)

    Storage object.



31
32
33
# File 'lib/google/api_client/auth/storage.rb', line 31

def store
  @store
end

Instance Method Details

#authorizeObject

Loads credentials and authorizes an client.

Returns:

  • (Object)

    Signet::OAuth2::Client or NIL



62
63
64
65
66
67
68
69
70
71
# File 'lib/google/api_client/auth/storage.rb', line 62

def authorize
  @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.refresh_authorization if @authorization.expired?
  end
  return @authorization
end

#refresh_authorizationObject

refresh credentials and save them to store



75
76
77
78
# File 'lib/google/api_client/auth/storage.rb', line 75

def refresh_authorization
  authorization.refresh!
  self.write_credentials
end

#write_credentials(authorization = nil) ⇒ Object

Write the credentials to the specified store.

Parameters:

  • authorization (Signet::OAuth2::Client) (defaults to: nil)

    Optional authorization instance. If not provided, the authorization already associated with this instance will be written.



52
53
54
55
56
57
# File 'lib/google/api_client/auth/storage.rb', line 52

def write_credentials(authorization=nil)
  @authorization = authorization if authorization
  if @authorization.respond_to?(:refresh_token) && @authorization.refresh_token
    store.write_credentials(credentials_hash)
  end
end