Skip to main content

1. Install dependencies

2. Configure your App

Minimal Configuration

Note: All URLs must be absolute URLs.

3. Set up CORS (for frontend integration)

If your frontend runs on a different domain/port, configure CORS to enable cross-origin cookie sharing:
Important: Cross-origin cookies (different ports/domains) require HTTPS to work properly. For local development with separate frontend/backend ports, use ngrok or similar service to create HTTPS tunnels:
The cookie storage automatically detects HTTPS and sets secure: true + sameSite: "none" for cross-origin compatibility. Without HTTPS, cross-origin cookies will not be saved by the browser.

4. Set up Cookies

Civic Auth uses cookies for storing the login state by default

5. Create a Login Endpoint

This endpoint will handle login requests, build the Civic login URL and redirect the user to it.

6. Create the Callback Endpoint

This endpoint handles successful logins and creates the session

7. Create a Logout Endpoint

This endpoint will handle logout requests, build the Civic logout URL and redirect the user to it.

8. Add Middleware

Middleware protects routes that require login.

9. Use the Session

If needed, get the logged-in user information.

10. Frontend Integration (Vanilla JavaScript)

Use the @civic/auth/vanillajs client with your backend:
Add this endpoint to expose login URLs:

Advanced Configuration

For more advanced use cases, you can include additional optional parameters in your configuration:

PKCE and Client Secrets

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.