Class: OmniAuth::Strategies::Cadun

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Cadun

Returns a new instance of Cadun.



10
11
12
13
14
# File 'lib/omni_auth/strategies/cadun.rb', line 10

def initialize(app, options = {})
  ::Cadun::Config.load_file(options[:config])
  
  super(app, :cadun, options)
end

Class Method Details

.build_auth_hash(user, request = nil) ⇒ Object



57
58
59
60
61
62
# File 'lib/omni_auth/strategies/cadun.rb', line 57

def self.build_auth_hash(user, request = nil)
  hash = { :provider => "cadun", :uid => user.id, :user_info => user.to_hash.merge(:birthday =>  user.birthday.strftime('%d/%m/%Y')) }
  hash[:user_info].merge!(:GLBID => request.params['GLBID'], :url => request.params['url']) if request
  
  hash
end

Instance Method Details

#auth_hashObject



28
29
30
# File 'lib/omni_auth/strategies/cadun.rb', line 28

def auth_hash
  self.class.build_auth_hash(user, request)
end

#callback_phaseObject



20
21
22
23
24
25
26
# File 'lib/omni_auth/strategies/cadun.rb', line 20

def callback_phase
  begin
    super
  rescue => e
    fail!(:invalid_credentials, e)
  end
end

#callback_urlObject



40
41
42
43
44
45
46
47
# File 'lib/omni_auth/strategies/cadun.rb', line 40

def callback_url
  uri = request.env['HTTP_HOST']
  port = request.env['SERVER_PORT'] == "80" ? nil : ":#{request.env['SERVER_PORT']}"
  scheme = request.env['rack.url_scheme']
  
  callback_url = "#{scheme}://#{uri}#{port}/auth/cadun/callback"
  URI.escape(callback_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

#client_ipObject



49
50
51
52
53
54
55
# File 'lib/omni_auth/strategies/cadun.rb', line 49

def client_ip
  if env['HTTP_X_FORWARDED_FOR'] and not env['HTTP_X_FORWARDED_FOR'].empty?
    env['HTTP_X_FORWARDED_FOR'].split(',').last.strip
  else
    env['REMOTE_ADDR']
  end
end

#request_phaseObject



16
17
18
# File 'lib/omni_auth/strategies/cadun.rb', line 16

def request_phase
  redirect "#{::Cadun::Config.}/#{service_id}?url=#{callback_url}"
end

#service_idObject



36
37
38
# File 'lib/omni_auth/strategies/cadun.rb', line 36

def service_id
  @options[:service_id]
end

#userObject



32
33
34
# File 'lib/omni_auth/strategies/cadun.rb', line 32

def user
  @user ||= ::Cadun::User.new(:glb_id => request.params['GLBID'], :ip => client_ip, :service_id => service_id)
end