From 1d5c8cc0ddfcabfbf45333871c5cd047033ce8c7 Mon Sep 17 00:00:00 2001 From: Andreas Nordahl Date: Mon, 11 Mar 2024 08:01:26 +0100 Subject: [PATCH] add missing files. oopsie. --- server/src/auth.ts | 24 ++++++++++++++++++++++++ server/src/routes.ts | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 server/src/auth.ts create mode 100644 server/src/routes.ts diff --git a/server/src/auth.ts b/server/src/auth.ts new file mode 100644 index 000000000..01cb8fcb1 --- /dev/null +++ b/server/src/auth.ts @@ -0,0 +1,24 @@ +import * as oasis from '@navikt/oasis'; +import { IncomingMessage } from 'http'; + +export const requestOboToken = async (audience: string, req: IncomingMessage) => { + const token = oasis.getToken(req); + if (!token) { + // TODO: handle missing token + throw Error('missing token in req'); + } + + const validation = await oasis.validateToken(token); + if (!validation.ok) { + // TODO: handle validation error + throw validation.error; + } + + const obo = await oasis.requestOboToken(token, audience); + if (!obo.ok) { + // TODO: handle obo error + throw obo.error; + } + + return obo.token; +}; diff --git a/server/src/routes.ts b/server/src/routes.ts new file mode 100644 index 000000000..925228913 --- /dev/null +++ b/server/src/routes.ts @@ -0,0 +1,23 @@ +import { getMiljo, Miljo } from './paths/miljo'; +import labsProxy from './proxy/labs-proxy'; +import apiProxy from './proxy/api-proxy'; +import decoratorInternProxy from './proxy/decorator-intern-proxy'; +import notifikasjonProxy from './proxy/notifikasjoner-proxy'; +import decoratorEksternProxy from './proxy/decorator-ekstern-proxy'; +import { Express } from 'express'; + +export const setupRoutes = async (server: Express) => { + const miljo: Miljo = getMiljo(); + + if (miljo === Miljo.DEV_GCP || miljo === Miljo.PROD_GCP) { + apiProxy.azureSetup(server); + + if (process.env.INTERN_INGRESS) { + decoratorInternProxy.setup(server); + } else { + notifikasjonProxy.setup(server); + decoratorEksternProxy.setup(server); + } + } + labsProxy.setup(server); +};