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

Commit a82b90a

Browse files
authored
Add type annotations to some of the configuration surrounding refresh tokens. (#11428)
1 parent 9cd13c5 commit a82b90a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

changelog.d/11428.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add type annotations to some of the configuration surrounding refresh tokens.

synapse/config/registration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from typing import Optional
1415

1516
from synapse.api.constants import RoomCreationPreset
1617
from synapse.config._base import Config, ConfigError
@@ -123,12 +124,14 @@ def read_config(self, config, **kwargs):
123124
refreshable_access_token_lifetime = self.parse_duration(
124125
refreshable_access_token_lifetime
125126
)
126-
self.refreshable_access_token_lifetime = refreshable_access_token_lifetime
127+
self.refreshable_access_token_lifetime: Optional[
128+
int
129+
] = refreshable_access_token_lifetime
127130

128131
refresh_token_lifetime = config.get("refresh_token_lifetime")
129132
if refresh_token_lifetime is not None:
130133
refresh_token_lifetime = self.parse_duration(refresh_token_lifetime)
131-
self.refresh_token_lifetime = refresh_token_lifetime
134+
self.refresh_token_lifetime: Optional[int] = refresh_token_lifetime
132135

133136
# The fallback template used for authenticating using a registration token
134137
self.registration_token_template = self.read_template("registration_token.html")

synapse/handlers/register.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,11 @@ class and RegisterDeviceReplicationServlet.
813813
access_token = self.macaroon_gen.generate_guest_access_token(user_id)
814814
else:
815815
if should_issue_refresh_token:
816+
# A refreshable access token lifetime must be configured
817+
# since we're told to issue a refresh token (the caller checks
818+
# that this value is set before setting this flag).
819+
assert self.refreshable_access_token_lifetime is not None
820+
816821
now_ms = self.clock.time_msec()
817822

818823
# Set the expiry time of the refreshable access token

0 commit comments

Comments
 (0)