Zitadel setup guide
This guide walks you through setting up Zitadel authentication for your FastAPI application.
Set up as described
This is an opinionated setup for a demo application. Follow the steps exactly as described first. Adjust settings for your use case only after a successful implementation.
Project configuration
In your Zitadel console:
-
Create New Project, named
Demo project
-
After saving, in the project overview, under General, tick:
- Assert Roles on Authentication
- Check authorization on Authentication
-
Under Roles, create a new role (e.g., key =
admin
) -
Record the Project Id ("Resource Id") from the project overview. You'll need this for the
ZitadelAuth
object'sproject_id
parameter.
Applications
The project requires (at least) two applications:
- An API application for service-to-service authentication
- A User Agent application for human authentication via Swagger UI
Application 1: API
Create an API application for service authentication:
-
In the project overview, create a New Application:
- Type: API
- Name:
Demo API
(or your preferred name) - Authentication Method: Private Key JWT
-
After saving, record the Issuer URL from the app overview under URLs (e.g.,
https://myinstance.zitadel.cloud
). You'll need this for theZitadelAuth
object'sissuer_url
parameter.
Application 2: User Agent
Create a User Agent application to enable Swagger UI authentication:
-
In the project overview, create a New Application:
- Type: User Agent
- Name:
Swagger UI
(or your preferred name) - Authentication Method: PKCE
- Redirect URI:
http://localhost:8001/oauth2-redirect
(or your FastAPI app URL +/oauth2-redirect
) - Toggle Development Mode for non-HTTPS redirects
-
After saving, go to the app's Token Settings:
- Set "Auth Token Type" to JWT
- Enable Add user roles to access token
- Enable User roles inside ID token
-
Record the client Id from the overview. You'll need this for the
ZitadelAuth
object'sapp_client_id
parameter.
Users
Create two user accounts with the admin
role (or your chosen role):
- A human user for interactive access
- A service user for automated processes
For more information, see Zitadel user types.
User 1: Human User
-
Create a New User:
- Name:
Admin User
(or your preferred name) - Enable Email Verified for testing
- Name:
-
Under Authorizations:
- Create new authorization
- Select your project (e.g., "Demo Project")
- Assign your role (e.g.,
admin
)
User 2: Service User
-
Create a New Service User:
- Username:
Admin Bot
(or your preferred name) - Access Token Type: JWT
- Username:
-
Under Authorizations:
- Create new authorization
- Select your project (e.g., "Demo Project")
- Assign your role (e.g.,
admin
)
-
Under Keys:
- Create a new JSON key
- Download and secure the key file
- Update the key file path in
demo_project/service_user.py
Configuration complete
By now, you should have recorded the following information:
- Project Id
- Issuer URL
- API application client Id