diff --git a/future-sir-frontend/app/.server/routes/dev/oidc-provider.tsx b/future-sir-frontend/app/.server/routes/dev/oidc-provider.tsx index 9f10b94..d7346eb 100644 --- a/future-sir-frontend/app/.server/routes/dev/oidc-provider.tsx +++ b/future-sir-frontend/app/.server/routes/dev/oidc-provider.tsx @@ -6,7 +6,6 @@ import { randomUUID } from 'node:crypto'; import { setTimeout } from 'node:timers'; import type { Route } from './+types/oidc-provider'; -import type { ServerEnvironment } from '~/.server/express/environment'; import type { TokenSet } from '~/utils/auth/authentication-strategy'; type AuthCode = string; @@ -89,8 +88,8 @@ export async function loader({ context, params, request }: Route.LoaderArgs) { /** * see: https://openid.net/specs/openid-connect-core-1_0.html#AuthorizationEndpoint */ -async function handleAuthorizeRequest({ context, request }: Route.LoaderArgs): Promise { - const config = getConfig(context.environment.server); +async function handleAuthorizeRequest({ request }: Route.LoaderArgs): Promise { + const config = getConfig(new URL(request.url)); const searchParams = new URL(request.url).searchParams; @@ -162,8 +161,8 @@ async function handleAuthorizeRequest({ context, request }: Route.LoaderArgs): P /** * see: https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderConfig */ -function handleMetadataRequest({ context }: Route.LoaderArgs): Response { - const { issuer } = getConfig(context.environment.server); +function handleMetadataRequest({ request }: Route.LoaderArgs): Response { + const { issuer } = getConfig(new URL(request.url)); return Response.json({ authorization_endpoint: `${issuer}/authorize`, @@ -192,8 +191,8 @@ async function handleJwksRequest(): Promise { /** * see: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint */ -async function handleTokenRequest({ context, request }: Route.LoaderArgs): Promise { - const config = getConfig(context.environment.server); +async function handleTokenRequest({ request }: Route.LoaderArgs): Promise { + const config = getConfig(new URL(request.url)); const formData = await request.formData(); @@ -262,12 +261,12 @@ function handleUserinfoRequest(): Response { /** * Get the OIDC configuration. */ -function getConfig(environment: ServerEnvironment): OidcConfig { +function getConfig(currentUrl: URL): OidcConfig { return { - issuer: `http://localhost:${environment.PORT}/auth/oidc`, + issuer: new URL('/auth/oidc', currentUrl.origin).toString(), clientId: '00000000-0000-0000-0000-000000000000', clientSecret: '00000000-0000-0000-0000-000000000000', - allowedRedirectUris: [`http://localhost:${environment.PORT}/auth/callback/local`], + allowedRedirectUris: [new URL('/auth/callback/local', currentUrl.origin).toString()], }; } diff --git a/future-sir-frontend/app/routes/auth/callback.tsx b/future-sir-frontend/app/routes/auth/callback.tsx index 5d4423d..49723f4 100644 --- a/future-sir-frontend/app/routes/auth/callback.tsx +++ b/future-sir-frontend/app/routes/auth/callback.tsx @@ -46,14 +46,14 @@ export async function loader({ context, params, request }: Route.LoaderArgs) { } case 'local': { - const { ENABLE_DEVMODE_OIDC, PORT } = environment.server; + const { ENABLE_DEVMODE_OIDC } = environment.server; if (!ENABLE_DEVMODE_OIDC) { throw Response.json(null, { status: 404 }); } const authStrategy = new LocalAuthenticationStrategy( - new URL(`http://localhost:${PORT}/auth/oidc`), + new URL('/auth/oidc', currentUrl.origin), new URL(`/auth/callback/${provider}`, currentUrl.origin), '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', diff --git a/future-sir-frontend/app/routes/auth/login.tsx b/future-sir-frontend/app/routes/auth/login.tsx index ca8deb3..595cf4e 100644 --- a/future-sir-frontend/app/routes/auth/login.tsx +++ b/future-sir-frontend/app/routes/auth/login.tsx @@ -53,14 +53,14 @@ export async function loader({ context, params, request }: Route.LoaderArgs) { } case 'local': { - const { ENABLE_DEVMODE_OIDC, PORT } = environment.server; + const { ENABLE_DEVMODE_OIDC } = environment.server; if (!ENABLE_DEVMODE_OIDC) { throw Response.json(null, { status: 404 }); } const authStrategy = new LocalAuthenticationStrategy( - new URL(`http://localhost:${PORT}/auth/oidc`), + new URL('/auth/oidc', currentUrl.origin), new URL(`/auth/callback/${provider}`, currentUrl.origin), '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000',