Convert Figma logo to code with AI

doorkeeper-gem logodoorkeeper

Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.

5,402
1,077
5,402
54

Top Related Projects

OmniAuth is a flexible authentication system utilizing Rack middleware.

24,195

Flexible authentication solution for Rails with Warden.

2,127

A Ruby wrapper for OAuth 2.0 protocol, including OIDC

A simple ruby authentication solution.

Quick Overview

Doorkeeper is a powerful OAuth 2 provider for Ruby on Rails applications. It allows you to implement an OAuth 2 server in your Rails app, providing a flexible and secure way to authenticate and authorize third-party applications.

Pros

  • Easy integration with Rails applications
  • Supports various OAuth 2 grant types (authorization code, client credentials, etc.)
  • Highly customizable and extensible
  • Active community and regular updates

Cons

  • Primarily focused on Rails, limiting its use in other Ruby frameworks
  • Can be complex to set up for beginners
  • Documentation can be overwhelming for newcomers

Code Examples

  1. Basic configuration:
Doorkeeper.configure do
  orm :active_record
  access_token_expires_in 2.hours
  use_refresh_token
end

This code sets up Doorkeeper with Active Record as the ORM, sets access token expiration to 2 hours, and enables refresh tokens.

  1. Protecting a resource with Doorkeeper:
class Api::V1::ResourceController < ApplicationController
  before_action :doorkeeper_authorize!

  def index
    render json: { message: "This is a protected resource" }
  end
end

This example shows how to protect an API endpoint using Doorkeeper's authentication.

  1. Customizing token generation:
Doorkeeper::OAuth::Token.module_eval do
  def generate_token
    SecureRandom.hex(32)
  end
end

This code overrides the default token generation method to use a custom implementation.

Getting Started

  1. Add Doorkeeper to your Gemfile:
gem 'doorkeeper'
  1. Run the installation generator:
rails generate doorkeeper:install
  1. Run the migration:
rails db:migrate
  1. Configure Doorkeeper in config/initializers/doorkeeper.rb:
Doorkeeper.configure do
  orm :active_record
  access_token_expires_in 2.hours
  use_refresh_token

  resource_owner_authenticator do
    current_user || redirect_to(new_user_session_url)
  end
end

This sets up a basic Doorkeeper configuration with Active Record, 2-hour token expiration, refresh tokens, and a simple resource owner authenticator.

Competitor Comparisons

OmniAuth is a flexible authentication system utilizing Rack middleware.

Pros of OmniAuth

  • Supports multiple authentication providers (e.g., Facebook, Google, Twitter)
  • Flexible and extensible with a wide range of strategies
  • Easy integration with existing user systems

Cons of OmniAuth

  • Primarily focused on authentication, not authorization
  • Requires additional setup for each provider
  • May need extra security measures for sensitive applications

Code Comparison

OmniAuth configuration:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']
  provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET']
end

Doorkeeper configuration:

Doorkeeper.configure do
  orm :active_record
  resource_owner_authenticator { User.find_by_id(session[:user_id]) || redirect_to(login_url) }
  access_token_expires_in 2.hours
end

Key Differences

  • OmniAuth focuses on multi-provider authentication, while Doorkeeper is an OAuth 2.0 provider for API authorization
  • OmniAuth is more suitable for social login integration, whereas Doorkeeper is better for building OAuth-protected APIs
  • OmniAuth requires less initial setup for basic authentication, while Doorkeeper offers more control over token management and scopes

Use Cases

  • Choose OmniAuth for applications requiring login via multiple social media platforms
  • Opt for Doorkeeper when building an API that needs OAuth 2.0 authorization
24,195

Flexible authentication solution for Rails with Warden.

Pros of Devise

  • More comprehensive authentication solution, including user registration, password recovery, and session management
  • Highly customizable with a wide range of configuration options
  • Large and active community, resulting in extensive documentation and support

Cons of Devise

  • Can be overkill for simple authentication needs
  • Deeper integration with Rails can make it less flexible for non-Rails projects
  • Steeper learning curve due to its extensive feature set

Code Comparison

Devise (User model setup):

class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
end

Doorkeeper (OAuth provider setup):

Doorkeeper.configure do
  orm :active_record
  resource_owner_authenticator do
    current_user || warden.authenticate!(scope: :user)
  end
end

Devise focuses on full-featured authentication for users, while Doorkeeper specializes in OAuth 2.0 provider functionality. Devise is more suitable for traditional web applications with user accounts, while Doorkeeper is ideal for API-centric applications requiring OAuth-based authorization.

Devise offers a more opinionated and Rails-centric approach, whereas Doorkeeper provides flexibility for various authentication strategies and is not limited to Rails applications. The choice between the two depends on the specific requirements of your project, such as the need for OAuth support or a comprehensive user authentication system.

2,127

A Ruby wrapper for OAuth 2.0 protocol, including OIDC

Pros of OAuth2

  • Lightweight and focused solely on OAuth 2.0 implementation
  • More flexible for custom OAuth 2.0 integrations
  • Easier to integrate with third-party OAuth providers

Cons of OAuth2

  • Requires more manual setup for server-side OAuth implementation
  • Less comprehensive documentation compared to Doorkeeper
  • Fewer built-in features for managing OAuth applications

Code Comparison

OAuth2 client usage:

client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://example.com')
token = client.client_credentials.get_token
response = token.get('/api/resource')

Doorkeeper client usage:

client = OAuth2::Client.new('client_id', 'client_secret', site: 'https://example.com')
token = client.client_credentials.get_token
response = token.get('/api/resource')

The client usage is similar for both libraries, as they both implement the OAuth 2.0 standard. However, Doorkeeper provides additional server-side functionality for implementing an OAuth 2.0 provider, which is not shown in this comparison.

Doorkeeper offers a more comprehensive solution for implementing OAuth 2.0 in Ruby on Rails applications, including both client and server-side functionality. It provides generators, database migrations, and a pre-built admin interface for managing OAuth applications.

OAuth2, on the other hand, is more focused on the client-side implementation and offers greater flexibility for custom OAuth 2.0 integrations. It's particularly useful when working with various third-party OAuth providers or implementing custom OAuth flows.

A simple ruby authentication solution.

Pros of Authlogic

  • Simpler setup and configuration for basic authentication needs
  • Lightweight and less resource-intensive
  • More flexible for customizing authentication logic

Cons of Authlogic

  • Less actively maintained (last release in 2021)
  • Lacks built-in support for OAuth2 and token-based authentication
  • May require more manual implementation for advanced features

Code Comparison

Authlogic (User model configuration):

class User < ApplicationRecord
  acts_as_authentic do |c|
    c.crypto_provider = Authlogic::CryptoProviders::BCrypt
  end
end

Doorkeeper (OAuth2 provider setup):

Doorkeeper.configure do
  orm :active_record
  access_token_expires_in 2.hours
  use_refresh_token
end

Key Differences

  • Doorkeeper is specifically designed for OAuth2 and API authentication, while Authlogic focuses on traditional session-based authentication
  • Doorkeeper provides more robust features for API security and access token management
  • Authlogic is better suited for simpler, monolithic applications, whereas Doorkeeper excels in API-centric and service-oriented architectures

Use Cases

  • Choose Authlogic for basic authentication in traditional web applications with simpler requirements
  • Opt for Doorkeeper when building APIs, implementing OAuth2, or requiring token-based authentication for mobile or single-page applications

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Doorkeeper — awesome OAuth 2 provider for your Rails / Grape app.

Gem Version CI Code Climate Coverage Status Reviewed by Hound GuardRails badge Dependabot

Doorkeeper is a gem (Rails engine) that makes it easy to introduce OAuth 2 provider functionality to your Ruby on Rails or Grape application.

Supported features:

Table of Contents

Documentation

This documentation is valid for main branch. Please check the documentation for the version of doorkeeper you are using in: https://github.com/doorkeeper-gem/doorkeeper/releases.

Additionally, other resources can be found on:

Installation

Installation depends on the framework you're using. The first step is to add the following to your Gemfile:

gem 'doorkeeper'

And run bundle install. After this, check out the guide related to the framework you're using.

Ruby on Rails

Doorkeeper currently supports Ruby on Rails >= 5.0. See the guide here.

Grape

Guide for integration with Grape framework can be found here.

ORMs

Doorkeeper supports Active Record by default, but can be configured to work with the following ORMs:

ORMSupport via
Active Recordby default
MongoDBdoorkeeper-gem/doorkeeper-mongodb
Sequelnbulaj/doorkeeper-sequel
Couchbaseacaprojects/doorkeeper-couchbase
RethinkDBaca-labs/doorkeeper-rethinkdb

Extensions

Extensions that are not included by default and can be installed separately.

Link
OpenID Connect extensiondoorkeeper-gem/doorkeeper-openid_connect
JWT Token supportdoorkeeper-gem/doorkeeper-jwt
Assertion grant extensiondoorkeeper-gem/doorkeeper-grants_assertion
I18n translationsdoorkeeper-gem/doorkeeper-i18n
CIBA - Client Initiated Backchannel Authentication Flow extensiondoorkeeper-ciba
Device Authorization Grantdoorkeeper-device_authorization_grant

Example Applications

These applications show how Doorkeeper works and how to integrate with it. Start with the oAuth2 server and use the clients to connect with the server.

ApplicationLink
OAuth2 Server with Doorkeeperdoorkeeper-gem/doorkeeper-provider-app
Sinatra Client connected to Provider Appdoorkeeper-gem/doorkeeper-sinatra-client
Devise + Omniauth Clientdoorkeeper-gem/doorkeeper-devise-client

You may want to create a client application to test the integration. Check out these client examples in our wiki or follow this tutorial here.

Sponsors

OpenCollective OpenCollective

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

Codecademy supports open source as part of its mission to democratize tech. Come help us build the education the world deserves: https://codecademy.com/about/careers


If you prefer not to deal with the gory details of OAuth 2, need dedicated customer support & consulting, try the cloud-based SaaS version: https://oauth.io


Wealthsimple is a financial company on a mission to help everyone achieve financial freedom by providing products and advice that are accessible and affordable. Using smart technology, Wealthsimple takes financial services that are often confusing, opaque and expensive and makes them simple, transparent, and low-cost. See what Investing on Autopilot is all about: https://www.wealthsimple.com

Development

To run the local engine server:

bundle install
bundle exec rake doorkeeper:server

By default, it uses the latest Rails version with ActiveRecord. To run the tests with a specific Rails version:

BUNDLE_GEMFILE=gemfiles/rails_6_0.gemfile bundle exec rake

You can also experiment with the changes using bin/console. It uses in-memory SQLite database and default Doorkeeper config, but you can reestablish connection or reconfigure the gem if you need.

Contributing

Want to contribute and don't know where to start? Check out features we're missing, create example apps, integrate the gem with your app and let us know!

Also, check out our contributing guidelines page.

Contributors

Thanks to all our awesome contributors!

License

MIT License. Created in Applicake. Maintained by the community.