Class: OmniAuth::Strategies::GloboCom

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ GloboCom

Returns a new instance of GloboCom.



13
14
15
16
17
18
# File 'lib/omni_auth/strategies/globocom.rb', line 13

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

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/omni_auth/strategies/globocom.rb', line 11

def logger
  @logger
end

Instance Method Details

#auth_hashObject



34
35
36
37
38
39
# File 'lib/omni_auth/strategies/globocom.rb', line 34

def auth_hash
  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

#callback_phaseObject



24
25
26
27
28
29
30
31
32
# File 'lib/omni_auth/strategies/globocom.rb', line 24

def callback_phase
  begin
    super
  rescue Exception => e
    logger.error(log_exception(e)) if logger
    
    fail!(e.message, e.message)
  end
end

#callback_urlObject



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

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/#{name}/callback"
  URI.escape(callback_url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end

#client_ipObject



58
59
60
61
62
63
64
# File 'lib/omni_auth/strategies/globocom.rb', line 58

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

#log_envObject



66
67
68
# File 'lib/omni_auth/strategies/globocom.rb', line 66

def log_env
  "#{Time.now.strftime("%d/%m/%Y %H:%M")} - SERVER_NAME: #{request.env['SERVER_NAME']} | PATH_INFO: #{request.env['PATH_INFO']} | QUERY_STRING: #{request.env['QUERY_STRING']}"
end

#log_exception(exception) ⇒ Object



70
71
72
# File 'lib/omni_auth/strategies/globocom.rb', line 70

def log_exception(exception)
  "#{log_env} | EXCEPTION: #{exception}"
end

#request_phaseObject



20
21
22
# File 'lib/omni_auth/strategies/globocom.rb', line 20

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

#service_idObject



45
46
47
# File 'lib/omni_auth/strategies/globocom.rb', line 45

def service_id
  @options[:service_id]
end

#userObject



41
42
43
# File 'lib/omni_auth/strategies/globocom.rb', line 41

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