I have a flask token authenticated application implemented by flask jwt extended.
Code
import random
import os
from flask import Flask, jsonify, request, session
from flask_cors import CORS
from flask_jwt_extended import create_access_token
from flask_jwt_extended import JWTManager
import json
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "some secret key"
jwt = JWTManager(app)
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
secret_email = "xxxx@gmail.com"
secret_pass = "password"
@app.route("/")
def home():
return jsonify({"msg":"Hello, World!"})
@app.route("/login", methods=["POST"])
def login():
email = request.json.get("email", None)
password = request.json.get("password", None)
if email != secret_email or password != secret_pass:
return jsonify({"msg": "Bad username or password"}), 401
access_token = create_access_token(identity=email)
return jsonify(access_token=access_token)
@app.route("/configs")
def configs():
a = random.randint(10,30)
b = random.randint(1,5)
summ = a+b
return jsonify({"a":a,"b":b})
@app.route("/sumcollect")
def sumcollect():
return jsonify({"sum is":summ})
if __name__ == "__main__":
app.run(debug=False)
The summ
variable in route /configs
needs to be accessed in route /sumcollect
. I tried with session variables. But the token authentication and session variables are not working together. Is there any way to pass the variables in this case.
Note: Just added django tag for this in case for them to look at to have a solution.