Sha256: 147e7f30a1851ff96f6d5be68c8cdc9871c8df6e5b71133cae588de9a347ed51
Contents?: true
Size: 1.32 KB
Versions: 69
Compression:
Stored size: 1.32 KB
Contents
module SparkApi module Authentication module OAuth2Impl # 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 class GrantTypePassword < GrantTypeBase def initialize(client, provider, session) super(client, provider, session) end def authenticate new_session = nil if needs_refreshing? new_session = refresh end return new_session unless new_session.nil? create_session(token_params) end 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 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 end end end end
Version data entries
69 entries across 69 versions & 1 rubygems