Class: OmniAuth::Strategies::GloboCom
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::GloboCom
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omni_auth/strategies/globocom.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #client_ip ⇒ Object
-
#initialize(app, opts = {}) ⇒ GloboCom
constructor
A new instance of GloboCom.
- #log_env ⇒ Object
- #log_exception(exception) ⇒ Object
- #request_phase ⇒ Object
- #service_id ⇒ Object
- #user ⇒ Object
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
#logger ⇒ Object (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_hash ⇒ Object
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_phase ⇒ Object
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., e.) end end |
#callback_url ⇒ Object
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_ip ⇒ Object
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_env ⇒ Object
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_phase ⇒ Object
20 21 22 |
# File 'lib/omni_auth/strategies/globocom.rb', line 20 def request_phase redirect "#{Cadun::Config.login_url}/#{service_id}?url=#{callback_url}" end |
#service_id ⇒ Object
45 46 47 |
# File 'lib/omni_auth/strategies/globocom.rb', line 45 def service_id @options[:service_id] end |
#user ⇒ Object
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 |