Skip to content

Instantly share code, notes, and snippets.

@Sh1Yo

Sh1Yo/main.py Secret

Last active July 24, 2022 12:59
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 Sh1Yo/26dfb6f9da34312b6f849a10933a335f to your computer and use it in GitHub Desktop.
Save Sh1Yo/26dfb6f9da34312b6f849a10933a335f to your computer and use it in GitHub Desktop.
example jwt python3 web app
# the packages flask and pyjwt are required for this application.
from flask import request, abort, Flask
import jwt
app = Flask(__name__)
secret = "secret_key"
@app.route("/")
def root():
if "Authorization" in request.headers:
data = jwt.decode(request.headers["Authorization"], secret, algorithms="HS256")
return "Your role is %s" % data["role"]
else:
return "Your jwt token is %s" % jwt.encode({"role": "user"}, secret, algorithm="HS256")
app.run(host='0.0.0.0', port=2222)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment