Auth0

The Auth0 connection is a User Provider that automatically imports and keeps your users up-to-date in UserHub.

To enable the Auth0 connection, you'll need to create a machine-to-machine application type and optionally add the UserHub action to your Auth0 tenant.

Create an Auth0 Application

  1. Go to the Auth0 Dashboard
  2. Switch to the tenant you want to set up in UserHub
  3. Click Applications and then Applications again
  4. Click the Create Application button
  5. Enter UserHub for the Name
  6. Select Machine to Machine for the Application type
  7. Click Create
  8. When prompted, select the Auth0 Management API
  9. Select the following permissions: read:users, update:users, delete:users, and create:users
  10. Click Authorize
  11. Take note of the Client ID from the header and the Client Secret from the Credentials tab. You'll need these in the next step.

Setup Connection

Next, you will need to set up the connection in the UserHub Admin Console.

  1. Go to the User tab after selecting your tenant, under Tenant settings > Connections.
  2. Click the Auth0 card
  3. Enter your Auth0 Domain (this must end with auth0.com)
  4. Enter the Client ID and Client Secret you created above
  5. Click Save
  6. Make sure the status switches to Active. If not click the Test connection button to see why.

Copy the newly created connection ID (e.g. conn_obXdd...), this will be used in the next step.

Optional: Setup Auth0 Action

The UserHub Auth0 Action ensures your users are immediately synced with UserHub on sign-in.

To set up the UserHub Auth0 action, you'll need the UserHub Auth0 connection ID (see above) and an Admin API key scoped to Auth0.

Create API Key

  1. Go API keys in the Admin Console
  2. Click New API key
  3. Enter Auth0 Action for the Description
  4. Select Admin API for the Type
  5. Don't set an expiration
  6. Click the Integrations dropdown and select Auth0
  7. Click Create
  8. Note the generated API key (e.g. sk_agX...), this ID will be used in the next step

Setup Action

Next, you'll need to set up the UserHub Action in Auth0:

  1. Go the the Auth0 Dashboard

  2. Switch to the desired Auth0 tenant

  3. Click Actions and then Library in the left menu

  4. Click Build Custom

  5. Enter UserHub for the Name

  6. Select Login / Post Login as the Trigger

  7. Select the latest recommended Node Runtime

  8. Click Create

  9. Replace the code with the following snippet:

    const { UserHubActions } = require("@userhub/auth0-actions");
    
    exports.onExecutePostLogin = async (event, api) => {
      const actions = new UserHubActions({
        apiKey: event.secrets.API_KEY,
        connectionId: event.secrets.CONNECTION_ID,
      });
    
      await actions.postLogin(event);
    };
    
  10. Click the Dependencies icon in the left panel and Add Dependency to add the UserHub dependency: @userhub/auth0-actions

  11. Click the Secrets icon in the left panel and click Add Secret

  12. Enter API_KEY for the Key

  13. Enter the Admin API key you generated above for the Value

  14. Click Create

  15. Click Add Secret again

  16. Enter CONNECTION_ID for the Key

  17. Enter the connection ID you noted in step 2 for the Value (e.g. conn_obXdd...)

  18. Click Create

  19. Click Deploy

  20. Click Flows under Actions in the left menu

  21. Click the Login card

  22. Click the Custom tab on the right

  23. Drag the UserHub action so that it's positioned between the Start and End nodes

  24. Click Apply

PreviousConnections
NextCustom Users

Turn users intorevenue
$

Subscribe to monthly product updates

© 2024 UserHub

Integrations

    UserHub & Auth0UserHub & Stripe BillingUserHub & Google CloudUserHub & FirebaseUserHub & Custom Auth

Resources