File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 11import { APIGatewayProxyEvent } from "aws-lambda" ;
2+ import { generateJwks } from "./utils/generate-jwks" ;
3+
24
35export const handler = async ( event : APIGatewayProxyEvent ) => {
46 if ( event . path === "/status" ) {
@@ -8,6 +10,17 @@ export const handler = async (event: APIGatewayProxyEvent) => {
810 } ;
911 }
1012
13+ if ( event . path === "/.well-known/jwks.json" && event . httpMethod === "GET" ) {
14+ const jwks = await generateJwks ( ) ;
15+ return {
16+ statusCode : 200 ,
17+ headers : {
18+ "Content-Type" : "application/json" ,
19+ } ,
20+ body : JSON . stringify ( jwks ) ,
21+ } ;
22+ }
23+
1124 return {
1225 statusCode : 404 ,
1326 body : JSON . stringify ( { error : "Not Found" } ) ,
Original file line number Diff line number Diff line change 1+ import * as jose from "jose" ;
2+ import { randomUUID } from "node:crypto" ;
3+
4+ let cachedJWK : unknown | null = null ;
5+
6+ export async function generateJwks ( ) {
7+ if ( cachedJWK ) {
8+ return cachedJWK ;
9+ }
10+
11+ const { publicKey } = await jose . generateKeyPair ( "RSA-OAEP-256" ) ;
12+
13+ const publicJwk = await jose . exportJWK ( publicKey ) ;
14+
15+ cachedJWK = {
16+ keys : [
17+ {
18+ ...publicJwk ,
19+ kid : randomUUID ( ) ,
20+ alg : "RSA-OAEP-256" ,
21+ use : "enc" ,
22+ } ,
23+ ] ,
24+ } ;
25+
26+ return cachedJWK ;
27+ }
Original file line number Diff line number Diff line change @@ -1380,6 +1380,13 @@ Resources:
13801380 Method : GET
13811381 RestApiId :
13821382 Ref : AmcStubsRestApi
1383+ jwks :
1384+ Type : Api
1385+ Properties :
1386+ Path : /.well-known/jwks.json
1387+ Method : GET
1388+ RestApiId :
1389+ Ref : AmcStubsRestApi
13831390 VpcConfig :
13841391 SubnetIds :
13851392 - Fn::ImportValue : !Sub ${VpcStackName}-PrivateSubnetIdA
You can’t perform that action at this time.
0 commit comments