Skip to content

Commit

Permalink
Add optional argument to MultiAuth class (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwri committed Nov 16, 2020
1 parent f18fb02 commit e3c6e5f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions flask_httpauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit e3c6e5f

Please sign in to comment.