Sha256: 99cd1de314c5162ba756181e8584f1e7e634cd14887b78971cba43e19f6d594e

Contents?: true

Size: 901 Bytes

Versions: 1

Compression:

Stored size: 901 Bytes

Contents

require 'signpost/verifier'

module SignPost
  module Rails
    module Authentication # :nodoc:
      attr_accessor :signpost_users
      class << self
        attr_accessor :fetch_method
      end

      def authenticate_signpost
        session[:user_id] = Signpost::Verifier.verify_action_dispatch_request(
          request,
          authorized_keys
        )
      rescue Signpost::Verifier::VerificationError => e
        ::Rails.logger.warn "Auth failure: #{e}"
        head :unauthorized
        return
      end

      def authorized_keys
        # If cached for less than 5 mins, then return the cache
        return signpost_users[:authorized_keys] if signpost_users && (Time.now - signpost_users[:cached_at]) < 5 * 60
        keys = SignPost::Rails::Authentication.fetch_method.call
        self.signpost_users = { cached_at: Time.now, authorized_keys: keys }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
signpost-rails-0.1.4 lib/signpost/rails/authentication.rb