Sha256: 385cbad8a49d4a24e6668e0eec25f49f2e4d2854379e3ccc67447796b8d73cad

Contents?: true

Size: 995 Bytes

Versions: 2

Compression:

Stored size: 995 Bytes

Contents

module Sso
  module Warden
    module Hooks
      class CreateMasterSession
        include ::Sso::Warden::Support

        def call
          if logged_in?
            debug { "Starting hook because this is considered the first login of the current session..." }
            debug { "Log out previous Sso:Session if exists : ID session['sso_session_id']" }
            ::Sso::Session.logout(session["sso_session_id"])
            generate_session
          end
          return nil
        end

        def generate_session
          debug { "Generating a Sso:Session for user #{user.id.inspect} for the session cookie at the Sso server..." }
          attributes = {  ip: request.ip, agent: request.user_agent }

          sso_session = Sso::Session.generate_master(user, attributes)
          debug { "Sso:Session with ID #{sso_session.id} generated successfuly. Persisting it in session..." }
          session["sso_session_id"] = sso_session.id.to_s
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper_sso-0.4.1 lib/sso/warden/hooks/create_master_session.rb
doorkeeper_sso-0.4.0 lib/sso/warden/hooks/create_master_session.rb