1. Install dependencies
2. Configure your App
Minimal Configuration
3. Set up CORS (for frontend integration)
If your frontend runs on a different domain/port, configure CORS to enable cross-origin cookie sharing: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 default5. 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 session7. 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:
Advanced Configuration
For more advanced use cases, you can include additional optional parameters in your configuration:Parameter | Required | Description |
---|---|---|
clientId | Yes | Client ID from auth.civic.com |
redirectUrl | Yes | OAuth callback URL where Civic redirects after authentication |
postLogoutRedirectUrl | No | Where to redirect users after logout |
loginSuccessUrl | No | Redirect Single Page Applications back to frontend after successful authentication |
oauthServer | No | OAuth server URL (useful for development/testing environments) |
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.