Last active
August 8, 2018 20:20
-
-
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."
This file contains 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
"""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