Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active February 16, 2018 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaguiini/246329a7bb00d467650689ed2e65d7f5 to your computer and use it in GitHub Desktop.
Save zaguiini/246329a7bb00d467650689ed2e65d7f5 to your computer and use it in GitHub Desktop.
A simple JWT verification snippet
import jwt
secret = 'minha_super_chave_imprevisivel'
meu_jwt = request['headers']['authorization']
try:
informacoes = jwt.decode(meu_jwt, secret, algorithm='HS256')
except ExpiredSignatureError:
print('Seu token esta expirado!')
except DecodeError:
print('Token invalido ou segredo incorreto!')
except:
print('Outro erro!')
else:
print(informacoes['uid']) # 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment