Sha256: 6452b7ac8064f9d86a40dedeac2550ea8d28edd45cd83ca672ff10154b761db3

Contents?: true

Size: 1.12 KB

Versions: 45

Compression:

Stored size: 1.12 KB

Contents

class ExvoAuth::Strategies::Base < OmniAuth::Strategies::OAuth2
  def initialize(app, name, options = {})
    options[:site]          ||= ExvoAuth::Config.host
    options[:client_id]     ||= ExvoAuth::Config.client_id
    options[:client_secret] ||= ExvoAuth::Config.client_secret
    
    if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil?
      raise(ArgumentError, "Please configure host, client_id and client_secret")
    end
    
    super(app, name, options.delete(:client_id), options.delete(:client_secret), options)
  end
  
  def user_data
    @data ||= MultiJson.decode(@access_token.get('/user.json'))
  end

  def user_info
    {
      'nickname' => user_data['nickname'],
      'email'    => user_data['email']
    }.reject{ |k, v| v.nil? }
  end

  def auth_hash
    OmniAuth::Utils.deep_merge(super, {
      'provider'  => 'exvo',
      'uid'       => user_data['id'],
      'user_info' => user_info,
      'extra'     => { 'user_hash' => user_data }
    })
  end
  
  protected
  
  # Have a better name? Let me know!
  def unicorns_and_rainbows(hash)
    hash.reject{|k, v| v.nil?}
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
exvo-auth-0.12.2 lib/exvo_auth/strategies/base.rb
exvo-auth-0.12.1 lib/exvo_auth/strategies/base.rb
exvo-auth-0.12.0 lib/exvo_auth/strategies/base.rb
exvo-auth-0.11.2 lib/exvo_auth/strategies/base.rb
exvo-auth-0.11.1 lib/exvo_auth/strategies/base.rb
exvo-auth-0.11.0 lib/exvo_auth/strategies/base.rb
exvo-auth-0.10.4 lib/exvo_auth/strategies/base.rb
exvo-auth-0.10.3 lib/exvo_auth/strategies/base.rb
exvo-auth-0.10.2 lib/exvo_auth/strategies/base.rb
exvo-auth-0.10.1 lib/exvo_auth/strategies/base.rb
exvo-auth-0.10.0 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.10 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.9 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.8 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.7 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.6 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.5 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.4 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.3 lib/exvo_auth/strategies/base.rb
exvo-auth-0.9.2 lib/exvo_auth/strategies/base.rb