This guide is relevant for Ruby on Rails with ActiveRecord. It assumes you have a User model using Devise as the authentication framework.
If you want to see how doorkeeper integrates with an existing application, check out the doorkeeper-provider-app repository, which is based on this guide.
Installation
The first step is to add Doorkeeper to your project's dependencies:
1
bundle add doorkeeper
Copied!
After that, you need to generate relevant files with:
1
bundle exec rails generate doorkeeper:install
Copied!
This will introduce three changes:
1.
A new initializer in config/initializers/doorkeeper.rb
Before executing the migration, you may want to add foreign keys to doorkeeper's tables to ensure data integrity. Go to the migration file and uncomment the lines below:
As the next step, you may want to add associations to your model. If you skip this step, you'll encounter ActiveRecord::InvalidForeignKeyerror when you try to destroy the User that has associated access grants or access tokens.
app/models/user.rb
1
classUser< ApplicationRecord
2
has_many :access_grants,
3
class_name:'Doorkeeper::AccessGrant',
4
foreign_key::resource_owner_id,
5
dependent::delete_all# or :destroy if you need callbacks
6
7
has_many :access_tokens,
8
class_name:'Doorkeeper::AccessToken',
9
foreign_key::resource_owner_id,
10
dependent::delete_all# or :destroy if you need callbacks