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#
- Go to the Auth0 Dashboard
- Switch to the tenant you want to set up in UserHub
- Click Applications and then Applications again
- Click the Create Application button
- Enter
UserHub
for the Name - Select
Machine to Machine
for the Application type - Click Create
- When prompted, select the
Auth0 Management API
- Select the following permissions:
read:users
,update:users
,delete:users
, andcreate:users
- Click Authorize
- 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.
- Go to the User tab after selecting your tenant, under Tenant settings > Connections.
- Click the Auth0 card
- Enter your Auth0 Domain (this must end with
auth0.com
) - Enter the Client ID and Client Secret you created above
- Click Save
- 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 need the UserHub Auth0 connection ID (see above) and an Admin API key scoped to Auth0.
- Go API keys in the Admin Console
- Click New API key
- Enter
Auth0 Action
for the Description - Select
Admin API
for the Type - Don't set an expiration
- Click the Integrations dropdown and select
Auth0
- Click Create
- Note the generated API key (e.g.
sk_agX...
), this ID will be used in the next step
Next, you need to set up the UserHub Action in Auth0:
- Go the the Auth0 Dashboard
- Switch to the Auth0 tenant you used in step 1
- Click Actions and then Library in the left menu
- Click Build Custom
- Enter
UserHub
for the Name - Select
Login / Post Login
as the Trigger - Select the latest recommended Node Runtime
- Click Create
- 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);
};
- Click the Dependencies icon in the left panel and Add Dependency to add the UserHub dependency:
@userhub/auth0-actions
- Click the Secrets icon in the left panel and click Add Secret
- Enter
API_KEY
for the Key - Enter the Admin API key you generated above for the Value
- Click Create
- Click Add Secret again
- Enter
CONNECTION_ID
for the Key - Enter the connection ID you noted in step 2 for the Value (e.g.
conn_obXdd...
) - Click Create
- Click Deploy
- Click Flows under Actions in the left menu
- Click the Login card
- Click the Custom tab on the right
- Drag the
UserHub
action so that it's positioned between the Start and End nodes - Click Apply