class Openlive::OAuth

Attributes

current_token[RW]

@return [OAuth2::AccessToken] Used to store the existing token

Public Instance Methods

client() click to toggle source

Return or instantiate the OAuth client

@return [OAuth2::Client]

# 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_token() click to toggle source

Fetch a new token from the OAuth server

@return [OAuth2::AccessToken]

# 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
token() click to toggle source

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

@return [OAuth2::AccessToken]

# File lib/openlive/oauth.rb, line 30
def token
  if current_token.nil? || current_token.expired?
    requisition_token
  else
    current_token
  end
end