Skip to content

Commit

Permalink
fix: broken dev OIDC provider
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-j-baker committed Dec 10, 2024
1 parent 260b069 commit 22ca9b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
19 changes: 9 additions & 10 deletions future-sir-frontend/app/.server/routes/dev/oidc-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<void> {
const config = getConfig(context.environment.server);
async function handleAuthorizeRequest({ request }: Route.LoaderArgs): Promise<void> {
const config = getConfig(new URL(request.url));

const searchParams = new URL(request.url).searchParams;

Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -192,8 +191,8 @@ async function handleJwksRequest(): Promise<Response> {
/**
* see: https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint
*/
async function handleTokenRequest({ context, request }: Route.LoaderArgs): Promise<Response> {
const config = getConfig(context.environment.server);
async function handleTokenRequest({ request }: Route.LoaderArgs): Promise<Response> {
const config = getConfig(new URL(request.url));

const formData = await request.formData();

Expand Down Expand Up @@ -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()],
};
}

Expand Down
4 changes: 2 additions & 2 deletions future-sir-frontend/app/routes/auth/callback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions future-sir-frontend/app/routes/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 22ca9b9

Please sign in to comment.