Auth0 Client Credential Flow for API Authentication

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 :slight_smile:

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

5 Likes

the clone link is busted .

I’ll try to update the link, but it seems as though I can’t open the IDE, so that could be the issue. I’ll update when that resolves.

EDIT

I believe it has to do this post:

Not the clone link itself.