Skip to content

Instantly share code, notes, and snippets.

@alsmola
Created February 3, 2020 04:37
Show Gist options
  • Save alsmola/7e5de01da28929ea573320285654509f to your computer and use it in GitHub Desktop.
Save alsmola/7e5de01da28929ea573320285654509f to your computer and use it in GitHub Desktop.
Verifies ALB token from Cognito
// Get OIDC JWT from headers
const encodeJwt = req.headers["x-amzn-oidc-data"];
const jwtHeaders = encodeJwt.split(".")[0];
const decodedJwtHeaders = Buffer.from(jwtHeaders, "base64");
const decodedJson = JSON.parse(decodedJwtHeaders);
const kid = decodedJson["kid"];
// Lookup ALB public key for JWT
const region = "us-east-1";
const url = `https://public-keys.auth.elb.${region}.amazonaws.com/${kid}`;
request(url, (error, response, body) => {
jwt.verify(encodeJwt, body, {algorithms: ["ES256"]}, (err, decoded) => {
// We should have a valid token, except for https://github.com/brianloveswords/node-jws/pull/84
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment