No release in over 3 years
Low commit activity in last 3 years
add authentication to your application - in 1 minute or less
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

gatleon-authform-rails

add authentication to your application - in 1 minute or less.

installation

add this line to your application's Gemfile:

gem "gatleon-authform-rails"

and then execute:

$ bundle install

open rails credentials:

$ EDITOR=vim rails credentials:edit

set authform credentials:

authform:
  public_key: "Available at https://authform.gatleon.com"
  secret_key: "Available at https://authform.gatleon.com"

add a profile controller:

class ProfileController < ActionController::Base
  include Gatleon::Authform::Rails::Concern.new(Rails.application.credentials.dig(:authform))

  before_action :require_login, only: [:index]

  def index
    erb = <<~ERB
      <h1>Profile</h1>
      <p style="color: green;">You are signed in. (<a href="/profile/signoff">sign off</a>)</p>
      <p><%= current_user._id %> <%= current_user._email %></p>
    ERB

    render inline: erb
  end

  def signin
    erb = <<~ERB
      <p style="color: red;"><%= flash[:error] %></p>
      <h1>Sign In</h1>
      <form action="<%= signon_url %>" method="POST">
        <input type="hidden" name="successPath" value="/profile">
        <input type="email" name="email">
        <button type="submit">Sign In</button>
      </form>
    ERB

    render inline: erb
  end

  def signoff
    current_user.signoff!

    redirect_to(profile_signin_path) and return
  end

  private

  def require_login
    unless current_user
      flash[:error] = "Sign in, please."

      redirect_to(profile_signin_path) and return
    end
  end
end

add profile routes to routes.rb:

Rails.application.routes.draw do
  get "/profile", to: "profile#index", as: :profile
  get "/profile/signin", to: "profile#signin", as: :profile_signin
  get "/profile/signoff", to: "profile#signoff", as: :profile_signoff
end

that's it!

license

the gem is available as open source under the terms of the MIT License.