Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active February 16, 2018 02:04
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/a5957d3a77b6be0b5dfc3046262fc03f to your computer and use it in GitHub Desktop.
Save zaguiini/a5957d3a77b6be0b5dfc3046262fc03f to your computer and use it in GitHub Desktop.
A simple JWT generation snippet
import jwt
from time import time # para geracao da timestamp
secret = 'minha_super_chave_imprevisivel'
user_id = 123
payload = {
'uid': user_id,
'exp': int(time()) + 3600 # queremos que o token seja valido por uma hora
}
meu_token_assinado = jwt.encode(payload, secret, algorithm='HS256')
# exemplo: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEyMywiZXhwIjoxNTE4NzQ5OTg1fQ.-uUCFwVFhpg57Jig9VwWh86f85Uip4lPvF4iL6nxjbA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment