Class: OmniAuth::Strategies::MapsMeToken

Inherits:
Object
  • Object
show all
Includes:
MapsMeBase, OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/mapsme-token.rb

Constant Summary

Constants included from MapsMeBase

OmniAuth::Strategies::MapsMeBase::MAPSME_BASE, OmniAuth::Strategies::MapsMeBase::MAPSME_CLIENT_OPTIONS, OmniAuth::Strategies::MapsMeBase::MAPSME_DEFAULT_SCOPE, OmniAuth::Strategies::MapsMeBase::MAPSME_USER_DETAILS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MapsMeBase

#extract_name

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



25
26
27
# File 'lib/omniauth/strategies/mapsme-token.rb', line 25

def access_token
  @access_token
end

Instance Method Details

#authorize_paramsObject



48
49
50
51
52
# File 'lib/omniauth/strategies/mapsme-token.rb', line 48

def authorize_params
  super.tap do |params|
    params[:scope] = MAPSME_DEFAULT_SCOPE
  end
end

#callback_phaseObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/omniauth/strategies/mapsme-token.rb', line 73

def callback_phase
  if !request.params['access_token'] || request.params['access_token'].to_s.empty?
    raise ArgumentError.new("No access token provided.")
  end

  self.access_token = build_access_token
  self.access_token = self.access_token.refresh! if self.access_token.expired?

  # Instead of calling super, duplicate the functionality, but change the provider to 'mapsme'.
  # So the list of accounts is single for both strategies.
  hash = auth_hash
  hash[:provider] = "mapsme"
  self.env['omniauth.auth'] = hash
  call_app!

 rescue ::OAuth2::Error => e
   fail!(:invalid_credentials, e)
 rescue ::MultiJson::DecodeError => e
   fail!(:invalid_response, e)
 rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
   fail!(:timeout, e)
 rescue ::SocketError => e
   fail!(:failed_to_connect, e)
end

#clientObject



62
63
64
# File 'lib/omniauth/strategies/mapsme-token.rb', line 62

def client
  ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
end

#info_optionsObject



58
59
60
# File 'lib/omniauth/strategies/mapsme-token.rb', line 58

def info_options
  options[:info_fields] ? {:params => {:fields => options[:info_fields]}} : {}
end

#mock_callback_callObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/omniauth/strategies/mapsme-token.rb', line 98

def mock_callback_call
  # Copying the parent implementation just so we can replace the provider name
  setup_phase
  @env['omniauth.origin'] = session.delete('omniauth.origin')
  @env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
  mocked_auth = OmniAuth.mock_auth_for(:mapsme)
  if mocked_auth.is_a?(Symbol)
    fail!(mocked_auth)
  else
    @env['omniauth.auth'] = mocked_auth
    @env['omniauth.params'] = session.delete('omniauth.params') || {}
    OmniAuth.config.before_callback_phase.call(@env) if OmniAuth.config.before_callback_phase
    call_app!
  end
end

#raw_infoObject



54
55
56
# File 'lib/omniauth/strategies/mapsme-token.rb', line 54

def raw_info
  @raw_info ||= access_token.get(MAPSME_USER_DETAILS).parsed || {}
end

#request_phaseObject



66
67
68
69
70
71
# File 'lib/omniauth/strategies/mapsme-token.rb', line 66

def request_phase
  form = OmniAuth::Form.new(:title => "User Token", :url => callback_path)
  form.text_field "Access Token", "access_token"
  form.button "Sign In"
  form.to_response
end