Sha256: dd90ff551dafa70d1a2871312e5853ec94205df4cd137c712e84ca7e9f5dd1ca

Contents?: true

Size: 572 Bytes

Versions: 5

Compression:

Stored size: 572 Bytes

Contents

module PushType
  module ApiAuthenticationMethods
    extend ActiveSupport::Concern

    included do
      before_action :authenticate_user!
    end

    protected

    def authenticate_user!
      unless current_push_type_user
        head(:unauthorized)
      end
    end

    def current_push_type_user
      @current_push_type_user ||= begin
        Knock::AuthToken.new(token: auth_token).entity_for(PushType::User)
      rescue
        nil
      end
    end

    def auth_token
      params[:token] || request.headers['Authorization']&.split&.last
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
push_type_auth-0.10.2 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.1 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.0 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.0.beta.5 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.0.beta.3 app/controllers/concerns/push_type/api_authentication_methods.rb