OptionalaccessCredentials that can be used by an application to access an API.
OptionalbuildBuilds the redirect URL that hands the STT to the target app's login endpoint.
Returns targetLoginUrl?session_transfer_token=<encoded>[&organization=…].
The developer passes the returned URL to res.redirect().
const url = req.oidc.buildSessionTransferRedirect('https://app.example.com/login', result, {
organization: 'org_globex',
});
res.redirect(url);
The targetLoginUrl must be a trusted, app-controlled value — never derive it
from untrusted input such as a query parameter, as the STT would be forwarded to
an attacker-controlled host. The URL must use https: (http: is accepted only
for localhost, 127.0.0.1, and [::1] to support local development); any other
scheme or non-loopback http: host throws a TypeError.
OptionalcustomPerforms a token exchange (RFC 8693) using the token endpoint.
app.get('/api', requiresAuth(), async (req, res) => {
const tokenSet = await req.oidc.customTokenExchange({
audience: 'https://downstream-api.example.com',
});
res.json({ access_token: tokenSet.access_token });
});
Errors thrown:
subject_token could not be
resolved (no session or no access token). err.error contains the OAuth error codeerr.error === 'mfa_required'Vendor-specific parameters must be passed via extra.
OptionalidThe OpenID Connect ID Token.
OptionalidAn object containing all the claims of the ID Token.
Method to check the user's authenticated state, returns true if logged in.
OptionalrefreshCredentials that can be used to refresh an access token.
OptionalrequestRequests a Session Transfer Token (STT) for impersonation via session transfer.
Performs a CTE call against the urn:{domain}:session_transfer audience.
The agent's session id_token is used as the actor automatically (refreshed if expired);
pass actor_token to override.
The returned STT is opaque and single-use (~60s). Pass it to
buildSessionTransferRedirect — never decode or store it.
app.post('/impersonate', requiresAuth(), async (req, res) => {
const result = await req.oidc.requestSessionTransferToken({
subject_token: req.body.customerToken,
subject_token_type: 'urn:mycompany:customer-subject',
extra: { reason: 'Investigating ticket TCK-1234' },
});
res.redirect(req.oidc.buildSessionTransferRedirect('https://app.example.com/login', result));
});
Errors thrown:
error: 'actor_unavailable' (HTTP 400) — no actor resolved (agent not authenticated or session expired with no refresh token)error: 'setactor_required' (HTTP 400) — CTE Action did not call setActorerror: 'session_transfer_disabled' (HTTP 400) — tenant feature flag is offerror: 'invalid_token_response' (HTTP 500) — AS returned an unexpected issued_token_type (not the STT URN)OptionaluserAn object containing all the claims of the ID Token with the claims specified in identityClaimFilter removed.
The request authentication context found on the Express request when OpenID Connect auth middleware is added to your application.