Prefer AI-assisted setup? Use our AI prompts for Flask to automatically integrate Civic Auth using Claude, ChatGPT, or other AI assistants. Includes a step-by-step video tutorial!
Important: The SDK Handles EverythingThe Civic Auth Python SDK abstracts away all token validation complexity. You do NOT need to:
- Implement custom middleware for token validation
- Parse or validate JWT tokens manually
- Handle token refresh logic yourself
1. Install dependencies
uv
package manager:
2. Configure your App
Your app will need the following configuration: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
5. Protect Routes
Use thecivic_auth_required
decorator to protect routes:
6. Access User Information
Useget_civic_user()
to access the logged-in user as a dictionary:
Working with User Data
Theget_civic_user()
function returns a dictionary with user information. Always use .get()
for safe access:
Complete Example
Here’s a complete working Flask application:Configuration Options
Field | Required | Description |
---|---|---|
client_id | Yes | Your Civic Auth Client ID from auth.civic.com |
redirect_url | Yes | Where Civic redirects after authentication (must be absolute URL) |
post_logout_redirect_url | Yes | Where users go after logout (must be absolute URL) |
Note:
redirect_url
and post_logout_redirect_url
must be absolute URLs.Next Steps
- Get your Client ID: Sign up at auth.civic.com
- Replace
YOUR_CLIENT_ID
with your actual client ID - Update URLs when deploying to production
- Add more protected routes as needed
- Handle user data safely using
.get()
method for dictionary access
Authentication Flows
Civic Auth supports multiple OAuth 2.0 authentication methods to provide maximum security for different application architectures.Need client secret authentication? Civic Auth supports PKCE-only, client secrets, and hybrid PKCE + client secret approaches. See our Authentication Flows guide for detailed comparison.