Class: Openlive::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/openlive/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_tokenOAuth2::AccessToken

Returns Used to store the existing token.

Returns:

  • (OAuth2::AccessToken)

    Used to store the existing token



7
8
9
# File 'lib/openlive/oauth.rb', line 7

def current_token
  @current_token
end

Instance Method Details

#clientOAuth2::Client

Return or instantiate the OAuth client

Returns:

  • (OAuth2::Client)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/openlive/oauth.rb', line 13

def client
  @client ||= (
    credentials = Openlive.configuration.oauth_credentials

    OAuth2::Client.new(
      credentials[:client_id],
      credentials[:client_secret],
      Openlive.configuration.oauth_settings
    )
  )
end

#requisition_tokenOAuth2::AccessToken

Fetch a new token from the OAuth server

Returns:

  • (OAuth2::AccessToken)


42
43
44
# File 'lib/openlive/oauth.rb', line 42

def requisition_token
  self.current_token = client.client_credentials.get_token(scope: Openlive.configuration.oauth_settings[:scope])
end

#tokenOAuth2::AccessToken

Return an existing unexpired token for this OAuth instance or requisition a new one from the server.

Returns:

  • (OAuth2::AccessToken)


30
31
32
33
34
35
36
# File 'lib/openlive/oauth.rb', line 30

def token
  if current_token.nil? || current_token.expired?
    requisition_token
  else
    current_token
  end
end