A command-line tool for creating Auth0 users with sequential email addresses and role assignments.
- Create multiple Auth0 users with sequential email addresses
- Assign roles to newly created users
- Interactive role selection from available Auth0 roles
- Export successful responses to a JSON file
- Smart output file handling: appends to existing data when possible
- Automatic extraction of Auth0 API URL from JWT token
- Debug mode to preview requests without making API calls
- Graceful error handling
- Python 3.6+
requests
library
It's recommended to use a virtual environment to avoid conflicts with other Python packages:
# Create a virtual environment
python -m venv auth0_venv
# Activate the virtual environment
## On macOS/Linux:
source auth0_venv/bin/activate
## On Windows:
# auth0_venv\Scripts\activate
# Install dependencies
pip install requests
# When finished, deactivate the virtual environment
# deactivate
If you prefer not to use a virtual environment, you can install the dependency directly:
pip install requests
python auth0_user_creator.py --token "YOUR_AUTH0_TOKEN" --email "client-test-e2e-{$}@example.com" --start 1 --end 10
--token
: Auth0 Management API token with the necessary permissions--email
: Email template with{$}
placeholder (e.g.,user-{$}@example.com
)--start
: Starting number for email replacement--end
: Ending number for email replacement
--role-id
: Auth0 Role ID to assign to each user (if not provided, you'll be prompted to select from available roles)--output
: Output JSON file for successful responses (default:auth0_users.json
)--debug
: Run in debug mode without making actual API calls
python auth0_user_creator.py --token "eyJhbGci..." --email "test-user-{$}@example.com" --start 1 --end 5
This will:
- Extract the Auth0 API URL from the token's "aud" claim
- Fetch available roles from Auth0 and display them for selection
- Prompt you to select a role to assign to all users
- Create 5 users with emails:
- Assign each user the selected role
If you don't provide the --role-id
parameter, the script will:
- Fetch all available roles from your Auth0 tenant
- Display the roles with their names, descriptions, and IDs
- Prompt you to select a role by entering its number
- Use the selected role for all user creations
Example:
Available Roles:
----------------
1. Admin - Administrator role (ID: rol_123abc)
2. User - Regular user role (ID: rol_456def)
3. Editor - Content editor role (ID: rol_789ghi)
Select a role (enter number): 2
Selected role: User (ID: rol_456def)
You can still provide the --role-id
directly if you prefer:
python auth0_user_creator.py --token "eyJhbGci..." --email "test-user-{$}@example.com" --start 1 --end 5 --role-id "rol_123abc"
The script intelligently handles output files:
- If the output file doesn't exist, it will create a new file
- If the output file exists and contains a valid JSON array, it will append new results to the existing data
- If the output file exists but doesn't contain valid JSON or doesn't contain a JSON array, it will overwrite the file
This means you can run the script multiple times with different parameters, and all successfully created users will be accumulated in the output file.
Example of appending to existing results:
$ python auth0_user_creator.py --token "..." --email "user-{$}@example.com" --start 1 --end 3
Successfully created 3 users. Total users in output file: 3
$ python auth0_user_creator.py --token "..." --email "user-{$}@example.com" --start 4 --end 6
Successfully created 3 users. Total users in output file: 6
Run the script with the --debug
flag to preview API requests without making actual calls:
python auth0_user_creator.py --token "YOUR_AUTH0_TOKEN" --email "user-{$}@example.com" --start 1 --end 2 --debug
This will:
- Display detailed information about each request that would be made
- Show sample response data
- Not create any actual users in Auth0
Debug mode is useful for:
- Testing your configuration
- Understanding the API requests before executing them
- Validating that the token contains the correct API URL
If an error occurs during user creation or role assignment, the script will:
- Output the error message
- Save all successful user creations to the specified output file
- Exit with status code 1