Skip to content

Instantly share code, notes, and snippets.

@vimalloc
Created May 29, 2021 14:19
Show Gist options
  • Save vimalloc/fa3333a1f70454efd424031fdae96ab6 to your computer and use it in GitHub Desktop.
Save vimalloc/fa3333a1f70454efd424031fdae96ab6 to your computer and use it in GitHub Desktop.
app.py
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