Class: OmniAuth::Strategies::Cadun
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Cadun
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omni_auth/strategies/cadun.rb
Class Method Summary collapse
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
- #callback_url ⇒ Object
- #client_ip ⇒ Object
-
#initialize(app, options = {}) ⇒ Cadun
constructor
A new instance of Cadun.
- #request_phase ⇒ Object
- #service_id ⇒ Object
- #user ⇒ Object
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, = {}) ::Cadun::Config.load_file([:config]) super(app, :cadun, ) 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_hash ⇒ Object
28 29 30 |
# File 'lib/omni_auth/strategies/cadun.rb', line 28 def auth_hash self.class.build_auth_hash(user, request) end |
#callback_phase ⇒ Object
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_url ⇒ Object
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_ip ⇒ Object
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_phase ⇒ Object
16 17 18 |
# File 'lib/omni_auth/strategies/cadun.rb', line 16 def request_phase redirect "#{::Cadun::Config.login_url}/#{service_id}?url=#{callback_url}" end |
#service_id ⇒ Object
36 37 38 |
# File 'lib/omni_auth/strategies/cadun.rb', line 36 def service_id @options[:service_id] end |
#user ⇒ Object
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 |