I was working on adding some security to my API’s and wanted to use the client credential grant flow for machine to machine communication.
I tweak auth0’s example and made it work in an anvil application
Here is the auth0 documentation:
Requesting a token
Client Credential Flow
Python Example
I pieced together some things to get the job done without flask.
Here is the clone:
https://anvil.works/build#clone:T4KBEMDJGL3WXOVY=QNJS5ZFAQYGDYM4F7WGWTNCU
NOTE
I am using the BETA capabilities to install your own libraries on python 3.10, but the libraries you need are python-jose and six which are already installed in the standard production anvil server!
Example usage:
from .utils import requires_auth
@anvil.server.http_endpoint("/auth_test/")
@requires_auth
def test_auth():
return {"test-string":"It was successful!"}
Where requires_auth is a wrapper that authenticates auth0 Bearer tokens!
All you have to update are the application secrets:
DOMAIN
API_AUDIENCE
ISSUER