We've moved discussions to Discord

How to set up Auth0 [UPDATED]

Georg Törnqvist
Just wondering how to configure Auth0.

[EDIT]
Auth0 doesn't seem to get along with auth0. See trace below.

20:14:50 web.1     | 
20:14:50 web.1     | 
20:14:52 web.1     | Started POST "/users/auth/auth0" for 127.0.0.1 at 2021-09-28 20:14:52 +0200
20:14:52 web.1     | D, [2021-09-28T20:14:52.194130 #27767] DEBUG -- omniauth: (auth0) Request phase initiated.
20:14:52 web.1     | Started GET "/users/auth/auth0/callback?code=j3rFc5SihsEY6yBy&state=73af5ae5936c98c2fd8f23d8211b69ae2e35632359f75bd4" for 127.0.0.1 at 2021-09-28 20:14:52 +0200
20:14:52 web.1     | D, [2021-09-28T20:14:52.497437 #27767] DEBUG -- omniauth: (auth0) Callback phase initiated.
20:14:53 web.1     | Processing by Users::OmniauthCallbacksController#auth0 as HTML
20:14:53 web.1     |   Parameters: {"code"=>"j3rFc5SihsEY6yBy", "state"=>"73af5ae5936c98c2fd8f23d8211b69ae2e35632359f75bd4"}
20:14:53 web.1     |   Account Load (0.1ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."domain" = $1 LIMIT $2  [["domain", "localhost"], ["LIMIT", 1]]
20:14:53 web.1     |   ↳ app/controllers/concerns/set_current_request_details.rb:25:in `account_from_domain'
20:14:53 web.1     |   Cart Load (0.4ms)  SELECT "carts".* FROM "carts" WHERE "carts"."id" = $1 LIMIT $2  [["id", 53], ["LIMIT", 1]]
20:14:53 web.1     |   ↳ app/models/concerns/current_cart.rb:6:in `set_cart'
20:14:53 web.1     |   User::ConnectedAccount Load (0.2ms)  SELECT "user_connected_accounts".* FROM "user_connected_accounts" WHERE "user_connected_accounts"."provider" = $1 AND "user_connected_accounts"."uid" IS NULL ORDER BY "user_connected_accounts"."id" ASC LIMIT $2  [["provider", "auth0"], ["LIMIT", 1]]
20:14:53 web.1     |   ↳ app/models/user/connected_account.rb:46:in `for_auth'
20:14:53 web.1     |   User Exists? (0.1ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" IS NULL LIMIT $1  [["LIMIT", 1]]
20:14:53 web.1     |   ↳ lib/jumpstart/lib/jumpstart/omniauth/callbacks.rb:16:in `block (2 levels) in <module:Callbacks>'
20:14:53 web.1     | Completed 422 Unprocessable Entity in 108ms (ActiveRecord: 0.8ms | Allocations: 4768)
20:14:53 web.1     | 
20:14:53 web.1     | 
20:14:53 web.1     |   
20:14:53 web.1     | ActiveRecord::RecordInvalid (Validation failed: Email can't be blank, Name can't be blank):
20:14:53 web.1     |   
20:14:53 web.1     | lib/jumpstart/lib/jumpstart/omniauth/callbacks.rb:59:in `create_user'
20:14:53 web.1     | lib/jumpstart/lib/jumpstart/omniauth/callbacks.rb:23:in `block (2 levels) in <module:Callbacks>'
20:14:53 web.1     | lib/jumpstart/lib/jumpstart/account_middleware.rb:30:in `call'
20:15:35 web.1     | 2021-09-28 20:15:35 +0200 Rack app ("GET /packs/js/application.js" - (127.0.0.1)): #<Net::OpenTimeout: execution expired>
20:51:35 web.1     | Started GET "/jumpstart" for 127.0.0.1 at 2021-09-28 20:51:35 +0200
20:51:35 web.1     | Processing by Jumpstart::AdminController#show as HTML


When I created this post I was stuck at step 2 below. As I've made some progress since then I thought I might as well describe how I got out of the mist... :)

Getting the login button to appear on the login page
The steps below makes login button appear on the login page. When you click it, it takes me to the Auth0 login screen.
  1. Create an Auth0 account and created the credentials and set the callback url.
  2. Put the auth0 credentials in the development.yml
  3. Add the auth0 section to the AVAILABLE_PROVIDERS constant in omniauth.rb.
  4. Restart the app and see the option Auth0 show up "Login & OAuth".
  5. Enable Auth0 and restart the app once more. 


My development.yml:
...
omniauth:
  # Add other OmniAuth providers here

  auth0:
    domain: 'mydomain.com'
    public_key: 'Client ID'
    private_key: 'Client Secret'
.... 

My omniauth.rb
..},
"auth0" => {
 name: "Auth0",
 provider: :auth0,
 icon: :auth0
}
}.freeze


All the best,
Georg

Chris Oliver
ActiveRecord::RecordInvalid (Validation failed: Email can't be blank, Name can't be blank):
You will need to update the omniauth code so that it assigns email and name from Auth0.
Notifications
You’re not receiving notifications from this thread.