Obtain user access_token from Python for unit tests

I’m hoping to run unit tests against some routes of my “Calculations” API which is a flask back end.
Basic authentication is working fine, I can use the the automatically generated “Calculations (Test Client)”'s id and secret pair to grab an access_token. So for routes that don’t depend on a user’s credentials I can test those.
However, for several routes I need to have the user’s identity that is obtained from the access_token.

Is there a way, in Python, to call the Auth0 authentication API, give it a username and password and receive an access_token for testing purposes?
I see some semblance of this being possible in the auth0.js, but am wanting a direct example.

If this isn’t possible in Python, then is there an example of doing this in js? In which case I’d have to create a node app and get Python to call it.

As it is now, I’m manually logging in as a test user, then taking the access_token from my browser’s local storage to use in my tests.

Managed to answer my own question with:

But am unsure if enabling password grants is a bad idea.

Hi @dimitryvoew , great that you managed to moved forward a bit with that SO link…
Not sure if I’m stating the obvious, but for node have you checked this one? https://auth0.com/docs/libraries/auth0js/v9#ready-to-go-example Let me know your thoughts about it.

1 Like

Hey there!

Sorry for such huge delay in response! We’re doing our best in providing you with best developer support experience out there, but sometimes our bandwidth is not enough comparing to the number of incoming questions.

Wanted to reach out to know if you still require further assistance?