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

Commit f25c75d

Browse files
authored
Rename unstable access_token_lifetime configuration option to refreshable_access_token_lifetime to make it clear it only concerns refreshable access tokens. (#11388)
1 parent 55669bd commit f25c75d

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

changelog.d/11388.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rename unstable `access_token_lifetime` configuration option to `refreshable_access_token_lifetime` to make it clear it only concerns refreshable access tokens.

synapse/config/registration.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,32 @@ def read_config(self, config, **kwargs):
112112
session_lifetime = self.parse_duration(session_lifetime)
113113
self.session_lifetime = session_lifetime
114114

115-
# The `access_token_lifetime` applies for tokens that can be renewed
115+
# The `refreshable_access_token_lifetime` applies for tokens that can be renewed
116116
# using a refresh token, as per MSC2918. If it is `None`, the refresh
117117
# token mechanism is disabled.
118118
#
119119
# Since it is incompatible with the `session_lifetime` mechanism, it is set to
120120
# `None` by default if a `session_lifetime` is set.
121-
access_token_lifetime = config.get(
122-
"access_token_lifetime", "5m" if session_lifetime is None else None
121+
refreshable_access_token_lifetime = config.get(
122+
"refreshable_access_token_lifetime",
123+
"5m" if session_lifetime is None else None,
123124
)
124-
if access_token_lifetime is not None:
125-
access_token_lifetime = self.parse_duration(access_token_lifetime)
126-
self.access_token_lifetime = access_token_lifetime
125+
if refreshable_access_token_lifetime is not None:
126+
refreshable_access_token_lifetime = self.parse_duration(
127+
refreshable_access_token_lifetime
128+
)
129+
self.refreshable_access_token_lifetime = refreshable_access_token_lifetime
127130

128-
if session_lifetime is not None and access_token_lifetime is not None:
131+
if (
132+
session_lifetime is not None
133+
and refreshable_access_token_lifetime is not None
134+
):
129135
raise ConfigError(
130136
"The refresh token mechanism is incompatible with the "
131137
"`session_lifetime` option. Consider disabling the "
132138
"`session_lifetime` option or disabling the refresh token "
133-
"mechanism by removing the `access_token_lifetime` option."
139+
"mechanism by removing the `refreshable_access_token_lifetime` "
140+
"option."
134141
)
135142

136143
# The fallback template used for authenticating using a registration token

synapse/handlers/register.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def __init__(self, hs: "HomeServer"):
116116
self.pusher_pool = hs.get_pusherpool()
117117

118118
self.session_lifetime = hs.config.registration.session_lifetime
119-
self.access_token_lifetime = hs.config.registration.access_token_lifetime
119+
self.refreshable_access_token_lifetime = (
120+
hs.config.registration.refreshable_access_token_lifetime
121+
)
120122

121123
init_counters_for_auth_provider("")
122124

@@ -817,7 +819,9 @@ class and RegisterDeviceReplicationServlet.
817819
user_id,
818820
device_id=registered_device_id,
819821
)
820-
valid_until_ms = self.clock.time_msec() + self.access_token_lifetime
822+
valid_until_ms = (
823+
self.clock.time_msec() + self.refreshable_access_token_lifetime
824+
)
821825

822826
access_token = await self._auth_handler.create_access_token_for_user_id(
823827
user_id,

synapse/rest/client/login.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def __init__(self, hs: "HomeServer"):
8181
self.saml2_enabled = hs.config.saml2.saml2_enabled
8282
self.cas_enabled = hs.config.cas.cas_enabled
8383
self.oidc_enabled = hs.config.oidc.oidc_enabled
84-
self._msc2918_enabled = hs.config.registration.access_token_lifetime is not None
84+
self._msc2918_enabled = (
85+
hs.config.registration.refreshable_access_token_lifetime is not None
86+
)
8587

8688
self.auth = hs.get_auth()
8789

@@ -453,7 +455,9 @@ class RefreshTokenServlet(RestServlet):
453455
def __init__(self, hs: "HomeServer"):
454456
self._auth_handler = hs.get_auth_handler()
455457
self._clock = hs.get_clock()
456-
self.access_token_lifetime = hs.config.registration.access_token_lifetime
458+
self.refreshable_access_token_lifetime = (
459+
hs.config.registration.refreshable_access_token_lifetime
460+
)
457461

458462
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
459463
refresh_submission = parse_json_object_from_request(request)
@@ -463,7 +467,9 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
463467
if not isinstance(token, str):
464468
raise SynapseError(400, "Invalid param: refresh_token", Codes.INVALID_PARAM)
465469

466-
valid_until_ms = self._clock.time_msec() + self.access_token_lifetime
470+
valid_until_ms = (
471+
self._clock.time_msec() + self.refreshable_access_token_lifetime
472+
)
467473
access_token, refresh_token = await self._auth_handler.refresh_token(
468474
token, valid_until_ms
469475
)
@@ -562,7 +568,7 @@ async def on_GET(self, request: SynapseRequest) -> None:
562568

563569
def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
564570
LoginRestServlet(hs).register(http_server)
565-
if hs.config.registration.access_token_lifetime is not None:
571+
if hs.config.registration.refreshable_access_token_lifetime is not None:
566572
RefreshTokenServlet(hs).register(http_server)
567573
SsoRedirectServlet(hs).register(http_server)
568574
if hs.config.cas.cas_enabled:

synapse/rest/client/register.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ def __init__(self, hs: "HomeServer"):
420420
self.password_policy_handler = hs.get_password_policy_handler()
421421
self.clock = hs.get_clock()
422422
self._registration_enabled = self.hs.config.registration.enable_registration
423-
self._msc2918_enabled = hs.config.registration.access_token_lifetime is not None
423+
self._msc2918_enabled = (
424+
hs.config.registration.refreshable_access_token_lifetime is not None
425+
)
424426

425427
self._registration_flows = _calculate_registration_flows(
426428
hs.config, self.auth_handler

tests/rest/client/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def test_token_refresh(self):
598598
refresh_response.json_body["refresh_token"],
599599
)
600600

601-
@override_config({"access_token_lifetime": "1m"})
601+
@override_config({"refreshable_access_token_lifetime": "1m"})
602602
def test_refresh_token_expiration(self):
603603
"""
604604
The access token should have some time as specified in the config.

0 commit comments

Comments
 (0)