Create a new controller ./app/controllers/auth0_controller.rb to handle the callback from Auth0.
You can also run rails generate controller auth0 callback failure logout --skip-assets --skip-helper --skip-routes --skip-template-engine to scaffold this controller for you.
# ./app/controllers/auth0_controller.rbclassAuth0Controller < ApplicationControllerdefcallback# OmniAuth stores the information returned from Auth0 and the IdP in request.env['omniauth.auth'].# In this code, you will pull the raw_info supplied from the id_token and assign it to the session.# Refer to https://github.com/auth0/omniauth-auth0/blob/master/EXAMPLES.md#example-of-the-resulting-authentication-hash for complete information on 'omniauth.auth' contents.
auth_info = request.env['omniauth.auth']
session[:userinfo] = auth_info['extra']['raw_info']
# Redirect to the URL you want after successful auth
redirect_to '/dashboard'enddeffailure# Handles failed authentication -- Show a failure page (you can also handle with a redirect)@error_msg = request.params['message']
enddeflogout# you will finish this in a later stependend
Add routes
Finally, add the following routes to your ./config/routes.rb file:
Rails.application.routes.draw do# ..
get '/auth/auth0/callback' => 'auth0#callback'
get '/auth/failure' => 'auth0#failure'
get '/auth/logout' => 'auth0#logout'end
Logging in
To redirect your users to Auth0 for authentication, redirect your users to the /auth/auth0 endpoint of your app. One way to do this is to use a link or button on a page:
Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.
Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout Why Auth0?
This project is licensed under the MIT license. See the LICENSE file for more info.
FAQs
Unknown package
We found that omniauth-auth0 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.
Package last updated on 25 Jul 2023
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Ransomware negotiators share how modern cybercriminals operate like corporations, using specialized teams, negotiation tactics, and reputation management.