From e9a3b3d5e3087dffe57a365511cbb68b964b34a1 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:34:51 -0700 Subject: [PATCH] move CustomBasicAuth override to import --- app/__init__.py | 21 +++++++++++---------- app/custom_auth.py | 16 +++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 76bf55333..2b7748d9c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -39,6 +39,7 @@ from werkzeug.local import LocalProxy from app import proxy_fix, webauthn_server from app.asset_fingerprinter import asset_fingerprinter from app.config import configs +from app.custom_auth import CustomBasicAuth from app.extensions import antivirus_client, redis_client, zendesk_client from app.formatters import ( convert_to_boolean, @@ -593,16 +594,16 @@ def init_jinja(application): jinja_loader = jinja2.FileSystemLoader(template_folders) application.jinja_loader = jinja_loader -class CustomBasicAuth(BasicAuth): - """ - Description: - Override BasicAuth to permit anonymous healthcheck at /_status?simple=true - """ - def challenge(self): - if "/_status" in request.url: - if request.args.get('elb', None) or request.args.get('simple', None): - return jsonify(status="ok"), 200 - return super(CustomBasicAuth, self).challenge() +# class CustomBasicAuth(BasicAuth): +# """ +# Description: +# Override BasicAuth to permit anonymous healthcheck at /_status?simple=true +# """ +# def challenge(self): +# if "/_status" in request.url: +# if request.args.get('elb', None) or request.args.get('simple', None): +# return jsonify(status="ok"), 200 +# return super(CustomBasicAuth, self).challenge() def setup_basic_auth(application): application.basic_auth = CustomBasicAuth(application) diff --git a/app/custom_auth.py b/app/custom_auth.py index 3989878c3..b8310cedb 100644 --- a/app/custom_auth.py +++ b/app/custom_auth.py @@ -3,15 +3,13 @@ from flask import jsonify, request class CustomBasicAuth(BasicAuth): """ - Description: - - Usage: - + Description: + Override BasicAuth to permit anonymous healthcheck at /_status?simple=true """ - - def check_credentials(self, username, password): - # here, for example, you can search user in the database by passed `username` and `password`, etc. - return username == 'user' and password == 'password' - + def challenge(self): + if "/_status" in request.url: + if request.args.get('elb', None) or request.args.get('simple', None): + return jsonify(status="ok"), 200 + return super(CustomBasicAuth, self).challenge() custom_basic_auth = CustomBasicAuth() \ No newline at end of file