Auth0
The Auth0 connection is a user provider that automatically imports your users and keeps them 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 Connections in the Developers dropdown of the Tenant settings.
- Click the Setup button for Auth0
- 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
Copy the newly created connection ID (e.g. conn_obXdd...
), as this will be used in the next step.
Optional: setup Portal callback
Next, you have the option of using Auth0's sign-in interface instead of implementing the Portal callback handler.
Create app for callback
- Go to the Auth0 dashboard
- Switch to the tenant you set up above
- Click Applications and then Applications again
- Click the Create Application button
- Enter
Billing
for the Name (or whatever you prefer) - Select Regular Web for the Application type
- Click Create
- Click the Settings tab
- Enter
https://<portal-domain>/
for Application Login URI (you can find this URL in the Admin console Portal settings) - Enter
https://<portal-domain>/signin
for Allowed Callback URLs - Enter
https://<portal-domain>/signout
for Allowed Logout URLs - Click Save Changes
- Note the Client ID and Client secret, you'll need it in the next step
Add app settings to connection
- Go to Connections from the UserHub Admin console Developers dropdown
- Click Auth0
- Click the Edit connection button
- Click Enable Portal sign-in
- Enter the App client ID and App client secret you noted above and click Save
You should now be able to open https://<portal-domain>/
in your browser and sign in.
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
- Go to the Admin console and click API keys via the Developers dropdown or Tenant settings
- 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...
), as this token will be used in the next step
Setup action
Next, you'll need to set up the UserHub action in Auth0:
Go the the Auth0 dashboard
Switch to the desired Auth0 tenant
Click Actions and then Library in the left menu
Click Build Custom
Enter
UserHub
for the NameSelect
Login / Post Login
as the TriggerSelect 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 KeyEnter the Admin API key you generated above for the Value
Click Create
Click Add Secret again
Enter
CONNECTION_ID
for the KeyEnter 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 nodesClick Apply