The JWT Auth engine provides a way to do simple JSON Web Token authentication in your Rails application.
How to use my plugin.
Add this line to your application's Gemfile:
gem 'jwt_auth', git: 'https://github.com/performant-software/jwt-auth.git', tag: 'v0.1.0'And then execute:
$ bundle installOr install it yourself as:
$ gem install jwt_authIn /config/initializers add a jwt_auth configuration file to define your model and login attribute:
JwtAuth.configure do |config|
config.model_class = 'User'
config.login_attribute = 'email'
endMount the engine in the /config/routes.rb file:
Rails.application.routes.draw do
mount JwtAuth::Engine => '/auth'
# Other routes here...You can now make POST requests to /auth/login with the following payload:
{
"email": "example@example.com",
"password": "password"
}To authenticate each request coming into your application, use the Authenticateable concern in your base controller:
class MyBaseController < ApplicationController
include JwtAuth::Authenticateable
end