πŸ›€οΈRails

Examples of Integrating Sign-In with Ethereum into Rails Applications

Overview

Rails is a full-stack framework built on top of Ruby to create web apps. The following are a set of gems and examples to get you started incorporating Sign-In with Ethereum to your Rails application.

Requirements

  • Ruby version 2.7.0 or above

  • Rails - can be installed using gem install rails once Ruby is installed

  • MetaMask wallet

Two gems have been created in order to make different examples of Rails integrations possible:

siwe_rails

Which is a Rails gem that adds Sign-In with Ethereum local sign-in routes.

omniauth-siwe

Which provides an OmniAuth strategy for Sign In With Ethereum.

Examples

Currently, there are three examples of Sign-In with Ethereum being used for authentication in Rails applications:

custom-controller

Which shows how to manually add endpoints to generate and verify the Sign-In with Ethereum message, and handle session-based user logins on a Rails application.

rails-engine

Which shows how to use siwe_rails gem to set up and configure the endpoints to generate and verify a Sign-In with Ethereum message in a Rails application.

omniauth-siwe

Which shows how to use and configure the omniauth-siwe provider with OmniAuth in a Rails application.

Each of these examples can be found in the siwe-rails-examples repository.

To get started with any of the examples, clone the siwe-rails-examples repository locally:

To build and test each example, check out the following guides:

Custom-Controller

  • First, enter the custom-controller directory in siwe-rails-examples.

  • Finally, run the following commands to run the example:

This executes any database migrations, installs the proper gems, and runs the Rails example. Visit the example by visiting localhost:3000 in your web browser.

You should now see the example, and be able to Sign-In with Ethereum to authenticate and establish a session.

Rails-Engine

  • Clone the siwe_rails gem in the same parent directory as siwe-rails-examples:

  • Next, enter the rails-engine directory in siwe-rails-examples.

  • Finally, run the following commands to run the example:

This executes any database migrations, installs the proper gems, and runs the Rails example. Visit the example by visiting localhost:3000 in your web browser.

You should now see the example, and be able to Sign-In with Ethereum to authenticate and establish a session.

OmniAuth

  • Clone the omniauth-siwe gem in the same parent directory as siwe-rails-examples:

  • Next, enter the omniauth directory in siwe-rails-examples.

  • To be able to use oidc.login.xyz you will need to register as a client. To do that, use the following command, filling out your own redirect_uris, according to your setup:

In this case, since we're running this example on localhost:3000, we need the redirect_uris to contain http://localhost:3000/auth/siwe/callback.

  • After that, update omniauth.rb under omniauth/config/initializers with both the provided identifier (client_id) and secret (client_secret):

  • Finally, run the following commands to run the example:

This installs the proper gems and runs the Rails example. Visit the example by visiting localhost:3000 in your web browser.

You should now see the example, and be able to Sign-In with Ethereum to authenticate and establish a session.

Last updated