You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Express.js](https://expressjs.com/) is a popular and powerful framework for building the backend of web applications. In a traditional setup, often called a "Backend for Frontend" (BFF), your Express server manages both your application's logic and renders the web pages that users see.
3
+
[Express](https://expressjs.com/) is a fast, unopinionated, minimalist web framework for Node.js. It provides a robust set of features for web and mobile applications, making it one of the most popular choices for building server-side applications. In a modern setup, your Express application manages both your application's frontend and backend logic through server-side routes and middleware.
4
4
5
-
To secure such an application, you need a reliable way to handle user logins. For the Express ecosystem, [Passport.js](http://www.passportjs.org/) is the standard and recommended middleware for authentication. Think of it as a flexible security guard for your app. This guide demonstrates how to use Passport.js with an Express v5 application to implement a secure login with ZITADEL.
5
+
To secure such an application, you need a reliable way to handle user logins. For the Express ecosystem, [Auth.js](https://authjs.dev/)(formerly NextAuth.js) is the standard and recommended library for authentication. Think of it as a flexible security guard for your app. This guide demonstrates how to use Auth.js with an Express application to implement a secure login with ZITADEL.
6
6
7
7
We'll be using the **OpenID Connect (OIDC)** protocol with the **Authorization Code Flow + PKCE**. This is the industry-best practice for security, ensuring that the login process is safe from start to finish. You can learn more in our [guide to OAuth 2.0 recommended flows](https://zitadel.com/docs/guides/integrate/login/oidc/oauth-recommended-flows).
8
8
9
-
This example uses **Passport.js**, the standard for Express.js authentication. While ZITADEL doesn't offer a specific SDK, Passport.js is highly modular. It works with a "strategy" that handles the communication with ZITADEL. Under the hood, this example uses the powerful [`openid-client`](https://github.com/panva/node-openid-client) library to manage the secure OIDC PKCE flow.
9
+
This example uses **Auth.js**, the standard for Express authentication. While ZITADEL doesn't offer a specific SDK, Auth.js is highly modular. It works with a "provider" that handles the communication with ZITADEL. Under the hood, this example uses the powerful OIDC standard to manage the secure PKCE flow.
10
10
11
11
Check out our Example Application to see it in action.
12
12
13
13
## Example Application
14
14
15
-
The example repository includes a complete Express.js application, ready to run, that demonstrates how to integrate ZITADEL for user authentication.
15
+
The example repository includes a complete Express application, ready to run, that demonstrates how to integrate ZITADEL for user authentication.
16
16
17
-
This example application showcases a typical web app authentication pattern: users start on a public landing page, click a login button to authenticate with ZITADEL, and are then redirected to a protected profile page displaying their user information. The app also includes secure logout functionality that clears the session and redirects users back to ZITADEL's logout endpoint. All protected routes are automatically secured using Passport.js middleware, ensuring only authenticated users can access sensitive areas of your application.
17
+
This example application showcases a typical web app authentication pattern: users start on a public landing page, click a login button to authenticate with ZITADEL, and are then redirected to a protected profile page displaying their user information. The app also includes secure logout functionality that clears the session and redirects users back to ZITADEL's logout endpoint. All protected routes are automatically secured using Auth.js middleware and session management, ensuring only authenticated users can access sensitive areas of your application.
18
18
19
19
### Prerequisites
20
20
@@ -23,6 +23,7 @@ Before you begin, ensure you have the following:
23
23
#### System Requirements
24
24
25
25
- Node.js (v20 or later is recommended)
26
+
- npm, yarn, or pnpm package manager
26
27
27
28
#### Account Setup
28
29
@@ -31,13 +32,13 @@ You'll need a ZITADEL account and application configured. Follow the [ZITADEL do
31
32
> **Important:** Configure the following URLs in your ZITADEL application settings:
> These URLs must exactly match what your Express application uses. For production, add your production URLs.
37
38
38
39
### Configuration
39
40
40
-
To run the application, you first need to copy the `.env.example` file to a new file named `.env` and fill in your ZITADEL application credentials.
41
+
To run the application, you first need to copy the `.env.example` file to a new file named `.env.local` and fill in your ZITADEL application credentials.
41
42
42
43
```dotenv
43
44
# Port number where your Express server will listen for incoming HTTP requests.
The application will now be running at `http://localhost:3000`.
101
106
107
+
## Key Features
108
+
109
+
### PKCE Authentication Flow
110
+
111
+
The application implements the secure Authorization Code Flow with PKCE (Proof Key for Code Exchange), which is the recommended approach for modern web applications.
112
+
113
+
### Session Management
114
+
115
+
Built-in session management with Auth.js handles user authentication state across your application, with automatic token refresh and secure session storage.
116
+
117
+
### Route Protection
118
+
119
+
Protected routes automatically redirect unauthenticated users to the login flow, ensuring sensitive areas of your application remain secure.
120
+
121
+
### Logout Flow
122
+
123
+
Complete logout implementation that properly terminates both the local session and the ZITADEL session, with proper redirect handling.
124
+
102
125
## TODOs
103
126
104
-
### 1. Security headers (Helmet)
127
+
### 1. Security headers (Express middleware)
128
+
129
+
**Not enabled.** Consider adding security headers middleware in your Express application:
105
130
106
-
**Not enabled yet.** Add [`helmet`](https://www.npmjs.com/package/helmet) before production:
0 commit comments