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

Show correct error when logging out and access token is missing #5256

Merged
merged 4 commits into from
May 30, 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/5256.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show the correct error when logging out and access token is missing.
27 changes: 9 additions & 18 deletions synapse/rest/client/v1/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from twisted.internet import defer

from synapse.api.errors import AuthError

from .base import ClientV1RestServlet, client_path_patterns

logger = logging.getLogger(__name__)
Expand All @@ -38,23 +36,16 @@ def on_OPTIONS(self, request):

@defer.inlineCallbacks
def on_POST(self, request):
try:
requester = yield self.auth.get_user_by_req(request)
except AuthError:
# this implies the access token has already been deleted.
defer.returnValue((401, {
"errcode": "M_UNKNOWN_TOKEN",
"error": "Access Token unknown or expired"
}))
requester = yield self.auth.get_user_by_req(request)

if requester.device_id is None:
# the acccess token wasn't associated with a device.
# Just delete the access token
access_token = self._auth.get_access_token_from_request(request)
yield self._auth_handler.delete_access_token(access_token)
else:
if requester.device_id is None:
# the acccess token wasn't associated with a device.
# Just delete the access token
access_token = self._auth.get_access_token_from_request(request)
yield self._auth_handler.delete_access_token(access_token)
else:
yield self._device_handler.delete_device(
requester.user.to_string(), requester.device_id)
yield self._device_handler.delete_device(
requester.user.to_string(), requester.device_id)

defer.returnValue((200, {}))

Expand Down