Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 79c592c

Browse files
sandhosebabolivier
andauthored
Deprecate the generate_short_term_login_token method in favor of an async create_login_token method in the Module API. (#13842)
Signed-off-by: Quentin Gliech <[email protected]> Co-authored-by: Brendan Abolivier <[email protected]>
1 parent f6f6bdc commit 79c592c

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

changelog.d/13842.removal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Deprecate the `generate_short_term_login_token` method in favor of an async `create_login_token` method in the Module API.

docs/upgrade.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ you may specify `enable_legacy_metrics: false` in your homeserver configuration.
128128
A list of affected metrics is available on the [Metrics How-to page](https://matrix-org.github.io/synapse/v1.69/metrics-howto.html?highlight=metrics%20deprecated#renaming-of-metrics--deprecation-of-old-names-in-12).
129129

130130

131+
## Deprecation of the `generate_short_term_login_token` module API method
132+
133+
The following method of the module API has been deprecated, and is scheduled to
134+
be remove in v1.71.0:
135+
136+
```python
137+
def generate_short_term_login_token(
138+
self,
139+
user_id: str,
140+
duration_in_ms: int = (2 * 60 * 1000),
141+
auth_provider_id: str = "",
142+
auth_provider_session_id: Optional[str] = None,
143+
) -> str:
144+
...
145+
```
146+
147+
It has been replaced by an asynchronous equivalent:
148+
149+
```python
150+
async def create_login_token(
151+
self,
152+
user_id: str,
153+
duration_in_ms: int = (2 * 60 * 1000),
154+
auth_provider_id: Optional[str] = None,
155+
auth_provider_session_id: Optional[str] = None,
156+
) -> str:
157+
...
158+
```
159+
160+
Synapse will log a warning when a module uses the deprecated method, to help
161+
administrators find modules using it.
162+
163+
131164
# Upgrading to v1.68.0
132165

133166
Two changes announced in the upgrade notes for v1.67.0 have now landed in v1.68.0.

synapse/module_api/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,40 @@ def record_user_external_id(
748748
)
749749
)
750750

751+
async def create_login_token(
752+
self,
753+
user_id: str,
754+
duration_in_ms: int = (2 * 60 * 1000),
755+
auth_provider_id: Optional[str] = None,
756+
auth_provider_session_id: Optional[str] = None,
757+
) -> str:
758+
"""Create a login token suitable for m.login.token authentication
759+
760+
Added in Synapse v1.69.0.
761+
762+
Args:
763+
user_id: gives the ID of the user that the token is for
764+
765+
duration_in_ms: the time that the token will be valid for
766+
767+
auth_provider_id: the ID of the SSO IdP that the user used to authenticate
768+
to get this token, if any. This is encoded in the token so that
769+
/login can report stats on number of successful logins by IdP.
770+
771+
auth_provider_session_id: The session ID got during login from the SSO IdP,
772+
if any.
773+
"""
774+
# The deprecated `generate_short_term_login_token` method defaulted to an empty
775+
# string for the `auth_provider_id` because of how the underlying macaroon was
776+
# generated. This will change to a proper NULL-able field when the tokens get
777+
# moved to the database.
778+
return self._hs.get_macaroon_generator().generate_short_term_login_token(
779+
user_id,
780+
auth_provider_id or "",
781+
auth_provider_session_id,
782+
duration_in_ms,
783+
)
784+
751785
def generate_short_term_login_token(
752786
self,
753787
user_id: str,
@@ -759,6 +793,9 @@ def generate_short_term_login_token(
759793
760794
Added in Synapse v1.9.0.
761795
796+
This was deprecated in Synapse v1.69.0 in favor of create_login_token, and will
797+
be removed in Synapse 1.71.0.
798+
762799
Args:
763800
user_id: gives the ID of the user that the token is for
764801
@@ -768,6 +805,11 @@ def generate_short_term_login_token(
768805
to get this token, if any. This is encoded in the token so that
769806
/login can report stats on number of successful logins by IdP.
770807
"""
808+
logger.warn(
809+
"A module configured on this server uses ModuleApi.generate_short_term_login_token(), "
810+
"which is deprecated in favor of ModuleApi.create_login_token(), and will be removed in "
811+
"Synapse 1.71.0",
812+
)
771813
return self._hs.get_macaroon_generator().generate_short_term_login_token(
772814
user_id,
773815
auth_provider_id,

0 commit comments

Comments
 (0)