This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support 3PID login in password providers (#4931)
Adds a new method, check_3pid_auth, which gives password providers the chance to allow authentication with third-party identifiers such as email or msisdn.
- Loading branch information
1 parent
903f04c
commit bbd244c
Showing
8 changed files
with
137 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add ability for password providers to login/register a user via 3PID (email, phone). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,20 @@ Password auth provider classes may optionally provide the following methods. | |
result from the ``/login`` call (including ``access_token``, ``device_id``, | ||
etc.) | ||
|
||
``someprovider.check_3pid_auth``\(*medium*, *address*, *password*) | ||
|
||
This method, if implemented, is called when a user attempts to register or | ||
log in with a third party identifier, such as email. It is passed the | ||
medium (ex. "email"), an address (ex. "[email protected]") and the user's | ||
password. | ||
|
||
The method should return a Twisted ``Deferred`` object, which resolves to | ||
a ``str`` containing the user's (canonical) User ID if authentication was | ||
successful, and ``None`` if not. | ||
|
||
As with ``check_auth``, the ``Deferred`` may alternatively resolve to a | ||
``(user_id, callback)`` tuple. | ||
|
||
``someprovider.check_password``\(*user_id*, *password*) | ||
|
||
This method provides a simpler interface than ``get_supported_login_types`` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -745,6 +745,42 @@ def validate_login(self, username, login_submission): | |
errcode=Codes.FORBIDDEN | ||
) | ||
|
||
@defer.inlineCallbacks | ||
def check_password_provider_3pid(self, medium, address, password): | ||
"""Check if a password provider is able to validate a thirdparty login | ||
Args: | ||
medium (str): The medium of the 3pid (ex. email). | ||
address (str): The address of the 3pid (ex. [email protected]). | ||
password (str): The password of the user. | ||
Returns: | ||
Deferred[(str|None, func|None)]: A tuple of `(user_id, | ||
callback)`. If authentication is successful, `user_id` is a `str` | ||
containing the authenticated, canonical user ID. `callback` is | ||
then either a function to be later run after the server has | ||
completed login/registration, or `None`. If authentication was | ||
unsuccessful, `user_id` and `callback` are both `None`. | ||
""" | ||
for provider in self.password_providers: | ||
if hasattr(provider, "check_3pid_auth"): | ||
# This function is able to return a deferred that either | ||
# resolves None, meaning authentication failure, or upon | ||
# success, to a str (which is the user_id) or a tuple of | ||
# (user_id, callback_func), where callback_func should be run | ||
# after we've finished everything else | ||
result = yield provider.check_3pid_auth( | ||
medium, address, password, | ||
) | ||
if result: | ||
# Check if the return value is a str or a tuple | ||
if isinstance(result, str): | ||
# If it's a str, set callback function to None | ||
result = (result, None) | ||
defer.returnValue(result) | ||
|
||
defer.returnValue((None, None)) | ||
|
||
@defer.inlineCallbacks | ||
def _check_local_password(self, user_id, password): | ||
"""Authenticate a user against the local password database. | ||
|
@@ -756,7 +792,8 @@ def _check_local_password(self, user_id, password): | |
user_id (unicode): complete @user:id | ||
password (unicode): the provided password | ||
Returns: | ||
(unicode) the canonical_user_id, or None if unknown user / bad password | ||
Deferred[unicode] the canonical_user_id, or Deferred[None] if | ||
unknown user/bad password | ||
Raises: | ||
LimitExceededError if the ratelimiter's login requests count for this | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters