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

Commit 1890cfc

Browse files
richvdhhawkowl
authored andcommitted
Inline issue_access_token (#5659)
this is only used in one place, so it's clearer if we inline it and reduce the API surface. Also, fixes a buglet where we would create an access token even if we were about to block the user (we would never return the AT, so the user could never use it, but it was still created and added to the db.)
1 parent 8ab3444 commit 1890cfc

3 files changed

Lines changed: 5 additions & 8 deletions

File tree

changelog.d/5659.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Inline issue_access_token.

synapse/handlers/auth.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,11 @@ def get_access_token_for_user_id(self, user_id, device_id=None):
578578
StoreError if there was a problem storing the token.
579579
"""
580580
logger.info("Logging in user %s on device %s", user_id, device_id)
581-
access_token = yield self.issue_access_token(user_id, device_id)
582581
yield self.auth.check_auth_blocking(user_id)
583582

583+
access_token = self.macaroon_gen.generate_access_token(user_id)
584+
yield self.store.add_access_token_to_user(user_id, access_token, device_id)
585+
584586
# the device *should* have been registered before we got here; however,
585587
# it's possible we raced against a DELETE operation. The thing we
586588
# really don't want is active access_tokens without a record of the
@@ -831,12 +833,6 @@ def _check_local_password(self, user_id, password):
831833
defer.returnValue(None)
832834
defer.returnValue(user_id)
833835

834-
@defer.inlineCallbacks
835-
def issue_access_token(self, user_id, device_id=None):
836-
access_token = self.macaroon_gen.generate_access_token(user_id)
837-
yield self.store.add_access_token_to_user(user_id, access_token, device_id)
838-
defer.returnValue(access_token)
839-
840836
@defer.inlineCallbacks
841837
def validate_short_term_login_token_and_get_user_id(self, login_token):
842838
auth_api = self.hs.get_auth()

tests/api/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def test_cannot_use_regular_token_as_guest(self):
244244
USER_ID = "@percy:matrix.org"
245245
self.store.add_access_token_to_user = Mock()
246246

247-
token = yield self.hs.handlers.auth_handler.issue_access_token(
247+
token = yield self.hs.handlers.auth_handler.get_access_token_for_user_id(
248248
USER_ID, "DEVICE"
249249
)
250250
self.store.add_access_token_to_user.assert_called_with(USER_ID, token, "DEVICE")

0 commit comments

Comments
 (0)