How doorkeeper-gem/doorkeeper works
Main Components
• Views and Presentation: The app/views/doorkeeper directory contains view templates that support the user interface aspects (e.g., forms for authorizing client applications).
• Core OAuth Logic: The lib/doorkeeper directory is packed with modules and classes that contain the domain logic, such as OAuth flows, token generation, client credentials, and error handling. Subdirectories like lib/doorkeeper/oauth, lib/doorkeeper/orm, and lib/doorkeeper/grant_flow help modularize the core functionality.
• Active Record Integration: The ORM integration is visible in lib/doorkeeper/orm/active_record, which handles persistence and interaction with the database.
• Configuration and Setup: The gemspec and various generators in lib/generators/doorkeeper show how the engine can be installed and configured in a host application.
Relationships and Interactions
• Clients (external applications) interact with the OAuth endpoints (controllers) via HTTP.
• The controllers call into the business logic (in the lib/doorkeeper modules) to handle various flows like the Authorization Code Flow, Client Credentials, Resource Owner Password, etc.
• The ORM layer is used to persist data such as access tokens, authorization codes, and application data.
• There is a clear interaction between configuration (lib/doorkeeper/config) and how the OAuth flows are executed.
• Additional support files (e.g., in bin, config, and spec directories) indicate testing infrastructure and server bootstrapping for development or testing purposes.
Architectural Patterns & Design Principles
• Modular Design: Core OAuth functionalities are broken down into loosely coupled modules (see the directories for oauth, grant_flow, and generators).
• Rails Engine Integration: The project works as a Rails engine (packaged in lib/doorkeeper/engine.rb) so that it hooks into an existing Rails or Grape app.
• Extensibility: The design encourages extensions—for example, separate gems exist for OpenID Connect, JWT support, and additional grant flows, indicating an architecture that supports plug-in extensions.
• Separation of Concerns: There is a distinct separation between controllers, views, models, and the underlying business logic.
Relevant Technologies, Frameworks, and Libraries
• Ruby on Rails & Grape: The engine is built for Rails and optionally integrates with Grape.
• Active Record: Default ORM for persistence.
• Testing frameworks (RSpec and related specs under spec/) for ensuring correctness.
Elements
• “Core OAuth Logic” (lib/doorkeeper modules such as oauth flows and grant flows)
• “ORM / Persistence Layer” (ActiveRecord models under lib/doorkeeper/orm)
• “UI / Views” (templates under app/views/doorkeeper)
• “Configuration & Initialization” (engine and generators)