Sha256: 106c40af695813e2debca68a40d3ba5fbf0d932bcdb2934b5c97f2e96ba0323f

Contents?: true

Size: 592 Bytes

Versions: 3

Compression:

Stored size: 592 Bytes

Contents

module Radriar
  module API
    module Authentication
      def warden
        env['warden']
      end

      def authenticated?
        warden.authenticated? || !!find_user
      end

      def authenticate!
        if authenticated?
          current_user.tap { |u| u.try(:seen!)}
        else
          error!("401 Unauthorized", 401)
        end
      end

      def current_user
        warden.user || find_user
      end

      def find_user
        token = params[:access_token] || headers['Authorization']
        User.find_for_token_authentication(token)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
radriar-0.1.0.alpha.3 lib/radriar/api/authentication.rb
radriar-0.1.0.alpha.2 lib/radriar/api/authentication.rb
radriar-0.1.0.alpha.1 lib/radriar/api/authentication.rb