Skip to content

Instantly share code, notes, and snippets.

@Sh1Yo

Sh1Yo/main.py Secret

Last active Jul 24, 2022
Embed
What would you like to do?
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