Created
February 3, 2020 04:37
-
-
Save alsmola/7e5de01da28929ea573320285654509f to your computer and use it in GitHub Desktop.
Verifies ALB token from Cognito
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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