A simple Ruby on Rails application demonstrating Auth0 SSO integration using OmniAuth.
- Auth0 Universal Login integration
- Session-based authentication
- User model with Auth0 profile data
- Protected routes example
- Bootstrap 5 UI
- Ruby 3.3.5
- Rails 7.0
- Node.js (for asset compilation)
- Auth0 account
git clone <repository-url>
cd auth0-test-flow
bundle install
npm install- Create an Auth0 account at https://auth0.com
- Create a new Application (Regular Web Application)
- In your application settings, configure:
- Allowed Callback URLs:
http://localhost:3000/auth/auth0/callback - Allowed Logout URLs:
http://localhost:3000 - Allowed Web Origins:
http://localhost:3000
- Allowed Callback URLs:
Copy the example env file and fill in your Auth0 credentials:
cp .env.example .envEdit .env with your Auth0 values:
AUTH0_CLIENT_ID=your_client_id
AUTH0_CLIENT_SECRET=your_client_secret
AUTH0_DOMAIN=your-tenant.auth0.com
bin/rails db:migratebin/devOr without foreman:
bin/rails serverVisit http://localhost:3000
- User clicks "Login with Auth0"
- User is redirected to Auth0's Universal Login page
- After authentication, Auth0 redirects back to
/auth/auth0/callback - The callback creates/finds the user and sets the session
- User is redirected to the home page, now logged in
config/initializers/auth0.rb- OmniAuth Auth0 configurationapp/controllers/auth0_controller.rb- Handles Auth0 callbacks and logoutapp/controllers/application_controller.rb-current_userandlogged_in?helpersapp/models/user.rb- User model withfrom_omniauthmethod
To require authentication for a controller action:
class SecretController < ApplicationController
before_action :require_login
def index
# Only accessible to logged-in users
end
endMIT