Skip to content

Example rails application implementing devise with web3id authentication strategy

Notifications You must be signed in to change notification settings

robinbortlik/web3id-rails

Repository files navigation

WEB3ID Rails example

This repo contains example rails application which integrates devise with web3id authenitication strategy.

What is web3id?

Example app setup

  • clone repo git clone git@github.com:robinbortlik/web3id-rails.git
  • generate your web3id key/secret as per instructions in official documentation
  • update .env file
  • bundle install
  • bundle exec rake db:setup
  • start server bundle exec rails s
  • open http://localhost:3000 in your browser

How to configure your devise with web3id ?

  • add omniauth-web3id gem to your Gemfile
  • configure web3id strategy in devise config
  config.omniauth(:web3id,
    ENV.fetch("WEB3ID_CLIENT_ID"),
    ENV.fetch("WEB3ID_CLIENT_SECRET_KEY"),
    callback_path: '/oauth/callback'
  )
  • define omniauth callbacks controller
class Omniauth::CallbacksController < Devise::OmniauthCallbacksController
  def web3id
    @account = Account.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @account
  end
end
  • register new controller in routes.rb
devise_for :accounts, :controllers => { :omniauth_callbacks => "omniauth/callbacks" }
devise_scope :account do
  get "/oauth/callback" => "omniauth/callbacks#web3id"
end
  • register omniauth provider in your devise model
class Account < ApplicationRecord
  devise :omniauthable, :omniauth_providers => [:web3id]
end
  • add login button to your html template
<%= form_tag account_web3id_omniauth_authorize_path, data: { turbo: false } do %>
  <button>Login</button>
<% end %>

Showcase

Screen_Recording_2022-07-24_at_23.43.27.mov

About

Example rails application implementing devise with web3id authentication strategy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published