Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ta i bruk @navikt/oasis #1203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"dependencies": {
"@navikt/arbeidsgiver-notifikasjoner-brukerapi-mock": "^6.2.2",
"@navikt/nav-dekoratoren-moduler": "^2.1.5",
"@navikt/oasis": "^3.2.2",
"axios": "^1.6.7",
"express-async-handler": "1.2.0",
"express-http-proxy": "^2.0.0",
"helmet": "^7.1.0",
"http-proxy-middleware": "^2.0.1",
"jsdom": "^24.0.0",
"openid-client": "^5.4.0"
"jsdom": "^24.0.0"
},
"devDependencies": {
"@types/express": "^4.17.17",
Expand Down
60 changes: 0 additions & 60 deletions server/src/login/azure.ts

This file was deleted.

43 changes: 0 additions & 43 deletions server/src/login/loginProvider.ts

This file was deleted.

55 changes: 0 additions & 55 deletions server/src/login/tokenx.ts

This file was deleted.

64 changes: 21 additions & 43 deletions server/src/proxy/api-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
import tokenx from '../login/tokenx';
import azure from '../login/azure';
import { requestOboToken } from '../auth';

Check failure on line 1 in server/src/proxy/api-proxy.ts

View workflow job for this annotation

GitHub Actions / Bygg og deploy

Cannot find module '../auth' or its corresponding type declarations.
import { Express } from 'express';
import { BaseClient } from 'openid-client';
import { Request } from 'express-serve-static-core';
import { createProxyMiddleware } from 'http-proxy-middleware';
import proxy from 'express-http-proxy';
import { ParsedQs } from 'qs';

const tokenxSetup = (app: Express, tokenxClient: BaseClient): void => {
const tokenxSetup = (app: Express): void => {
console.log('api-proxy setup for tokenx');

setupPath(app);

app.use(
'/tiltaksgjennomforing/api',
proxy(process.env.APIGW_URL as string, {
proxyReqPathResolver: (req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
return req.originalUrl.replace('/tiltaksgjennomforing/api', '/tiltaksgjennomforing-api');
},
proxyReqOptDecorator: async (options: any, req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
const accessToken = await tokenx.getTokenExchangeAccessToken(
tokenxClient,
process.env.API_AUDIENCE,
req,
);
options.headers.Authorization = `Bearer ${accessToken}`;
return options;
},
}),
);
setup(app, process.env.API_AUDIENCE!);
};

const azureSetup = (app: Express, azureClient: BaseClient, azureTokenEndpoint: any): void => {
const azureSetup = (app: Express): void => {
console.log('api-proxy setup for azure');

setupPath(app);

app.use(
'/tiltaksgjennomforing/api',
proxy(process.env.APIGW_URL as string, {
proxyReqPathResolver: (req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
return req.originalUrl.replace('/tiltaksgjennomforing/api', '/tiltaksgjennomforing-api');
},
proxyReqOptDecorator: async (options: any, req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
const accessToken = await azure.getOnBehalfOfAccessToken(azureClient, azureTokenEndpoint, req);
options.headers.Authorization = `Bearer ${accessToken}`;
return options;
},
}),
);
setup(app, process.env.API_SCOPE!);
};

function setupPath(app: Express) {
const setup = (app: Express, audience: string) => {
app.use('/tiltaksgjennomforing/api/internal', (req, res) => {
res.status(401).send();
});
Expand All @@ -74,6 +38,20 @@
proxyTimeout: 10000,
}),
);
}

app.use(
'/tiltaksgjennomforing/api',
proxy(process.env.APIGW_URL as string, {
proxyReqPathResolver: (req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
return req.originalUrl.replace('/tiltaksgjennomforing/api', '/tiltaksgjennomforing-api');
},
proxyReqOptDecorator: async (options: any, req: Request<{}, any, any, ParsedQs, Record<string, any>>) => {
const accessToken = await requestOboToken(audience, req);
options.headers.Authorization = `Bearer ${accessToken}`;
return options;
},
}),
);
};

export default { tokenxSetup, azureSetup };
7 changes: 3 additions & 4 deletions server/src/proxy/decorator-intern-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import proxy from 'express-http-proxy';
import onbehalfof from '../login/azure';
import { BaseClient } from 'openid-client';
import { Express, Response } from 'express';
import { Request } from 'express-serve-static-core';
import { ParsedQs } from 'qs';
import { IncomingMessage, RequestOptions } from 'http';
import { requestOboToken } from '../auth';

Check failure on line 6 in server/src/proxy/decorator-intern-proxy.ts

View workflow job for this annotation

GitHub Actions / Bygg og deploy

Cannot find module '../auth' or its corresponding type declarations.

const setup = (app: Express, azureClient: BaseClient, azureTokenEndpoint: BaseClient) => {
const setup = (app: Express) => {
app.use(
'/modiacontextholder/api/decorator',
proxy(process.env.APIGW_URL as string, {
Expand All @@ -20,7 +19,7 @@
options: RequestOptions,
req: Request<{}, any, any, ParsedQs, Record<string, any>>,
) => {
const accessToken = await onbehalfof.getOnBehalfOfAccessToken(azureClient, azureTokenEndpoint, req);
const accessToken = await requestOboToken(process.env.API_SCOPE!, req);
if (options?.headers) {
options.headers.Authorization = `Bearer ${accessToken}`;
let cookies = options.headers.cookie;
Expand Down
Loading
Loading