Auth0 Home Blog Docs

Obtain user access_token from Python for unit tests

tests
testing
access_token
python

#1

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.


#2

Managed to answer my own question with:
[https://stackoverflow.com/a/48554119/1758759][1]

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


#3

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.