Flask
Follow these simple steps to set up Civic Auth with a Flask backend (a working example is available in the github repo).
1. Install dependencies
2. Configure your App
Your app will need the following configuration:
Note: redirect_url
and post_logout_redirect_url
must be absolute URLs.
3. Initialize Civic Auth
Set up Civic Auth with your Flask app:
4. Login and Logout Routes
The auth blueprint automatically creates these routes:
/auth/login
- Initiates the login flow/auth/callback
- Handles the OAuth callback/auth/logout
- Logs the user out
You can redirect users to start the login process:
5. Protect Routes
Use the civic_auth_required
decorator to protect routes:
6. Access User Information
Use get_civic_user()
to access the logged-in user:
PKCE and Client Secrets
Civic Auth uses PKCE (Proof Key for Code Exchange), to protect users and clients from unauthorized access to user information. This, alongside domain registration for apps in production environments, mean that you don’t need to provide a client secret in your backend.
When using the Civic Auth SDK, PKCE is handled entirely by the library.