-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}; |