Ruby On Rails: User Profile

View on Github

Ruby On Rails: User Profile

Gravatar for
By Josh Cunningham

This tutorial demonstrates shows how to access the user profile information using OmniAuth-Auth0 strategy. We recommend you to Log in to follow this quickstart with examples configured for your account.

I want to integrate with my app

15 minutes
  1. Process the Callback
  2. Display the User Profile

I want to explore a sample app

2 minutes

Get a sample configured with your account settings or check it out on Github.

View on Github
System requirements: Ruby 2.3.1+ | Rails 5.0.0+ or Rails 4.2.0+

Issue: The IdP Login Page Doesn't Display

Process the Callback

After receiving a successful callback at /auth/auth0/callback, the OmniAuth strategy provides available user profile information via the request.env['omniauth.auth'] hash.

The full contents of the authentication hash retrieved by the Auth0 strategy are detailed here.

In the login step, you configured the application for OmniAuth to start the OmniAuth-Auth0 strategy and for OmniAuth to take over and complete the authentication process. You also set a route that matches the callback URL in the application routes.

The callback action in the auth0 controller retrieves the auth hash and stores it in the application's session hash. It then redirects to the dashboard controller show action, which renders the dashboard view.

Test the Connection

Display the User Profile

The auth hash built by the OmniAuth Auth0 strategy has the user profile data under the info key. Each element is named according to the normalized user profile definition.

The auth hash also contains the full user profile under the raw key. The difference is that the normalized user profile data is pre-processed and guaranteed to be present, while the full user profile data may vary depending on several factors, including which social identity provider is used to log the user in.

Add a template which displays the user's profile data.

Additionally, declare and assign the contents to the user variable in the dashboard controller:

Use Auth0 for FREE