|
1 | 1 | # omniauth-ethereum |
2 | | -Implements the Ethereum provider strategy for OmniAuth |
3 | 2 |
|
4 | | -To test |
| 3 | +[](https://github.com/q9f/omniauth-ethereum/actions) |
| 4 | +[](https://github.com/q9f/omniauth-ethereum/releases) |
| 5 | +[](https://rubygems.org/gems/omniauth-ethereum) |
| 6 | +[](https://github.com/q9f/omniauth-ethereum/pulse) |
| 7 | +[](LICENSE) |
| 8 | + |
| 9 | +Authentication Strategy for [OmniAuth](https://github.com/omniauth/omniauth) to authenticate a user with an [Ethereum](https://ethereum.org) account. |
| 10 | + |
| 11 | +### Installation |
| 12 | +Add `omniauth-ethereum` to your `Gemspec`. |
| 13 | + |
| 14 | +```ruby |
| 15 | +gem 'omniauth-ethereum' |
| 16 | +``` |
| 17 | + |
| 18 | +### Rails Usage |
| 19 | +1. Configure `config/routes.rb` in rails to serve the following routes: |
| 20 | + |
| 21 | +```ruby |
| 22 | +Rails.application.routes.draw do |
| 23 | + post '/auth/:provider/callback', to: 'sessions#create' |
| 24 | + post '/auth/ethereum', to: 'sessions#new' |
| 25 | + root to: 'sessions#index' |
| 26 | +end |
5 | 27 | ``` |
6 | | -bundle |
7 | | -rspec |
| 28 | + |
| 29 | +2. Create a `SessionsController` for your app that enables an Ethereum authentication path. |
| 30 | + |
| 31 | +```ruby |
| 32 | +class SessionsController < ApplicationController |
| 33 | + skip_before_action :verify_authenticity_token, only: :create |
| 34 | + |
| 35 | + def create |
| 36 | + if request.env['omniauth.auth'] |
| 37 | + flash[:notice] = "Logged in" |
| 38 | + else |
| 39 | + flash[:notice] = "Unable to log in" |
| 40 | + end |
| 41 | + |
| 42 | + redirect_to '/' |
| 43 | + end |
| 44 | + |
| 45 | + def index |
| 46 | + render inline: "<%= button_to 'Sign in', auth_ethereum_path %>", layout: true |
| 47 | + end |
| 48 | +end |
8 | 49 | ``` |
9 | 50 |
|
10 | | -An [example Rails app using omniauth-ethereum](https://github.com/nahurst/omniauth-ethereum-rails) |
| 51 | +3. Add an Ethereum provider to your `config/initializers/omniauth.rb` middleware. |
| 52 | + |
| 53 | +```ruby |
| 54 | +Rails.application.config.middleware.use OmniAuth::Builder do |
| 55 | + provider :ethereum |
| 56 | +end |
| 57 | +``` |
| 58 | + |
| 59 | +4. Add a `notice` class to your body templates relevant for authentication. |
| 60 | + |
| 61 | +```html |
| 62 | +<p class="notice"><%= notice %></p> |
| 63 | +``` |
| 64 | + |
| 65 | +### Testing |
| 66 | +Run the spec tests: |
| 67 | + |
| 68 | +```shell |
| 69 | +bundle install |
| 70 | +bundle exec rspec --require spec_helper |
| 71 | +``` |
| 72 | + |
| 73 | +### Demo template |
| 74 | +An example Rails app using omniauth-ethereum can be found at [nahurst/omniauth-ethereum-rails](https://github.com/nahurst/omniauth-ethereum-rails). |
| 75 | + |
| 76 | +### License |
| 77 | +The gem is available as open-source software under the terms of the [Apache 2.0 License](LICENSE). |
0 commit comments