Skip to content

Commit f1f6f06

Browse files
committed
Allow hiding NoSuchUser error
1 parent 9398b9a commit f1f6f06

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/quickstart.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The following configuration values exist for Flask-Multipass:
5454
``MULTIPASS_FAILURE_CATEGORY`` Category of message when flashing after unsuccessful login
5555
``MULTIPASS_ALL_MATCHING_IDENTITIES`` If true, all matching identities are passed after successful authentication
5656
``MULTIPASS_REQUIRE_IDENTITY`` If true, ``IdentityRetrievalFailed`` is raised when no matching identities are found, otherwise empty list is passed
57+
``MULTIPASS_HIDE_NO_SUCH_USER`` If true, ``InvalidCredentials`` instead of ``NoSuchUser`` is raised when no user is found in the system
5758
====================================== =========================================
5859

5960
A configuration example can be found here: :ref:`config_example`

flask_multipass/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
from werkzeug.exceptions import NotFound
1313

1414
from flask_multipass.auth import AuthProvider
15-
from flask_multipass.exceptions import GroupRetrievalFailed, IdentityRetrievalFailed, MultipassException
15+
from flask_multipass.exceptions import (
16+
GroupRetrievalFailed,
17+
IdentityRetrievalFailed,
18+
InvalidCredentials,
19+
MultipassException,
20+
NoSuchUser,
21+
)
1622
from flask_multipass.identity import IdentityProvider
1723
from flask_multipass.util import (
1824
get_canonical_provider_map,
@@ -72,6 +78,7 @@ def init_app(self, app):
7278
app.config.setdefault('MULTIPASS_FAILURE_CATEGORY', 'error')
7379
app.config.setdefault('MULTIPASS_ALL_MATCHING_IDENTITIES', False)
7480
app.config.setdefault('MULTIPASS_REQUIRE_IDENTITY', True)
81+
app.config.setdefault('MULTIPASS_HIDE_NO_SUCH_USER', False)
7582
with app.app_context():
7683
self._create_login_rule()
7784
state.auth_providers = ImmutableDict(self._create_providers('AUTH', AuthProvider))
@@ -528,6 +535,8 @@ def handle_login_form(self, provider, data):
528535
try:
529536
response = provider.process_local_login(data)
530537
except MultipassException as e:
538+
if isinstance(e, NoSuchUser) and current_app.config['MULTIPASS_HIDE_NO_SUCH_USER']:
539+
e = InvalidCredentials(e.provider)
531540
self.handle_auth_error(e)
532541
else:
533542
return response

0 commit comments

Comments
 (0)