Roda

If you want to integrate rodauth-oauth in a roda application, you’ve come to the right place: rodauth-oauth is a feature of rodauth, itself a plugin for roda!

The wiki page and README both contain a Roda application. The integration is seamless:

# in a roda application
plugin :rodauth do
  enable :login, :oauth_authorization_code_grant # just another feature
  oauth_applications_scopes %w[books.read books.write]
end

route do |r|
  r.rodauth # this also loads the oauth routes

  r.is "books" do
    rodauth.require_oauth_authorization("books.read")
    # only valid oauth access tokens with the right permission shall pass!
    ...
  end
end

It’s very important to understand the roda/rodauth integration, as all other integrations are a subset of it. So, Let’s break it down.

Roda

roda is something like a rack toolkit for building applications. It can be your main “framework”, but it can also be “bundled” into your main rack applications. This makes it quite flexible.

Roda comes with a plugin system, which builds on top of its main components. rodauth is therefore one of the many plugins which can be used within roda.

Rodauth

feature configuration

Bootstrapping rodauth inside a roda application looks like this:

plugin :rodauth do
  # enable features
  enable :oauth_authorization_code_grant # there it is
  # options come here ...
end

This is where all rodauth features and options are declared or overridden.

Usage

Once the plugin is declared, you can do two things: bundle the rodauth feature set in the roda application, and call the rodauth publicly available methods, which can, i.e. require authentication or authorization.

route do `r`
  # this loads the rodauth feature routes, your /authorize, /token....
  r.rodauth

  # all rodauth feature public methods are available through the `rodauth` object
  rodauth.require_oauth_authentication("profile.read")

  @account = rodauth.current_oauth_account
end

This is the gist of it, really. rodauth is pretty feature rich, and there are some options you can use to tweak rodauth-oauth, so you’re always suggested to learn more about it.

Home