ruby
3.2.2node
18.x
# setup the DB
rails db:create
rails db:migrate
# !IMPORTANT! setup .env.development file according to .env.template
# start the server
bin/dev
rails new my-rails-app --database=postgresql --javascript=esbuild --css=bootstrap
https://github.com/heartcombo/devise#getting-started
bundle add devise
rails generate devise:install
Add to config/environments/development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
rails generate devise User
rails db:migrate
Add to app/controllers/application_controllers.rb
before_action :authenticate_user!
https://doorkeeper.gitbook.io/guides/ruby-on-rails/getting-started
bundle add doorkeeper
bundle exec rails generate doorkeeper:install
bundle exec rails generate doorkeeper:migration
Uncomment below to ensure a valid reference to the resource owner's table At db/migrate/_create_doorkeeper_tables.rb
add_foreign_key :oauth_access_grants, :users, column: :resource_owner_id
add_foreign_key :oauth_access_tokens, :users, column: :resource_owner_id
bundle exec rake db:migrate
Add to app/models/user.rb
has_many :access_grants,
class_name: 'Doorkeeper::AccessGrant',
foreign_key: :resource_owner_id,
dependent: :delete_all # or :destroy if you need callbacks
has_many :access_tokens,
class_name: 'Doorkeeper::AccessToken',
foreign_key: :resource_owner_id,
dependent: :delete_all # or :destroy if you need callbacks
# config/initializers/doorkeeper.rb
Doorkeeper.configure do
resource_owner_authenticator do
current_user || warden.authenticate!(scope: :user)
end
end
bundle add doorkeeper-jwt
# start the server
bin/dev
# TODO
curl http://localhost:3000 \
-H "Content-Type: application/json"