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

Inline issue_access_token #5659

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5659.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Inline issue_access_token.
10 changes: 3 additions & 7 deletions synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,11 @@ def get_access_token_for_user_id(self, user_id, device_id=None):
StoreError if there was a problem storing the token.
"""
logger.info("Logging in user %s on device %s", user_id, device_id)
access_token = yield self.issue_access_token(user_id, device_id)
yield self.auth.check_auth_blocking(user_id)

access_token = self.macaroon_gen.generate_access_token(user_id)
yield self.store.add_access_token_to_user(user_id, access_token, device_id)

# the device *should* have been registered before we got here; however,
# it's possible we raced against a DELETE operation. The thing we
# really don't want is active access_tokens without a record of the
Expand Down Expand Up @@ -831,12 +833,6 @@ def _check_local_password(self, user_id, password):
defer.returnValue(None)
defer.returnValue(user_id)

@defer.inlineCallbacks
def issue_access_token(self, user_id, device_id=None):
access_token = self.macaroon_gen.generate_access_token(user_id)
yield self.store.add_access_token_to_user(user_id, access_token, device_id)
defer.returnValue(access_token)

@defer.inlineCallbacks
def validate_short_term_login_token_and_get_user_id(self, login_token):
auth_api = self.hs.get_auth()
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def test_cannot_use_regular_token_as_guest(self):
USER_ID = "@percy:matrix.org"
self.store.add_access_token_to_user = Mock()

token = yield self.hs.handlers.auth_handler.issue_access_token(
token = yield self.hs.handlers.auth_handler.get_access_token_for_user_id(
USER_ID, "DEVICE"
)
self.store.add_access_token_to_user.assert_called_with(USER_ID, token, "DEVICE")
Expand Down