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

Commit

Permalink
Merge pull request #5256 from aaronraimist/logout-correct-error
Browse files Browse the repository at this point in the history
Show correct error when logging out and access token is missing
  • Loading branch information
erikjohnston authored May 30, 2019
2 parents 8d92329 + 123918b commit 45f5d8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
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

0 comments on commit 45f5d8f

Please sign in to comment.