File tree Expand file tree Collapse file tree 5 files changed +43
-0
lines changed
Expand file tree Collapse file tree 5 files changed +43
-0
lines changed Original file line number Diff line number Diff 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*"
Original file line number Diff line number Diff 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 } ,
Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ import { switchBackupMethodRouter } from "./components/switch-backup-method/swit
7474import { changeDefaultMethodRouter } from "./components/change-default-method/change-default-method-routes" ;
7575import { logoutRedirectRouter } from "./components/logout-redirect/logout-redirect-routes" ;
7676import { isUserLoggedInMiddleware } from "./middleware/is-user-logged-in-middleware" ;
77+ import { jwksRouter } from "./components/jwks/jwks-routes" ;
7778import { applyOverloadProtection } from "./middleware/overload-protection-middleware" ;
7879import { frontendVitalSignsInit } from "@govuk-one-login/frontend-vital-signs" ;
7980import { 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 } ;
You can’t perform that action at this time.
0 commit comments