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 = " <h1>Profile</h1>\n <p style=\"color: green;\">You are signed in. (<a href=\"/profile/signoff\">sign off</a>)</p>\n <p><%= current_user._id %> <%= current_user._email %></p>\n ERB\n\n render inline: erb\n end\n\n def signin\n erb = <<~ERB\n <p style=\"color: red;\"><%= flash[:error] %></p>\n <h1>Sign In</h1>\n <form action=\"<%= signon_url %>\" method=\"POST\">\n <input type=\"hidden\" name=\"successPath\" value=\"/profile\">\n <input type=\"email\" name=\"email\">\n <button type=\"submit\">Sign In</button>\n </form>\n ERB\n\n render inline: erb\n end\n\n def signoff\n current_user.signoff!\n\n redirect_to(profile_signin_path) and return\n end\n\n private\n\n def require_login\n unless current_user\n flash[:error] = \"Sign in, please.\"\n\n redirect_to(profile_signin_path) and return\n end\n end\nend\n"
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.