Skip to content

Instantly share code, notes, and snippets.

@mtairu
Last active August 8, 2018 20:20
Show Gist options
  • Save mtairu/b6f8a86e050dc6c548e7622ffbc13b32 to your computer and use it in GitHub Desktop.
Save mtairu/b6f8a86e050dc6c548e7622ffbc13b32 to your computer and use it in GitHub Desktop.
RS256 Token Validation & Decoding using Public Key Not Working "ValueError: Could not deserialize key data."
"""Solution for decoding and verifying Amazon Cognito (JWK) issued tokens.
- NodeJS (jwk-to-pem) to convert jwk to pem
- PyJWT to decode and verify an access token
- pm install jwk-to-pem
- pipenv install pyjwt
- pipenv install cryptography
"""
#node
jwk = require("./jwk.json")
topem = require("jwk-to-pem")
pem = topem(jwk)
# then write to file
fs = require("fs")
fs.writeFile("key.pem", pem)
# Return to Python
f = open('./appname.pem').read()
#Decode and Verify using pyjwt
jwt.decode(atoken, f, algorithms='RS256', verify=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment