I'm running two instances of flask app. For security, I'm using flask-security
and flask-mongoengine
. Both api instances has to work as a node to a load balancer. Now when I login using the first api, I get an access token, now I'm trying to hit the second api using the access token which is giving unauthorized
status.
Now, I was wondering that is it possible to use same access token for both apis . Both api share same database, mongo config and security config. Code is below:
from flask import Flask,request, render_template,abort,jsonify
from flask_mongoengine import MongoEngine
from flask_security import Security, MongoEngineUserDatastore, \
UserMixin, RoleMixin, login_required,auth_token_required,roles_required, current_user
from flask_security.utils import logout_user
from flask_cors import CORS, cross_origin
import csv
import time
import hashlib
import datetime
import requests
import json
# Create app
app = Flask(__name__)
CORS(app)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'
app.config['SECURITY_PASSWORD_HASH'] = 'plaintext'
app.config['SECURITY_TRACKABLE'] = True
app.config['SECURITY_PASSWORD_SALT'] = 'somepaswwordsalt'
app.config['WTF_CSRF_ENABLED'] = False
# MongoDB Config
app.config['MONGODB_DB'] = 'db'
app.config['MONGODB_HOST'] = 'localhost'
app.config['MONGODB_PORT'] = 27017
app.config['MONGODB_USERNAME'] = 'username'
app.config['MONGODB_PASSWORD'] = 'password'
# Create database connection object
db = MongoEngine(app)
@app.route('/api/v1/',methods=['GET'])
@auth_token_required
@roles_required('admin')
def create():
......
......