Search code examples
pythonauth0

Python Auth0 - example script not authorized


Need to enumerate users, I'm using the auth0 client located here - https://github.com/auth0/auth0-python.

I've setup an example application, and made sure it has Client Credentials grant type. Via the example, trying to run the following . . . .

        get_token = GetToken(domain)
    token = get_token.client_credentials(non_interactive_client_id,
                                         non_interactive_client_secret, 'https://{}/api/v2/'.format(domain))
    mgmt_api_token = token['access_token']

    auth0 = Auth0(domain, mgmt_api_token)

    conns = auth0.connections.all()
    return conns

However at .client_credentials, I'm failing with . ..

auth0.v3.exceptions.Auth0Error: 403: Client is not authorized to access "https://MY_DOMAIN/api/v2/". You might probably want to create a "client-grant" associated to this API. 

There's a doc associated with the error, but it is 404.


Solution

  • The SDK is consuming the Management API via the client credentials grant using the non_interactive_client_id as the client id.

    The error you are seeing is Auth0 telling you that that particular client id is not authorized to consume the API.

    The Management API is a resource you can find in your Auth0 Dashboard under "APIs" (not sure but there was also a deep link such as manage.auth0.com/#/apis/management). In there there is a tab that should say something like "Non Interactive Clients" where you will see the list of all your clients and toggles to grant them access to the API.

    After granting access to the API (and to the required scopes), your operation should work.