From e3c6e5fb0481c14c326460408c2d0d038adf7ddc Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Mon, 16 Nov 2020 09:44:04 +0000 Subject: [PATCH] Add optional argument to MultiAuth class (#115) --- flask_httpauth.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/flask_httpauth.py b/flask_httpauth.py index b524f82..9183feb 100644 --- a/flask_httpauth.py +++ b/flask_httpauth.py @@ -352,9 +352,11 @@ def __init__(self, main_auth, *args): self.main_auth = main_auth self.additional_auth = args - def login_required(self, f=None, role=None): - if f is not None and role is not None: # pragma: no cover - raise ValueError('role is the only supported argument') + def login_required(self, f=None, role=None, optional=None): + if f is not None and \ + (role is not None or optional is not None): # pragma: no cover + raise ValueError( + 'role and optional are the only supported arguments') def login_required_internal(f): @wraps(f) @@ -374,8 +376,9 @@ def decorated(*args, **kwargs): break if selected_auth is None: selected_auth = self.main_auth - return selected_auth.login_required(role=role)(f)( - *args, **kwargs) + return selected_auth.login_required(role=role, + optional=optional + )(f)(*args, **kwargs) return decorated if f: