class SparkApi::Authentication::OAuth2Impl::GrantTypeCode
OAuth2
authentication flow using username and password parameters for the user in the request. This implementation is geared towards authentication styles for web applications that have a OAuth flow for redirects.
Public Class Methods
new(client, provider, session)
click to toggle source
Calls superclass method
SparkApi::Authentication::OAuth2Impl::GrantTypeBase::new
# File lib/spark_api/authentication/oauth2_impl/grant_type_code.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_code.rb, line 11 def authenticate if(provider.code.nil?) SparkApi.logger.debug { "[oauth2] No authoriztion code present. Redirecting to #{authorization_url}." } provider.redirect(authorization_url) end 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_code.rb, line 23 def refresh() SparkApi.logger.debug { "[oauth2] Refresh oauth session." } refresher = GrantTypeRefresh.new(client,provider,session) refresher.params = {"redirect_uri" => @provider.redirect_uri} refresher.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_code.rb, line 34 def token_params hash = { "client_id" => @provider.client_id, "client_secret" => @provider.client_secret, "code" => @provider.code, "grant_type" => "authorization_code", "redirect_uri" => @provider.redirect_uri } MultiJson.dump(hash) end