Skip to content

Instantly share code, notes, and snippets.

@jordifierro
Last active February 22, 2016 15:51
Show Gist options
  • Save jordifierro/b97c16d4acb6461fac89 to your computer and use it in GitHub Desktop.
Save jordifierro/b97c16d4acb6461fac89 to your computer and use it in GitHub Desktop.
Example of a Rails api authentication module using ActiveSupport::Concern
module Api::V1::Concerns
module Authenticator
extend ActiveSupport::Concern
included do
before_action :auth_with_token!
end
def current_user
@current_user ||= User.find_by(auth_token: request.headers['Authorization'])
end
def user_signed_in?
current_user.present?
end
def auth_with_token!
head :unauthorized unless user_signed_in?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment