Skip to content
JWT Token support for Doorkeeper
Ruby Shell
Branch: master
Clone or download
nbulaj Merge pull request #35 from doorkeeper-gem/dependabot/bundler/rake-tw…

Update rake requirement from ~> 12.3 to ~> 13.0
Latest commit 52aea84 Oct 2, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Update our project Rubocop styles Oct 2, 2019
lib/doorkeeper Update our project Rubocop styles Oct 2, 2019
.rubocop.yml Update our project Rubocop styles Oct 2, 2019
LICENSE.txt initial commit Mar 27, 2015
Rakefile Update our project Rubocop styles Oct 2, 2019

Gem Version Coverage Status Build Status Maintainability


Doorkeeper JWT adds JWT token support to the Doorkeeper OAuth library. Confirmed to work with Doorkeeper 2.2.x - 4.x. Untested with later versions of Doorkeeper.

gem 'doorkeeper'


Add this line to your application's Gemfile:

gem 'doorkeeper-jwt'

And then execute:

$ bundle

Or install it yourself as:

$ gem install doorkeeper-jwt


In your doorkeeper.rb initializer add the follow to the Doorkeeper.configure block:

access_token_generator '::Doorkeeper::JWT'

Then add a Doorkeeper::JWT.configure block below the Doorkeeper.configure block to set your JWT preferences.

Doorkeeper::JWT.configure do
  # Set the payload for the JWT token. This should contain unique information
  # about the user. Defaults to a randomly generated token in a hash:
  #     { token: "RANDOM-TOKEN" }
  token_payload do |opts|
    user = User.find(opts[:resource_owner_id])

      iss: 'My App',
      iat: Time.current.utc.to_i,

      # @see JWT reserved claims -
      jti: SecureRandom.uuid,

      user: {

  # Optionally set additional headers for the JWT. See
  token_headers do |opts|
    { kid: opts[:application][:uid] }

  # Use the application secret specified in the access grant token. Defaults to
  # `false`. If you specify `use_application_secret true`, both `secret_key` and
  # `secret_key_path` will be ignored.
  use_application_secret false

  # Set the encryption secret. This would be shared with any other applications
  # that should be able to read the payload of the token. Defaults to "secret".
  secret_key ENV['JWT_SECRET']

  # If you want to use RS* encoding specify the path to the RSA key to use for
  # signing. If you specify a `secret_key_path` it will be used instead of
  # `secret_key`.
  secret_key_path File.join('path', 'to', 'file.pem')

  # Specify encryption type ( Defaults to
  # `nil`.
  encryption_method :hs512


After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to


  1. Fork it ([my-github-username]/doorkeeper-jwt/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request
You can’t perform that action at this time.