Rails

Rails is the most widely used framework in the ruby ecosystem, by far. Its feature and capabilities are wide, and as a consequence, most of the OAuth libraries which work in rails, only work in Rails (ex: doorkeeper). The same can be said of the authentication case (ex: devise)

However, rodauth-rails changed that! It integrates rodauth with the rails feature set, by bringing:

  • db migration generators;
  • view generators;
  • models/helpers/controllers;

and everything that one can expect from a rails app.

How to integrate rodauth-oauth in a rails app?

First thing you’ll have to do is install and integrate rodauth-rails.

Once you do it, you can then:

1. Generate migrations and models

> rails generate rodauth:oauth:install

This will:

  • generate the db migrations to create the necessary tables (you are recommended to open and tweak them according to your needs);
  • generate active record models for the oauth entities (rodauth-oauth does not use them internally, so feel free to update and use them yourself);

2. Generate the views

> rails generate rodauth:oauth:views

This will:

  • Generate a template under app/views with the authorize form;
  • Generate templates for the client application management dashboard (if you pass -a or --features oauth_applications;

which you can then tweak according to your requirements.

3. Enable oauth feature

rodauth-specific configuration can be found under lib/rodauth_app.rb. It’s there where you’ll have to enable the feature:

# in lib/rodauth_app.rb
plugin :rodauth do
  enable :oauth
  ...

And that’s it, really.

Home