JwtHandlerRuby
Short description and motivation.
Usage
How to use my plugin.
Gem has next methods:
decode_user(jwt)
- expects jwt with user and returns decoded payload(in our case user info).
valid_jwt?(jwt)
- expects jwt and checks if it is valid. Return true
when it is valid, otherwise returns false
Gem adds next endpoints to your application:
/logins
which has next methods:
POST
- expects {"jwt": <jwt_signed by UM private key>}. It checks if jwt is valid and if so, then save it to the cookies called 'jwt'.
if jwt is not valid then it delete it from the cookies. When jwt was added to cookies than it will be sent with every request.
Installation
Add this line to your application's Gemfile:
gem 'jwt_handler_ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jwt_handler_ruby
Requirements
To use gem you should provide environment variable with UM public key called 'JWT_PUBLIC_KEY'.
Also, in your routes.rb file you should specify where /login
endpoint will be mount.
Example:
mount JwtHandlerRuby::Engine, at: '/'
in this case gems '/login' endpoint will be mounted at: domain.com/logins
.
If you already have a '/login' endpoint you can isolate it by
mount JwtHandlerRuby::Engine, at: '/some_path'
Then gems /login
endpoint will be mounted on domain.com/some_path/logins
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.