Build and Secure a FastAPI Server with Auth0

Hi @tepeit, glad you enjoyed the tutorial.

It is true that it would be possible to optimize the number of calls to retrieve the jwks, however, the caching method should be evaluated on a project basis.

For example, Auth0 supports signing key rotation triggered by tenant admins, and your cache system should retrieve the latest values otherwise newly created tokens won’t be accepted, and the old ones, which should be deprecated would still work while your cache is up.

There are other examples, and use cases that our colleague Nicolas explains well on this thread: Caching JWKS signing key

In the sample code you provided, there seems to be no way to update the cache other than restarting the app, you may wanna evaluate that for your needs.

Thanks again for your response, and looking forward to reading how you decided to go about caching for your app, and seeing more Auth0 implementations for FastAPI, such a fantastic framework!