Hono is a small, simple, and ultra-fast web framework for the Edges that works on Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Netlify, AWS Lambda, Lambda@Edge, and Node.js. This example demonstrates how to integrate Zitadel using the OAuth 2.0 PKCE flow to authenticate users securely and maintain sessions across your Hono application.
This example uses Auth.js (formerly NextAuth.js), the standard authentication library for modern web frameworks. Auth.js implements the OpenID Connect (OIDC) protocol with PKCE, performs secure token exchange, and provides session management helpers. The integration uses @hono/auth-js, the official Hono adapter for Auth.js, along with @auth/core which handles the core OIDC flows and the Zitadel provider.
This example showcases a complete web application authentication pattern with Hono and Zitadel. Users start on a public landing page, initiate authentication with Zitadel using the secure PKCE flow, and are redirected to a protected profile page displaying their user information after successful authentication. The application demonstrates several key features including sign-in with authorization code flow + PKCE, OAuth callback handling with secure session storage using JWT strategy, route protection through authentication middleware that guards sensitive pages, automatic token refresh to maintain long-lived sessions without requiring re-authentication, access to user profile information including OIDC standard claims and Zitadel-specific claims such as organization roles and metadata, and secure sign-out with federated logout that terminates both the local session and the Zitadel session through the end-session endpoint.
Before running this example, you need to create and configure a PKCE application in the ZITADEL Management Console. Follow the PKCE application setup guide to:
Note: Make sure to enable Dev Mode in the ZITADEL Management Console if you're using HTTP URLs during local development. For production, always use HTTPS URLs and disable Dev Mode.
Create a .env file (copy from .env.example) and configure it with the values from your Zitadel application. Use the exact environment variable names from the repository:
Your actual Zitadel instance URL (the Issuer from your instance settings)
The Client ID you copied when creating the application in the PKCE setup
The redirect URI you configured in the PKCE setup (must match exactly)
The post-logout redirect URI for handling logout callbacks
A strong random session secret (generate using: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
Note: While PKCE doesn't require a client secret for public clients, Auth.js requires a value for internal configuration. You can leave ZITADEL_CLIENT_SECRET empty or provide a random string.
Install dependencies using npm and start the development server:
npm installnpm run dev
The application will be running at http://localhost:3000. Visit the homepage to test the authentication flow.