{"id":50746990,"url":"https://github.com/zitadel/express-auth","last_synced_at":"2026-06-10T22:01:41.463Z","repository":{"id":360156335,"uuid":"1223583620","full_name":"zitadel/express-auth","owner":"zitadel","description":"Official Zitadel auth integration for Express.","archived":false,"fork":false,"pushed_at":"2026-06-08T13:43:40.000Z","size":888,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-08T15:27:48.341Z","etag":null,"topics":["auth","authentication","authn","authorization","authz","express","expressjs","iam","identity","login","nodejs","sso","typescript","zitadel"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@zitadel/express-auth","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zitadel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE.txt","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-28T13:11:13.000Z","updated_at":"2026-06-08T13:44:15.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zitadel/express-auth","commit_stats":null,"previous_names":["zitadel/express-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zitadel/express-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexpress-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexpress-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexpress-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexpress-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zitadel","download_url":"https://codeload.github.com/zitadel/express-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zitadel%2Fexpress-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34172196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","authn","authorization","authz","express","expressjs","iam","identity","login","nodejs","sso","typescript","zitadel"],"created_at":"2026-06-10T22:01:40.690Z","updated_at":"2026-06-10T22:01:41.447Z","avatar_url":"https://github.com/zitadel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Auth.js\n\nAn [Express](https://expressjs.com/) integration for [Auth.js](https://authjs.dev/)\nthat provides seamless authentication with multiple providers, session\nmanagement, and route protection using Express middleware patterns.\n\nThis integration brings the power and flexibility of Auth.js to Express\napplications with full TypeScript support and efficient HTTP handling.\n\n### Why?\n\nModern web applications require robust, secure, and flexible authentication\nsystems. While Auth.js provides excellent authentication capabilities,\nintegrating it with Express applications requires careful handling of\nrequest/response conversion and middleware composition.\n\nHowever, a direct integration isn't always straightforward. Different types\nof applications or deployment scenarios might warrant different approaches:\n\n- **HTTP Request Handling:** Express uses its own request/response format\n  which requires conversion to Web API standards used by Auth.js core.\n  This integration handles that conversion transparently while maintaining\n  proper encoding for different content types.\n- **Middleware Composition:** Express's middleware pattern requires proper\n  error handling and next() chaining. This integration composes body\n  parsing and authentication into a single middleware that works correctly\n  with Express's middleware pipeline.\n- **Session Management:** Proper session handling requires integration with\n  Express's request lifecycle. Manual integration often leads to\n  inconsistent session management across different routes.\n\nThis integration, `@zitadel/express-auth`, aims to provide the flexibility to\nhandle such scenarios. It allows you to leverage the full Auth.js ecosystem\nwhile maintaining Express best practices, ultimately leading to a more\neffective and less burdensome authentication implementation.\n\n## Installation\n\nInstall using NPM by using the following command:\n\n```sh\nnpm install @zitadel/express-auth @auth/core\n```\n\n## Usage\n\nTo use this integration, add the `ExpressAuth` middleware to your Express\napplication. The middleware handles all Auth.js routes including sign-in,\nsign-out, and callbacks.\n\nYou'll need to configure it with your Auth.js providers and options.\n\nFirst, add the middleware to your Express app:\n\n```typescript\nimport express from 'express';\nimport { ExpressAuth } from '@zitadel/express-auth';\nimport Zitadel from '@auth/core/providers/zitadel';\n\nconst app = express();\napp.set('trust proxy', true);\n\napp.use(\n  '/auth/*',\n  ExpressAuth({\n    providers: [\n      Zitadel({\n        clientId: process.env.ZITADEL_CLIENT_ID,\n        issuer: process.env.ZITADEL_ISSUER,\n      }),\n    ],\n    secret: process.env.AUTH_SECRET,\n    trustHost: true,\n  }),\n);\n```\n\n#### Using the Authentication System\n\nThe integration provides functions for handling authentication:\n\n**Functions:**\n\n- `ExpressAuth()`: Middleware that handles all Auth.js routes\n- `getSession()`: Retrieves the current Auth.js session from requests\n\n**Basic Usage:**\n\n```typescript\nimport { getSession } from '@zitadel/express-auth';\nimport type { Session } from '@auth/core/types';\n\n// Public route - no authentication needed\napp.get('/api/public', (req, res) =\u003e {\n  res.json({ message: 'Public endpoint' });\n});\n\n// Protected route - manual session check\napp.get('/api/profile', async (req, res) =\u003e {\n  const session = await getSession(req, authConfig);\n\n  if (!session) {\n    return res.status(401).json({ error: 'Unauthorized' });\n  }\n\n  res.json({\n    user: session.user,\n    expires: session.expires,\n  });\n});\n```\n\n##### Example: Advanced Configuration with Multiple Providers\n\nThis example shows how to use the middleware with multiple Auth.js\nproviders and custom session configuration:\n\n```typescript\nimport express from 'express';\nimport { ExpressAuth, getSession } from '@zitadel/express-auth';\nimport GoogleProvider from '@auth/core/providers/google';\nimport GitHubProvider from '@auth/core/providers/github';\n\nconst app = express();\napp.set('trust proxy', true);\n\nconst authConfig = {\n  providers: [\n    GoogleProvider({\n      clientId: process.env.GOOGLE_CLIENT_ID,\n      clientSecret: process.env.GOOGLE_CLIENT_SECRET,\n    }),\n    GitHubProvider({\n      clientId: process.env.GITHUB_CLIENT_ID,\n      clientSecret: process.env.GITHUB_CLIENT_SECRET,\n    }),\n  ],\n  secret: process.env.AUTH_SECRET,\n  trustHost: true,\n  session: {\n    strategy: 'jwt',\n    maxAge: 30 * 24 * 60 * 60, // 30 days\n  },\n  callbacks: {\n    jwt: async ({ token, user }) =\u003e {\n      if (user) {\n        token.roles = user.roles;\n      }\n      return token;\n    },\n    session: async ({ session, token }) =\u003e {\n      session.user.roles = token.roles as string[];\n      return session;\n    },\n  },\n};\n\napp.use('/auth/*', ExpressAuth(authConfig));\n\n// Authentication middleware\nasync function requireAuth(req, res, next) {\n  const session = await getSession(req, authConfig);\n  if (!session?.user) {\n    return res.redirect('/auth/signin?error=SessionRequired');\n  }\n  req.session = session;\n  next();\n}\n\n// Protected routes\napp.get('/api/user', requireAuth, (req, res) =\u003e {\n  res.json(req.session.user);\n});\n```\n\n## Known Issues\n\n- **Body Parsing:** The middleware automatically applies JSON and\n  URL-encoded body parsing. If you need custom body parsing, ensure\n  it is configured before the Auth.js middleware.\n- **Session Storage Configuration:** The integration relies on Auth.js\n  session handling mechanisms. When configuring custom session storage or\n  database adapters, ensure they are properly configured in the Auth.js\n  options passed to the middleware.\n\n## Useful links\n\n- **[Auth.js](https://authjs.dev/):** The authentication library that this\n  integration is built upon.\n- **[Express](https://expressjs.com/):** The Node.js framework this\n  integration is designed for.\n- **[Auth.js Providers](https://authjs.dev/getting-started/providers):**\n  Complete list of supported authentication providers.\n\n## Contributing\n\nIf you have suggestions for how this integration could be improved, or\nwant to report a bug, open an issue - we'd love all and any\ncontributions.\n\n## License\n\nApache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Fexpress-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzitadel%2Fexpress-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzitadel%2Fexpress-auth/lists"}