Doorkeeper Documentation

repository·main·Indexed 26 days ago

https://github.com/doorkeeper-gem/doorkeeper

An OAuth 2 provider gem for Ruby on Rails (>= 5.0) and Grape applications. It implements the OAuth 2.0 framework, including support for various grant types, token revocation, and introspection. Doorkeeper supports Active Record by default, with adapter gems available for MongoDB, Sequel, Couchbase, and RethinkDB. It offers extensions for OpenID Connect, JWT tokens, assertion grants, CIBA, and Device Authorization Grants.

Tokens
2.2K
Snippets
3
Records
24
Agent score
90%

What's inside Doorkeeper

  1. Install Doorkeeper

    main

    To use Doorkeeper as an OAuth 2 provider, add the gem to your Gemfile and run bundle install.

    Depending on your framework, follow the specific integration guides:

    • Ruby on Rails: Supports Rails >= 5.0.
    • Grape: Requires specific integration steps for the Grape framework.
    gem 'doorkeeper'
  2. Run the Doorkeeper local engine server

    main

    If you are developing with Doorkeeper or want to run the local engine server, use the following commands:

    1. Install dependencies: bundle install
    2. Start the server: bundle exec rake doorkeeper:server
    bundle install
    bundle exec rake doorkeeper:server
  3. Control token introspection permissions

    main

    You can define fine-grained logic to determine if a specific token is allowed to be introspected by configuring allow_token_introspection. This configuration accepts a proc that is called with the token, the auth_client (if using client authentication), and the auth_token (if using bearer token authentication).

    This is useful for restricting introspection to specific clients or ensuring tokens can only be introspected by authorized resource servers.

  4. Customize the Token Introspection response

    main

    You can customize the JSON response returned by the RFC 7662 Token Introspection endpoint by configuring custom_introspection_response in your Doorkeeper configuration. This block receives the token and the server.context (the controller context), allowing you to merge additional metadata into the introspection response.

    If the block returns a blank value, the default response is used.

  5. Customize OAuth 2.0 Authorization Server Metadata

    main

    Doorkeeper implements the OAuth 2.0 Authorization Server Metadata response as described in RFC 8414. You can extend the default metadata response by providing a custom_metadata hash in your Doorkeeper configuration. This is useful for adding fields required by extensions like OpenID Connect (e.g., userinfo_endpoint).

    Note that the userinfo_endpoint is intentionally returned as null by default to maintain backwards compatibility and should be populated via custom_metadata.

  6. Available Doorkeeper Extensions

    main

    The following features can be added to Doorkeeper via separate gems:

    • OpenID Connect extension: doorkeeper-gem/doorkeeper-openid_connect
    • JWT Token support: doorkeeper-gem/doorkeeper-jwt
    • Assertion grant extension: doorkeeper-gem/doorkeeper-grants_assertion
    • I18n translations: doorkeeper-gem/doorkeeper-i18n
    • CIBA (Client Initiated Backchannel Authentication Flow): doorkeeper-ciba
    • Device Authorization Grant: doorkeeper-device_authorization_grant
  7. Supported ORMs for Doorkeeper

    main

    Doorkeeper supports Active Record by default. For other databases, you must use specific adapter gems:

    ORMSupport via
    Active Recordby default
    MongoDBdoorkeeper-gem/doorkeeper-mongodb
    Sequelnbulaj/doorkeeper-sequel
    Couchbaseacaprojects/doorkeeper-couchbase
    RethinkDBaca-labs/doorkeeper-rethinkdb
  8. Initialize the Doorkeeper::Server

    main
    The Doorkeeper::Server class is the core OAuth 2.0 server implementation used to handle incoming requests. It requires a context object during initialization. This context is expected to respond to methods like request and current_resource_owner (or resource_owner_from_credentials).