Sha256: 378462a7fa46f77701e71aba38023a20c4961963f28ec8ce91dd760990c9a8d4

Contents?: true

Size: 1.08 KB

Versions: 12

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module NulogySSO

  # A mix-in that is intended to enhance a controller with NulogySSO authentication code.
  # It is recommended to `include NulogySSO::ControllerHelper` in your ApplicationController.
  module ControllerHelper
    extend ActiveSupport::Concern

    included do
      # Makes the commonly used @current_user variable available to controllers and views.
      # This emulates a code pattern popular in Rails apps using Devise.
      attr_reader :current_user
      helper_method :current_user if defined?(helper_method)
      before_action :store_previous_url_in_session
    end

    def authenticate_sso_user
      raw_token = CookieTokenStore.new(request, response).fetch
      return NulogySSO.handle_unauthenticated_request.call(self) if raw_token.blank?

      @current_user = Authenticator.new.authenticated_user(raw_token)
      return NulogySSO.handle_unauthenticated_request.call(self) if @current_user.blank?
    end

    def store_previous_url_in_session
      session[:previous_request_url] = request.url unless current_user
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nulogy_sso-2.6.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.5.1 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.5.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.4.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.3.1 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.3.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.2.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.1.3 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.1.2 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.1.1 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.1.0 lib/nulogy_sso/controller_helper.rb
nulogy_sso-2.0.0 lib/nulogy_sso/controller_helper.rb