omniauth-ethereum
Authentication Strategy for OmniAuth to authenticate a user with an Ethereum account.
Installation
Add omniauth-ethereum
to your Gemspec
.
gem 'omniauth-ethereum'
Rails Usage
- Configure
config/routes.rb
in rails to serve the following routes:
Rails.application.routes.draw do
post '/auth/:provider/callback', to: 'sessions#create'
post '/auth/ethereum', to: 'sessions#new'
root to: 'sessions#index'
end
- Create a
SessionsController
for your app that enables an Ethereum authentication path.
class SessionsController < ApplicationController
skip_before_action :verify_authenticity_token, only: :create
def create
if request.env['omniauth.auth']
flash[:notice] = "Logged in"
else
flash[:notice] = "Unable to log in"
end
redirect_to '/'
end
def index
render inline: "<%= button_to 'Sign in', auth_ethereum_path %>", layout: true
end
end
- Add an Ethereum provider to your
config/initializers/omniauth.rb
middleware.
Rails.application.config.middleware.use OmniAuth::Builder do
provider :ethereum
end
- Add a
notice
class to your body templates relevant for authentication.
<p class="notice"><%= notice %></p>
Testing
Run the spec tests:
bundle install
bundle exec rspec --require spec_helper
Demo template
An example Rails app using omniauth-ethereum can be found at nahurst/omniauth-ethereum-rails.
License
The gem is available as open-source software under the terms of the Apache 2.0 License.