Class: OmniAuth::Strategies::Cartodb

Inherits:
OAuth
  • Object
show all
Defined in:
lib/cartoset/auth/omniauth_cartodb_authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, site, app_id, app_secret, options = {}) ⇒ Cartodb

Returns a new instance of Cartodb.



7
8
9
10
11
12
13
14
# File 'lib/cartoset/auth/omniauth_cartodb_authentication.rb', line 7

def initialize(app, site, app_id, app_secret, options = {})
  @cartodb_options = options
  @cartodb_options[:site] = site
  @cartodb_options[:authorize_path] = '/oauth/authorize'
  @cartodb_options[:access_token_path] = '/oauth/access_token'
  @cartodb_options[:callback_url] = '/auth/oauth/callback'
  super(app, :cartodb, app_id, app_secret, @cartodb_options)
end

Instance Attribute Details

#cartodb_optionsObject

Returns the value of attribute cartodb_options.



15
16
17
# File 'lib/cartoset/auth/omniauth_cartodb_authentication.rb', line 15

def cartodb_options
  @cartodb_options
end

Instance Method Details

#auth_hashObject



31
32
33
34
35
36
37
38
39
# File 'lib/cartoset/auth/omniauth_cartodb_authentication.rb', line 31

def auth_hash
  OmniAuth::Utils.deep_merge(super, {
    'uid'          => user_data['uid'],
    'username'     => user_data['username'],
    'email'        => user_data['email'],
    'oauth_key'    => user_data['oauth_key'],
    'oauth_secret' => user_data['oauth_secret']
  })
end

#consumerObject



17
18
19
20
21
22
23
24
25
# File 'lib/cartoset/auth/omniauth_cartodb_authentication.rb', line 17

def consumer
  if CartoDB::Settings.present?
    if @consumer.nil? || @consumer.key != CartoDB::Settings['oauth_key'] || @consumer.secret != CartoDB::Settings['oauth_secret']
      @cartodb_options[:site] = CartoDB::Settings['host']
      @consumer = ::OAuth::Consumer.new(CartoDB::Settings['oauth_key'], CartoDB::Settings['oauth_secret'], @cartodb_options)
    end
  end
  super
end

#user_dataObject



27
28
29
# File 'lib/cartoset/auth/omniauth_cartodb_authentication.rb', line 27

def user_data
  @user_data ||= MultiJson.decode(@access_token.get('/oauth/identity', { 'Accept'=>'application/json' }).body)
end