Created
June 7, 2025 20:39
-
-
Save lordjabez/dda734a8dff955893d25c0bec9ac6dc8 to your computer and use it in GitHub Desktop.
Get an Auth0 access token via script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import getpass | |
| import os | |
| import requests | |
| auth0_url = os.environ['AUTH0_URL'] | |
| auth0_audience = os.environ['AUTH0_AUDIENCE'] | |
| auth0_client_id = os.environ['AUTH0_CLIENT_ID'] | |
| auth0_client_secret = os.environ['AUTH0_CLIENT_SECRET'] | |
| def get_access_token(username, password): | |
| body = { | |
| 'grant_type': 'password', | |
| 'audience': auth0_audience, | |
| 'client_id': auth0_client_id, | |
| 'client_secret': auth0_client_secret, | |
| 'username': username, | |
| 'password': password, | |
| } | |
| response = requests.post(auth0_url, data=body, timeout=5.0) | |
| body = response.json() | |
| if 'access_token' in body: | |
| return body['access_token'] | |
| else: | |
| description = body['error_description'] | |
| print(f'Error: {description}') | |
| return None | |
| username = input('Auth0 Username: ') | |
| password = getpass.getpass('Auth0 Password: ') | |
| access_token = get_access_token(username, password) | |
| print(access_token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment