Browse Source

fix(api): improve OIDC state store typing

pull/7630/head
KenTandrian 3 days ago
parent
commit
dbe15285db
  1. 29
      apps/api/src/app/auth/oidc-state.store.ts

29
apps/api/src/app/auth/oidc-state.store.ts

@ -1,17 +1,24 @@
import type { Request } from 'express';
import ms from 'ms'; import ms from 'ms';
import type {
SessionStore,
SessionStoreCallback,
SessionStoreContext,
SessionVerifyCallback
} from 'passport-openidconnect';
/** /**
* Custom state store for OIDC authentication that doesn't rely on express-session. * Custom state store for OIDC authentication that doesn't rely on express-session.
* This store manages OAuth2 state parameters in memory with automatic cleanup. * This store manages OAuth2 state parameters in memory with automatic cleanup.
*/ */
export class OidcStateStore { export class OidcStateStore implements SessionStore {
private readonly STATE_EXPIRY_MS = ms('10 minutes'); private readonly STATE_EXPIRY_MS = ms('10 minutes');
private stateMap = new Map< private stateMap = new Map<
string, string,
{ {
appState?: unknown; appState?: unknown;
ctx: { issued?: Date; maxAge?: number; nonce?: string }; ctx: SessionStoreContext;
meta?: unknown; meta?: unknown;
timestamp: number; timestamp: number;
} }
@ -22,11 +29,11 @@ export class OidcStateStore {
* Signature matches passport-openidconnect SessionStore * Signature matches passport-openidconnect SessionStore
*/ */
public store( public store(
_req: unknown, _req: Request,
_meta: unknown, ctx: SessionStoreContext,
appState: unknown, appState: unknown,
ctx: { maxAge?: number; nonce?: string; issued?: Date }, meta: unknown,
callback: (err: Error | null, handle?: string) => void callback: SessionStoreCallback
) { ) {
try { try {
// Generate a unique handle for this state // Generate a unique handle for this state
@ -35,7 +42,7 @@ export class OidcStateStore {
this.stateMap.set(handle, { this.stateMap.set(handle, {
appState, appState,
ctx, ctx,
meta: _meta, meta,
timestamp: Date.now() timestamp: Date.now()
}); });
@ -53,13 +60,9 @@ export class OidcStateStore {
* Signature matches passport-openidconnect SessionStore * Signature matches passport-openidconnect SessionStore
*/ */
public verify( public verify(
_req: unknown, _req: Request,
handle: string, handle: string,
callback: ( callback: SessionVerifyCallback
err: Error | null,
appState?: unknown,
ctx?: { maxAge?: number; nonce?: string; issued?: Date }
) => void
) { ) {
try { try {
const data = this.stateMap.get(handle); const data = this.stateMap.get(handle);

Loading…
Cancel
Save