@sviy/authglue
v1.0.8
Published
OIDC auth glue for Express apps
Readme
@sviy/authglue
OIDC authentication glue for Express apps.
Wraps into a single setup call :
openid-client and
express-session
Your app redirects to any OIDC provider, handles the callback, creates a session, and gives you back req.session.user.
No auth boilerplate per app.
Install
npm install @sviy/authglueDependencies
- openid-client — OIDC client library
- express-session — session middleware
- @sequencemedia/session-file-store — file-based session store
Known Socket Alerts
Socket.dev reports a "Uses eval" alert from [email protected],
a transitive dependency of express-session. This is a false positive —
depd uses the Function constructor for deprecation wrapper generation,
not eval() on external input. depd is used by 142M weekly downloads
across the Express ecosystem and has no known vulnerabilities.
Usage
import express from 'express';
import { setupAuth } from '@sviy/authglue';
const app = express();
const requireAuth = await setupAuth(app, {
issuerUrl: process.env.IDP_ISSUER,
clientId: process.env.IDP_CLIENT_ID,
clientSecret: process.env.IDP_CLIENT_SECRET,
callbackUrl: `${process.env.HOST}/callback`,
sessionSecret: process.env.SESSION_SECRET,
sessionPath: '/app/data/.session',
originUrl: process.env.CLOUDRON_APP_ORIGIN,
secure: true,
successRedirect: '/dashboard',
postLogoutUrl: '/',
});
app.get('/dashboard', requireAuth, (req, res) => {
res.render('dashboard', { user: req.session.user });
});
app.listen(3000);Behind a reverse proxy (Cloudron, nginx, etc.) add app.set('trust proxy', 1)
before setupAuth. Without it Express reports http as the protocol and the
callback URL built during the code exchange is wrong.
sessionPath must point at a persistent, writable directory — under Cloudron
use /app/data/, which survives restarts and is included in backups.
Configuration
| Field | Required | Description |
|---|---|---|
| issuerUrl | Yes | OIDC provider issuer URL (e.g. https://rauthy.example.com) |
| clientId | Yes | Client ID registered with the OIDC provider |
| clientSecret | Yes | Client secret registered with the OIDC provider |
| callbackUrl | Yes | Redirect URI registered with the provider |
| sessionSecret | Yes | Secret used to sign session cookies |
| sessionPath | No | Where to persist session files. Default: ./sessions |
| sessionTtl | No | Session lifetime in seconds. The cookie and the stored session both use it, and it is a sliding window. Default: 2592000 (30 days) |
| originUrl | No | Absolute origin of this app (e.g. CLOUDRON_APP_ORIGIN). Required to resolve a relative postLogoutUrl |
| scopes | No | OIDC scopes to request. Default: openid profile email |
| secure | No | Set true to enable Secure cookies (requires HTTPS). Default: false |
| loginPath | No | Route that triggers login. Default: /login |
| callbackPath | No | Route the provider redirects to. Default: /callback |
| logoutPath | No | Route that triggers logout. Default: /logout |
| postLogoutUrl | No | Where the IdP sends the user after logout. Must be absolute, or relative to originUrl |
| successRedirect | No | Where to send the user after successful login. Default: / |
How It Works
- User visits a protected route without a session
requireAuthredirects to/loginauthgluegenerates PKCE verifier + state, redirects to the OIDC provider- User authenticates at the provider (password, passkey, 2FA — whatever the provider supports)
- Provider redirects back to
/callback authglueexchanges the authorization code for tokens, creates an Express session- User is redirected to
successRedirectwithreq.session.userpopulated
Provider-Agnostic
Works with any OIDC-compatible provider:
- Rauthy
- Autentico
- Pocket ID
- Keycloak
- Zitadel
- Auth0
- Okta
- Any other OIDC provider
Switching providers means changing issuerUrl, clientId, and clientSecret. Nothing else.
What This Package Does Not Do
- Does not store users or passwords — that's the IdP's job
- Does not provide an admin UI or login page — the IdP renders those
- Does not implement OIDC protocol details —
openid-clientdoes that - Does not handle 2FA or passkeys — the IdP handles those
This package is the glue between your Express app and your OIDC provider. Nothing more.
License
MIT No responsibility, liability ro warranty. Use at your risk.
