Auth1
Auth1 is a Rails Engine for Auth0. Auth1 provides everything you need to use Auth0 in your Rails application.
Usage
View Helpers
Link Helpers
<% if logged_in? -%>
<%= logout_link %>
<% else -%>
<%= login_link %>
<% end -%>
# or just
<%= login_or_logout_link %>
Button Helpers
<% if logged_in? -%>
<%= logout_button %>
<% else -%>
<%= login_button %>
<% end -%>
# or just
<%= login_or_logout_button %>
URL Helpers
auth1.callback_url
auth1.failure_url
auth1.logout_url
Installation
Add this line to your application's Gemfile:
gem 'auth1'
Then run bundle install
.
Next, run the Auth1 install generator:
rails g auth1:install
This will add the following environment variables to .env.local
if you are using dotenv-rails gem:
# Values from https://manage.auth0.com/#/applications
AUTH0_CLIENT_ID
AUTH0_CLIENT_SECRET
AUTH0_DOMAIN
# URL in your application to redirect to after logout from Auth0
AUTH0_LOGOUT_URL
If you're not using dotenv-rails
gem, just set the above environment variables yourself.
This will also mount Auth1 routes in your application by adding the following to config/routes.rb
:
# config/routes.rb
Rails.application.routes.draw do
mount Auth1::Engine => '/'
end
Update Allowed Callback URLs field in Auth0 Application Settings. For local development, you can set this value to http://localhost:3000/auth/auth0/callback
.
Update Allowed Logout URLs field in Auth0 Application Settings with the same value in AUTH0_LOGOUT_URL
environment variable.
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.