logoutservlet.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import absolute_import
  16. from twisted.web.resource import Resource
  17. import logging
  18. from sydent.http.servlets import jsonwrap, send_cors
  19. from sydent.db.accounts import AccountStore
  20. from sydent.http.auth import authIfV2, tokenFromRequest
  21. logger = logging.getLogger(__name__)
  22. class LogoutServlet(Resource):
  23. isLeaf = True
  24. def __init__(self, syd):
  25. self.sydent = syd
  26. @jsonwrap
  27. def render_POST(self, request):
  28. """
  29. Invalidate the given access token
  30. """
  31. send_cors(request)
  32. authIfV2(self.sydent, request, False)
  33. token = tokenFromRequest(request)
  34. accountStore = AccountStore(self.sydent)
  35. accountStore.delToken(token)
  36. return {}
  37. def render_OPTIONS(self, request):
  38. send_cors(request)
  39. return b''