Skip to main content

API reference

The public surface of

@thunderid/express, as documented in its reference pages.

middlewareThunderID Middleware

The `thunderID()` function returns Express middleware that initializes a `ThunderIDExpressClient` and attaches it to both `req.thunderIDAuth` and `res.thunderIDAuth`.

Example
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignIn, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(
thunderID({
baseUrl: 'https://localhost:8090',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
}),
);
app.get('/login', handleSignIn());
app.get('/logout', handleSignOut());
middlewarehandleFlow()

The `handleFlow()` function returns an Express route handler that advances the embedded sign-in flow and responds with JSON.

Example
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleFlow, handleSignIn, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(express.json());
app.use(
thunderID({
baseUrl: 'https://localhost:8090',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
mode: 'embedded',
}),
);
app.post('/flow/sign-in', handleFlow());
app.get('/login', handleSignIn());
app.get('/logout', handleSignOut());
middlewarehandleSignIn()

The `handleSignIn()` function returns an Express route handler for the sign-in path.

Example
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignIn} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(
thunderID({
baseUrl: 'https://localhost:8090',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignInUrl: 'http://localhost:3000/login',
}),
);
app.get('/login', handleSignIn());
middlewarehandleSignOut()

The `handleSignOut()` function returns an Express route handler for the sign-out path.

Example
const express = require('express');
const cookieParser = require('cookie-parser');
const {thunderID, handleSignOut} = require('@thunderid/express');
const app = express();
app.use(cookieParser());
app.use(
thunderID({
baseUrl: 'https://localhost:8090',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignOutUrl: 'http://localhost:3000/logout',
}),
);
app.get('/logout', handleSignOut());
middlewareprotect()

The `protect()` function returns Express middleware that blocks unauthenticated requests.

Example
const {protect} = require('@thunderid/express');
app.get('/protected', protect(), (_req, res) => {
res.send('Protected content');
});
classThunderIDExpressClient

`ThunderIDExpressClient` is the Express-aware client class exported by `@thunderid/express`. It extends `ThunderIDNodeClient` and adds Express-specific request and configuration access.

Example
const {ThunderIDExpressClient} = require('@thunderid/express');
exportExpressClientConfig

`ExpressClientConfig` is the main configuration type for `@thunderid/express`.

Example
const {thunderID} = require('@thunderid/express');
app.use(
thunderID({
baseUrl: 'https://localhost:8090',
clientId: '<your-client-id>',
clientSecret: '<your-client-secret>',
afterSignInUrl: 'http://localhost:3000/login',
afterSignOutUrl: 'http://localhost:3000/logout',
sessionCookie: {
expiryTime: 28800,
httpOnly: true,
sameSite: 'lax',
secure: false,
},
}),
);
exportCookieConfig

The Express SDK exports `CookieConfig` and `SESSION_COOKIE_NAME` for the session cookie behavior used by the SDK.

Example
const {SESSION_COOKIE_NAME} = require('@thunderid/express');
app.get('/session-id', (req, res) => {
res.json({sessionId: req.cookies?.[SESSION_COOKIE_NAME] ?? null});
});
ThunderID LogoThunderID Logo

Product

DocsAPIsSDKs
© Copyright Linux Foundation Europe.For web site terms of use, trademark policy and other project policies please see https://linuxfoundation.eu/en/policies.