Skip to content

Commit 083e90a

Browse files
committed
Retrieve user identifier from form data
1 parent 60905a6 commit 083e90a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

flask_multipass/auth.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class AuthProvider(metaclass=SupportsMeta):
3030
#: form in your application, specify a :class:`~flask_wtf.Form`
3131
#: here (usually containing a username/email and a password field).
3232
login_form = None
33+
#: The field name in the login form that contains the identifier.
34+
#: Useful to reliably retrieve identifier data in applications that use
35+
#: multiple auth providers.
36+
identifier_field_name = None
3337

3438
def __init__(self, multipass, name, settings):
3539
self.multipass = multipass
@@ -113,5 +117,11 @@ def process_logout(self, return_url):
113117
"""
114118
return None
115119

120+
def get_identifier(self, data):
121+
"""Get the user identifier from form data."""
122+
if self.identifier_field_name is None:
123+
raise NotImplementedError('No identifier field name set')
124+
return data.get(self.identifier_field_name)
125+
116126
def __repr__(self):
117127
return f'<{type(self).__name__}({self.name})>'

flask_multipass/providers/sqlalchemy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class SQLAlchemyAuthProviderBase(AuthProvider):
3030

3131
#: The :class:`~flask_wtf.Form` that is used for the login dialog
3232
login_form = LoginForm
33+
#: The field name in the login form that contains the identifier
34+
identifier_field_name = LoginForm.identifier.name
3335
#: The Flask-SQLAlchemy model representing a user identity
3436
identity_model = None
3537
#: The column of the identity model that contains the provider

flask_multipass/providers/static.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class StaticAuthProvider(AuthProvider):
3333
"""
3434

3535
login_form = StaticLoginForm
36+
identifier_field_name = StaticLoginForm.username.name
3637

3738
def __init__(self, *args, **kwargs):
3839
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)