fix: correctly passthrough and handle a new OIDC redirect_uri system

This commit is contained in:
Aarnav Tale
2025-12-04 10:34:48 -05:00
parent e09c5760af
commit 199ef46ee1
8 changed files with 124 additions and 47 deletions
+46
View File
@@ -0,0 +1,46 @@
import { createCookie } from 'react-router';
import type { HeadplaneConfig } from '~/server/config/config-schema';
export interface OidcStateCookie {
nonce: string;
state: string;
redirect_uri: string;
}
export function createOidcStateCookie(config: HeadplaneConfig) {
const cookie = createCookie('__oidc_state', {
httpOnly: true,
maxAge: 1800,
secure: config.server.cookie_secure,
domain: config.server.cookie_domain,
path: `${__PREFIX__}/oidc/callback`,
});
return {
...cookie,
serialize: async (value: OidcStateCookie): Promise<string> => {
return cookie.serialize(value);
},
parse: async (
cookieHeader: string | null,
): Promise<OidcStateCookie | null> => {
const parsed = await cookie.parse(cookieHeader);
if (
parsed == null ||
typeof parsed !== 'object' ||
typeof parsed.nonce !== 'string' ||
typeof parsed.state !== 'string' ||
typeof parsed.redirect_uri !== 'string'
) {
return null;
}
return {
nonce: parsed.nonce,
state: parsed.state,
redirect_uri: parsed.redirect_uri,
};
},
};
}