FastAPI
The FastApi starter kit leverages the oneloop-python
SDK under the hood, but provides a helpful middleware that can be used for verifying API keys.
You can fork the starter kit repo, or copy the middleware from it.
If you haven’t already, create an account with Oneloop. Here is the link to our QuickStart Guide to help you get started.
Installation
To learn more about the this SDK, you can visit the Python SDK documentation.
Usage
Middleware
Let’s first add the middleware that will be used to verify the API key. This will save you from having to write the same code in every route.
Authenticate the API key
Now, let’s use the middleware in a FastApi route and authenticate the API key.
Checking for permissions
You can also check for permissions in your routes. Let’s say you have a route that requires a specific read access for profile data. You want to check if the API key has the required scope before returning the data. You can pass that scope to the middleware.
Let’s modify the above route to check for profile
read access.