summary refs log tree commit diff
path: root/synapse/module_api/__init__.py
diff options
context:
space:
mode:
authorAndrew Morgan <1342360+anoadragon453@users.noreply.github.com>2021-04-28 10:07:20 +0100
committerGitHub <noreply@github.com>2021-04-28 10:07:20 +0100
commita5575ea3cf5a16ae2cf57e812e27cd657f1d220f (patch)
tree8c2ae84631994082ddf3ae28af475a65e0bc68bd /synapse/module_api/__init__.py
parentPort "Allow providing credentials to HTTPS_PROXY (#9657)" from mainline (#95) (diff)
parentRemove 3.6 old deps check (diff)
downloadsynapse-a5575ea3cf5a16ae2cf57e812e27cd657f1d220f.tar.xz
Merge pull request #97 from matrix-org/anoa/dinsic_release_1_31_0
Merge Synapse release v1.31.0 into dinsic
Diffstat (limited to 'synapse/module_api/__init__.py')
-rw-r--r--synapse/module_api/__init__.py52
1 files changed, 43 insertions, 9 deletions
diff --git a/synapse/module_api/__init__.py b/synapse/module_api/__init__.py

index 72ab5750cc..781e02fbbb 100644 --- a/synapse/module_api/__init__.py +++ b/synapse/module_api/__init__.py
@@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging -from typing import TYPE_CHECKING, Iterable, Optional, Tuple +from typing import TYPE_CHECKING, Any, Generator, Iterable, Optional, Tuple from twisted.internet import defer @@ -203,11 +203,26 @@ class ModuleApi: ) def generate_short_term_login_token( - self, user_id: str, duration_in_ms: int = (2 * 60 * 1000) + self, + user_id: str, + duration_in_ms: int = (2 * 60 * 1000), + auth_provider_id: str = "", ) -> str: - """Generate a login token suitable for m.login.token authentication""" + """Generate a login token suitable for m.login.token authentication + + Args: + user_id: gives the ID of the user that the token is for + + duration_in_ms: the time that the token will be valid for + + auth_provider_id: the ID of the SSO IdP that the user used to authenticate + to get this token, if any. This is encoded in the token so that + /login can report stats on number of successful logins by IdP. + """ return self._hs.get_macaroon_generator().generate_short_term_login_token( - user_id, duration_in_ms + user_id, + auth_provider_id, + duration_in_ms, ) @defer.inlineCallbacks @@ -275,11 +290,19 @@ class ModuleApi: redirect them directly if whitelisted). """ self._auth_handler._complete_sso_login( - registered_user_id, request, client_redirect_url, + registered_user_id, + "<unknown>", + request, + client_redirect_url, ) async def complete_sso_login_async( - self, registered_user_id: str, request: SynapseRequest, client_redirect_url: str + self, + registered_user_id: str, + request: SynapseRequest, + client_redirect_url: str, + new_user: bool = False, + auth_provider_id: str = "<unknown>", ): """Complete a SSO login by redirecting the user to a page to confirm whether they want their access token sent to `client_redirect_url`, or redirect them to that @@ -291,15 +314,23 @@ class ModuleApi: request: The request to respond to. client_redirect_url: The URL to which to offer to redirect the user (or to redirect them directly if whitelisted). + new_user: set to true to use wording for the consent appropriate to a user + who has just registered. + auth_provider_id: the ID of the SSO IdP which was used to log in. This + is used to track counts of sucessful logins by IdP. """ await self._auth_handler.complete_sso_login( - registered_user_id, request, client_redirect_url, + registered_user_id, + auth_provider_id, + request, + client_redirect_url, + new_user=new_user, ) @defer.inlineCallbacks def get_state_events_in_room( self, room_id: str, types: Iterable[Tuple[str, Optional[str]]] - ) -> defer.Deferred: + ) -> Generator[defer.Deferred, Any, defer.Deferred]: """Gets current state events for the given room. (This is exposed for compatibility with the old SpamCheckerApi. We should @@ -346,7 +377,10 @@ class ModuleApi: event, _, ) = await self._hs.get_event_creation_handler().create_and_send_nonmember_event( - requester, event_dict, ratelimit=False, ignore_shadow_ban=True, + requester, + event_dict, + ratelimit=False, + ignore_shadow_ban=True, ) return event