Skip to main content

Express

Official

Middleware to protect Express routes and APIs with ThunderID.

Embedded Sign-In

~3 min

Use embedded sign-in when your application needs to advance the sign-in flow through JSON requests. Use it when you do not want to rely on a browser redirect for every interaction.

Embedded Sign-In

1

Prerequisites

- `express` - `cookie-parser` - `express.json()` - `mode: 'embedded'` in your Express SDK configuration

2

Middleware and Route Setup

index.js
js
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',
afterSignInUrl: 'http://localhost:3000/login',
afterSignOutUrl: 'http://localhost:3000/logout',
}),
);
app.post('/flow/sign-in', handleFlow());
app.get('/login', handleSignIn());
app.get('/logout', handleSignOut());
3

Request Lifecycle

### Start the Flow Send the first request without an `executionId`:

json
{
"applicationId": "app-id",
"flowType": "SIGN_IN"
}
4

Response Lifecycle

### Continue rendering UI If the flow still needs more steps, `handleFlow()` returns:

json
{
"authId": "...",
"challengeToken": "...",
"components": [],
"executionId": "...",
"flowStatus": "..."
}
5

How `GET /login` and `POST /flow/sign-in` Work Together

- `POST /flow/sign-in` advances the embedded interaction and eventually returns a redirect URL - `GET /login` completes the OAuth callback after the embedded flow returns the authorization code redirect Both routes are required for the embedded sign-in flow shown in the current SDK source.

6

Failure Cases

`handleFlow()` returns `500` JSON responses when: - the SDK is not initialized because `thunderID()` was not mounted first - `baseUrl` is missing from the config - flow execution fails at runtime

7

Related APIs

- [`handleFlow()`](../../apis/middleware/handle-flow) - [`handleSignIn()`](../../apis/middleware/handle-sign-in) - [`ExpressClientConfig`](../../apis/configuration/express-client-config)

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.