class SparkApi::Authentication::OAuth2Impl::GrantTypePassword

OAuth2 authentication flow using username and password parameters for the user in the request. This implementation is geared towards authentication styles for native applications that need to use OAuth2

Public Class Methods

new(client, provider, session) click to toggle source
# File lib/spark_api/authentication/oauth2_impl/grant_type_password.rb, line 8
def initialize(client, provider, session)
  super(client, provider, session)
end

Public Instance Methods

authenticate() click to toggle source
# File lib/spark_api/authentication/oauth2_impl/grant_type_password.rb, line 11
def authenticate
  new_session = nil
  if needs_refreshing?
    new_session = refresh
  end
  return new_session unless new_session.nil?
  create_session(token_params)
end
refresh() click to toggle source
# File lib/spark_api/authentication/oauth2_impl/grant_type_password.rb, line 20
def refresh()
  GrantTypeRefresh.new(client,provider,session).authenticate
rescue ClientError => e
  SparkApi.logger.info("[oauth2] Refreshing token failed, the library will try and authenticate from scratch: #{e.message}")
  nil
end

Private Instance Methods

token_params() click to toggle source
# File lib/spark_api/authentication/oauth2_impl/grant_type_password.rb, line 28
def token_params
  hash = {
    "client_id" => @provider.client_id,
    "client_secret" => @provider.client_secret,
    "grant_type" => "password",
    "password" => @provider.password,
    "username" => @provider.username
  }
  MultiJson.dump(hash)
end