Created
May 29, 2021 14:19
-
-
Save vimalloc/fa3333a1f70454efd424031fdae96ab6 to your computer and use it in GitHub Desktop.
app.py
This file contains hidden or 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
from flask import Flask | |
from flask import jsonify | |
from flask_jwt_extended import create_access_token | |
from flask_jwt_extended import get_jwt_identity | |
from flask_jwt_extended import jwt_required | |
from flask_jwt_extended import JWTManager | |
app = Flask(__name__) | |
app.config["JWT_SECRET_KEY"] = "super-secret" # Change this! | |
jwt = JWTManager(app) | |
@app.route("/login", methods=["POST"]) | |
def login(): | |
access_token = create_access_token(identity='example_user') | |
return jsonify(access_token=access_token) | |
@app.route("/hello", methods=["GET"]) | |
@jwt_required() | |
def hello(): | |
current_user = get_jwt_identity() | |
return jsonify(hello=current_user) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment