I've declared my own security manager and inside of this I was trying to use a before_request to check and then redirect to the login page if the session had expire for the app. However, every time the session is expired and the before request runs and tries to redirect the app I get a ERR_TOO_MANY_REDIRECTS error. I understand why there are too many redirects (because the before request redirects for every request made), so I have tried alternatives such as after_this_request, but this returns the same result. I'm convinced my problem lies within the use of the before request, however I have not come across an alternative solution as of yet.
Below is one of the many combinations of code I have tried:
def before_request(self):
logging.error(session)
if 'oauth' not in session:
logging.error("Stopping")
redirect_url = request.url_root.strip('/') + self.appbuilder.get_url_for_login
return redirect('https://.../logout redirect_uri=' + quote(redirect_url))
@after_this_request
def relogin(response):
if not current_user.is_authenticated():
logging.error("Not Authorized")
return response
else:
logging.error(session['oauth'])
g.user = current_user