Skip to content

Commit 70995fa

Browse files
committed
Bytter over til fakedings for lokal utvikling, siden cookie er fjernet fra token 4
1 parent 3bc0801 commit 70995fa

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,6 @@
228228
"webpack-cli": "^5.1.4",
229229
"webpack-merge": "^5.10.0",
230230
"webpack-plugin-serve": "^1.6.0"
231-
}
231+
},
232+
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
232233
}

src/backend/middlewares/tokenProxy.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const WONDERWALL_ID_TOKEN_HEADER = 'x-wonderwall-id-token';
1515
const attachToken = (applicationName: ApplicationName): RequestHandler => {
1616
return async (req: Request, res: Response, next: NextFunction) => {
1717
try {
18-
const authenticationHeader = await prepareSecuredRequest(req, applicationName);
19-
req.headers[AUTHORIZATION_HEADER] = authenticationHeader.authorization;
18+
const token = await prepareSecuredRequest(req, applicationName);
19+
req.headers[AUTHORIZATION_HEADER] = token;
2020
req.headers[WONDERWALL_ID_TOKEN_HEADER] = '';
2121
next();
2222
} catch (error) {
@@ -35,9 +35,9 @@ const harBearerToken = (authorization: string) => {
3535
return authorization.includes('Bearer ');
3636
};
3737

38-
const utledToken = (req: Request, authorization: string | undefined): string => {
38+
const utledToken = (authorization: string | undefined): string => {
3939
if (erLokalt()) {
40-
return req.cookies['localhost-idtoken'];
40+
throw Error('Lokal profil kan bruke fakedings direkte');
4141
} else if (authorization && harBearerToken(authorization)) {
4242
return authorization.split(' ')[1];
4343
} else {
@@ -48,19 +48,25 @@ const utledToken = (req: Request, authorization: string | undefined): string =>
4848
const prepareSecuredRequest = async (req: Request, applicationName: ApplicationName) => {
4949
logRequest(req, 'PrepareSecuredRequest', LOG_LEVEL.INFO);
5050
const { authorization } = req.headers;
51-
const token = utledToken(req, authorization);
5251
if (erLokalt()) {
53-
return {
54-
authorization: `Bearer ${token}`,
55-
};
52+
return await getFakedingsToken(applicationName);
5653
}
54+
const token = utledToken(authorization);
5755
logRequest(req, 'IdPorten-token found: ' + (token.length > 1), LOG_LEVEL.INFO);
5856
const accessToken = await exchangeToken(token, applicationName).then(
5957
accessToken => accessToken
6058
);
61-
return {
62-
authorization: `Bearer ${accessToken}`,
63-
};
59+
return `Bearer ${accessToken}`;
60+
};
61+
62+
const getFakedingsToken = async (applicationName: string): Promise<string> => {
63+
const clientId = 'dev-gcp:teamfamilie:familie-ks-soknad';
64+
const audience = `dev-gcp:teamfamilie:${applicationName}`;
65+
const url = `http://fakedings.intern.dev.nav.no/fake/tokenx?client_id=${clientId}&aud=${audience}&acr=Level4&pid=31458931375`;
66+
const token = await fetch(url).then(function (body) {
67+
return body.text();
68+
});
69+
return `Bearer ${token}`;
6470
};
6571

6672
export default attachToken;

src/backend/routes/api.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Miljø, { basePath } from '../../shared-utils/Miljø';
44
import { erklaeringInterceptor } from '../middlewares/erklaering-interceptor';
55
import { escapeBody } from '../middlewares/escape';
66
import { modellVersjonInterceptor } from '../middlewares/modell-versjon-interceptor';
7-
import { addCallId, doProxy, fjernAutentiseringHeaderHvisLokalt } from '../middlewares/proxy';
7+
import { addCallId, doProxy } from '../middlewares/proxy';
88
import attachToken from '../middlewares/tokenProxy';
99

1010
export const konfigurerApi = (app: Express): Express => {
@@ -24,7 +24,6 @@ export const konfigurerApi = (app: Express): Express => {
2424
`${basePath}dokument`,
2525
addCallId(),
2626
attachToken('familie-dokument'),
27-
fjernAutentiseringHeaderHvisLokalt(),
2827
doProxy(Miljø().dokumentUrl, `${basePath}dokument`)
2928
);
3029
return app;

src/shared-utils/Miljø.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ const Miljø = (): MiljøProps => {
6363
dokumentProxyUrl: `http://localhost:3000${basePath}dokument`,
6464
dokumentUrl: `http://localhost:8082/familie/dokument/api`,
6565
modellVersjon: modellVersjon,
66-
wonderwallUrl:
67-
'http://localhost:8080/local/cookie?issuerId=tokenx&audience=familie-app&cookiename=localhost-idtoken&subject=12345678901&redirect=',
66+
wonderwallUrl: '',
6867
oauthCallbackUri: `http://localhost:3000${basePath}`,
6968
port: 55554,
7069
};

0 commit comments

Comments
 (0)