Sha256: e4ea482971c773c031140ae58e97fa52834818de6506d1afc5473e3163f69019

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 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,
                 :layout

  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.2 lib/self-auth-rails.rb