example jwt python3 web app
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
# 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