Skip to content

Commit 2bf2658

Browse files
committed
OLH-3862 add route
1 parent d351e3d commit 2bf2658

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

deploy/template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,8 @@ Resources:
916916
- Name: "AMC_JWKS_URL"
917917
Value:
918918
!FindInMap [EnvironmentVariables, !Ref Environment, AMCJWKSURL]
919+
- Name: "JWKS_BUCKET_NAME"
920+
Value: !Ref JwksBucket
919921
Cpu: !FindInMap [Container, !Ref Environment, CPU]
920922
Memory: !FindInMap [Container, !Ref Environment, Memory]
921923
ExecutionRoleArn: !GetAtt TaskExecutionRole.Arn
@@ -1077,6 +1079,11 @@ Resources:
10771079
- "kms:DescribeKey"
10781080
Resource:
10791081
- !GetAtt SigningKmsKey.Arn
1082+
- Effect: Allow
1083+
Action:
1084+
- "s3:GetObject"
1085+
Resource:
1086+
- !Sub "${JwksBucket.Arn}/jwks.json"
10801087
- Effect: Allow
10811088
Action:
10821089
- "kms:GenerateDataKey*"

src/app.constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ export const PATH_DATA: Record<
179179
THANKS_TXT: {
180180
url: "/.well-known/thanks.txt",
181181
},
182+
JWKS_JSON: {
183+
url: "/.well-known/jwks.json",
184+
},
182185
TRACK_AND_REDIRECT: {
183186
url: "/track-and-redirect",
184187
},

src/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { switchBackupMethodRouter } from "./components/switch-backup-method/swit
7474
import { changeDefaultMethodRouter } from "./components/change-default-method/change-default-method-routes";
7575
import { logoutRedirectRouter } from "./components/logout-redirect/logout-redirect-routes";
7676
import { isUserLoggedInMiddleware } from "./middleware/is-user-logged-in-middleware";
77+
import { jwksRouter } from "./components/jwks/jwks-routes";
7778
import { applyOverloadProtection } from "./middleware/overload-protection-middleware";
7879
import { frontendVitalSignsInit } from "@govuk-one-login/frontend-vital-signs";
7980
import { Server } from "node:http";
@@ -242,6 +243,7 @@ async function createApp(): Promise<express.Application> {
242243
app.use(authMiddleware(getOIDCConfig()));
243244

244245
app.use(backchannelLogoutRouter);
246+
app.use(jwksRouter);
245247
// Must be added to the app after the session is set up and before the routers
246248
app.use(csrfSynchronisedProtection);
247249

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Request, Response } from "express";
2+
import { s3Client } from "../../config/aws";
3+
import { GetObjectCommand } from "@aws-sdk/client-s3";
4+
import { HTTP_STATUS_CODES } from "../../app.constants";
5+
6+
export async function jwksGet(req: Request, res: Response): Promise<void> {
7+
try {
8+
const response = await s3Client.getClient().send(
9+
new GetObjectCommand({
10+
Bucket: process.env.JWKS_BUCKET_NAME,
11+
Key: "jwks.json",
12+
})
13+
);
14+
15+
const jwks = await response.Body?.transformToString();
16+
res.setHeader("Content-Type", "application/json");
17+
res.status(HTTP_STATUS_CODES.OK).send(jwks);
18+
} catch (error) {
19+
req.log.error(`Failed to fetch JWKS: ${error}`);
20+
res.status(HTTP_STATUS_CODES.INTERNAL_SERVER_ERROR).send("Internal Server Error");
21+
}
22+
}

src/components/jwks/jwks-routes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PATH_DATA } from "../../app.constants";
2+
import * as express from "express";
3+
import { jwksGet } from "./jwks-controller";
4+
5+
const router = express.Router();
6+
7+
router.get(PATH_DATA.JWKS_JSON.url, jwksGet);
8+
9+
export { router as jwksRouter };

0 commit comments

Comments
 (0)