Sha256: cf763abab0b3b5e33da35e65fa08dedb04dd57bca83346ebb9af0d23242d9f28

Contents?: true

Size: 582 Bytes

Versions: 9

Compression:

Stored size: 582 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'].try(:split).try(:last)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
push_type_auth-0.12.1 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.12.0 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.12.0.beta.1 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.11.2 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.11.1 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.11.0.beta.2 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.11.0.beta.1 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.4 app/controllers/concerns/push_type/api_authentication_methods.rb
push_type_auth-0.10.3 app/controllers/concerns/push_type/api_authentication_methods.rb