File tree Expand file tree Collapse file tree 3 files changed +13
-0
lines changed Expand file tree Collapse file tree 3 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ class AuthProvider(metaclass=SupportsMeta):
30
30
#: form in your application, specify a :class:`~flask_wtf.Form`
31
31
#: here (usually containing a username/email and a password field).
32
32
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
33
37
34
38
def __init__ (self , multipass , name , settings ):
35
39
self .multipass = multipass
@@ -113,5 +117,11 @@ def process_logout(self, return_url):
113
117
"""
114
118
return None
115
119
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
+
116
126
def __repr__ (self ):
117
127
return f'<{ type (self ).__name__ } ({ self .name } )>'
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ class SQLAlchemyAuthProviderBase(AuthProvider):
30
30
31
31
#: The :class:`~flask_wtf.Form` that is used for the login dialog
32
32
login_form = LoginForm
33
+ #: The field name in the login form that contains the identifier
34
+ identifier_field_name = LoginForm .identifier .name
33
35
#: The Flask-SQLAlchemy model representing a user identity
34
36
identity_model = None
35
37
#: The column of the identity model that contains the provider
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class StaticAuthProvider(AuthProvider):
33
33
"""
34
34
35
35
login_form = StaticLoginForm
36
+ identifier_field_name = StaticLoginForm .username .name
36
37
37
38
def __init__ (self , * args , ** kwargs ):
38
39
super ().__init__ (* args , ** kwargs )
You can’t perform that action at this time.
0 commit comments