Skip to main content
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
Simply use the provided decorators and user access functions - the SDK handles all authentication logic for you.

1. Install dependencies

Or, if you’re using the uv package manager:

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 as a dictionary:

Working with User Data

The get_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

Note: redirect_url and post_logout_redirect_url must be absolute URLs.

Next Steps

  1. Get your Client ID: Sign up at auth.civic.com
  2. Replace YOUR_CLIENT_ID with your actual client ID
  3. Update URLs when deploying to production
  4. Add more protected routes as needed
  5. 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.
The examples above use PKCE authentication, which is handled entirely by the Civic Auth SDK and suitable for most applications.

Access Tokens

Retrieve tokens from session (or via a CivicAuth instance if exposed):