Sha256: 1e37b276a45ff34a1acd8e7b629bdb2f34350c610034460c09d9ab15fd79c922

Contents?: true

Size: 758 Bytes

Versions: 12

Compression:

Stored size: 758 Bytes

Contents

#
# From https://gist.github.com/josevalim/fb706b1e933ef01e4fb6
#
module Renalware
  module API
    class TokenAuthenticatedApiController < ApplicationController
      before_action :authenticate_user_from_token!
      before_action :authenticate_user! # fallback

      private

      def authenticate_user_from_token!
        username = params[:username].presence
        user = username && User.find_by(username: username)

        # Notice how we use Devise.secure_compare to compare the token
        # in the database with the token given in the params, mitigating
        # timing attacks.
        if user && Devise.secure_compare(user.authentication_token, params[:token])
          sign_in user, store: false
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
renalware-core-2.0.11 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.9 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.8 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.7 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.5 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.4 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.3 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.2 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.1 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.0 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/api/token_authenticated_api_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/api/token_authenticated_api_controller.rb