This gem provides JSON Web Token (JWT) based authentication.
Add this line to your application's Gemfile:
gem 'rack-jwt'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rack-jwt
Rack::JWT::Auth
accepts several configuration options:
secret
: required : String : A cryptographically secure String that serves as the HMAC SHA-256 secret for the JSON Web Token.verify
: optional : Boolean : Determines whether JWT will verify tokens when decoded. Default istrue
.options
: optional : Hash : A hash of options that are passed through to JWT to configure supported claims. See the ruby-jwt docs for the available options. By default only expiration (exp) and Not Before (nbf) claims are verified.exclude
: optional : Array : An Array of path strings representing paths that should not check for JWT authentication tokens before allowing access.
use Rack::JWT::Auth, secret: 'you_secret_token_goes_here', verify: true, options: {}, exclude: ['/api/docs']
Cuba.use Rack::JWT::Auth, secret: 'you_secret_token_goes_here', verify: true, options: {}, exclude: ['/api/docs']
Rails.application.config.middleware.use, Rack::JWT::Auth, secret: Rails.application.secrets.secret_key_base, verify: true, options: {}, exclude: ['/api/docs']
You can generate JSON Wen Tokens for your users using the Token#encode
method
Rack::JWT::Token.encode(payload, secret)
- Fork it ( https://github.com/[my-github-username]/rack-jwt/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request