示例#1
0
    def test_can_read_token_from_headers(self):
        """Tests that Sydent correct extracts an auth token from request headers"""
        self.sydent.run()

        request, _ = make_request(self.sydent.reactor, "GET",
                                  "/_matrix/identity/v2/hash_details")
        request.requestHeaders.addRawHeader(
            b"Authorization", b"Bearer " + self.test_token.encode("ascii"))

        token = tokenFromRequest(request)

        self.assertEqual(token, self.test_token)
示例#2
0
    def test_can_read_token_from_query_parameters(self):
        """Tests that Sydent correct extracts an auth token from query parameters"""
        self.sydent.run()

        request, _ = make_request(
            self.sydent.reactor, "GET",
            "/_matrix/identity/v2/hash_details?access_token=" +
            self.test_token)

        token = tokenFromRequest(request)

        self.assertEqual(token, self.test_token)
示例#3
0
    def render_POST(self, request):
        """
        Invalidate the given access token
        """
        send_cors(request)

        authIfV2(self.sydent, request, False)

        token = tokenFromRequest(request)

        accountStore = AccountStore(self.sydent)
        accountStore.delToken(token)
        return {}
示例#4
0
    def render_POST(self, request: Request) -> JsonDict:
        """
        Invalidate the given access token
        """
        send_cors(request)

        authV2(self.sydent, request, False)

        token = tokenFromRequest(request)
        if token is None:
            raise MatrixRestError(400, "M_MISSING_PARAMS", "Missing token")

        accountStore = AccountStore(self.sydent)
        accountStore.delToken(token)
        return {}