Sha256: 1a08de79d12013268edaff08afbc4895c63629d79f9ead5cb41df1ff640b080f

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require "self-auth-rails/version"
require "self-auth-rails/engine"

module SelfAuthRails
  mattr_accessor :self_client,
                 :session_class_name,
                 :auth_facts,
                 :fact_mapping,
                 :authenticated_path,
                 :authenticated_path

  class Engine < ::Rails::Engine
    default_auth_facts = [:display_name]
    default_authenticated_path = '/'

    config.after_initialize do
      unless SelfAuthRails::self_client.nil?
        SelfAuthRails.auth_facts ||= default_auth_facts
        SelfAuthRails.authenticated_path ||= default_authenticated_path

        response_manager = SelfAuthResponseManagerService.new(ActionCable.server)

        # Subscribe to fact responses
        SelfAuthRails::self_client.facts.subscribe do |auth|
          response_manager.process_response(auth)
        end

        # Subscribe to authentication responses
        SelfAuthRails::self_client.authentication.subscribe do |auth|
          response_manager.process_response(auth)
        end
      end
    end
  end

  def self.session_class
    class_name = session_class_name || 'User'
    Object.const_get(class_name)
  end

  # this function maps the vars from your app into your engine
  def self.setup(&block)
    yield self
  end

  def authenticated_path
    SelfAuthRails::authenticated_path || SelfAuthRails::default_authenticated_path
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
self-auth-rails-0.1.1 lib/self-auth-rails.rb