Test with import users to Auth0 enabled
When import users is enabled, users are gradually migrated from your external user store to Auth0 user store. In the process, users will be authenticated against the external store the first time they successfully log in. All further login attempts will be executed against the Auth0 user store. To learn more, read about automatic migrations in Import and Export Users.Create a test tenant and application
- Use the Auth0 Dashboard to create a new tenant.
-
Navigate to Applications > Applications and create a Machine-to-Machine application.
You need to note the Client ID and Client Secret when you create the custom database scripts. You need to note the Client ID to enable scopes in Management API.
-
Enable both the Password and Client Credential grant for this application (both grants should be enabled for this test).
- To authorize your application, navigate to Applications > APIs.
- Select Management API.
- Under the Machine-to-Machine Applications tab, use the toggle to authorize your test application.
-
Select the drop-down menu to enable the following Auth0 Management API scopes:
-
read:users
-
update:users
-
delete:users
-
create:users
-
read:users_app_metadata
-
update:users_app_metadata
-
create:users_app_metadata
-
Create test database connections
After you create a tenant and an application in Dashboard, create a source database connection and a target database connection.- Navigate to Authentication > Database to create a new database connection to be the source.
-
Name your test source connection, enable Requires Username, and select Create.
You can create users to use in your test by navigating to User Management > Users. Once you select Create Users and populate the necessary fields, select the source database under the Connection field.
-
Create a second database to be the target with the same configuration from step 2.
You can set the Password Policy to Non-empty password required in both target and source databases so you can use simple passwords in your tests.
-
In your target database, switch to the Custom Database view and toggle on Use my own database.
If you want to test using Organizations with your custom databases, enable Context object in database scripts.
- Switch to the Settings view and enable Import Users to Auth0.
- Switch to the Custom Database view, and then locate the Database settings section. Add the following information from your source database created in step 1:
Key | Value |
---|---|
client_id | Client ID of the application you created. |
client_secret | Client Secret of the application you created. |
auth0_domain | Your tenant name in the Auth0 domain: yourTenant.us.auth0.com . |
source_database | Name of the source connection. |
- Update the Login and Get User database action scripts in your target database. To learn more about best practices using database action scripts, read Custom Database Connection and Action Scripts Best Practices.
- Select Save and Try on each script. You should monitor the Real-time Webtask Logs Extension
console.log
output. To learn more, read Real-time Webtask Logs Extension. - Select Try Connection to test the connection live.
Test without Import Users enabled
- Repeat steps in Create a test tenant and application.
- Create one test database connection.
- Make sure Import Users to Auth0 under your source database settings is disabled. Users will authenticate against the external user store during each login attempt.
- Update all database actions scripts with the samples below.
Get User script
The Get User script implements an executable function that determines the current state of a user. When Import Users to Auth0 is enabled, the Get User script runs when a user attempts to sign up to check if the user already exists in the external user store. The Get User script also runs when a user attempts to:- Change a user’s email address (Change Email script)
- Log in (Login script)
- Change a user’s password (Change Password script)
- Create a user (Create script)
- Change a user’s email address (Change Email script)
- Change a user’s password (Change Password script)
Example
Login script
The Login script implements an executable function that authenticates a user when a user logs in. If the user exists in the target database (Auth0), it authenticates them using that record. Otherwise, it authenticates the user with their record in the source database (external).Example
Create script
The Create script implements an executable function that creates a corresponding user record in the external database when a user signs up through , or is created in the or with the Auth0 .Example
Delete script
The Delete script implements an executable function that deletes a user from Auth0 and the external database in the same operation when a user is deleted in the Auth0 Dashboard or with the Auth0 Management API.Example
Verify script
The Verify script implements an executable function that marks the verification status of a user’s email address in the external database when a user clicks on the link in the verification email sent by Auth0.Example
Change Password script
The Change Password script implements an executable function that updates a user’s password in the external database when a password change workflow starts from the Auth0 Dashboard or the Auth0 Management API.Example
Change Email script
The Change Email script implements an executable function that updates a user’s email address when the user changes their email address or their email address verification status. This script is not available in the Auth0 Dashboard. You must call the Management API Update a connection endpoint and provide theoptions.customScripts.change_email
property.