Class: OmniAuth::Strategies::Linnworks

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/linnworks.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject

rubocop:disable MethodLength



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/omniauth/strategies/linnworks.rb', line 31

def callback_phase # rubocop:disable MethodLength
  @response = Faraday.post('https://api.linnworks.net//api/Auth/AuthorizeByApplication', {"applicationId" => options.application_id, 
                                                                                "applicationSecret" => options.application_secret,
                                                                                "token" => request.params['token']})

  fail!(:error, Exception.new(JSON.parse(@response.body))) unless @response.success?
  super
rescue ::Timeout::Error => e
  fail!(:timeout, e)
rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
  fail!(:service_unavailable, e)
rescue ::OAuth::Unauthorized => e
  fail!(:invalid_credentials, e)
end

#request_phaseObject

rubocop:disable MethodLength



20
21
22
23
24
25
26
27
28
29
# File 'lib/omniauth/strategies/linnworks.rb', line 20

def request_phase # rubocop:disable MethodLength
  authorize_url = "#{options.client_options.site}#{options.client_options.authorize_url}/#{options.application_id}"
  authorize_url += "?tracking=#{options.client_options.tracking}" if options.client_options.tracking

  redirect authorize_url
rescue ::Timeout::Error => e
  fail!(:timeout, e)
rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
  fail!(:service_unavailable, e)
end