Compare commits

...

4 Commits

Author SHA1 Message Date
Travis Ralston
b1f2078ef1 Fix errors 2019-07-03 14:53:22 -06:00
Travis Ralston
3c9c39df6c Don't cache access tokens 2019-07-03 14:50:54 -06:00
Travis Ralston
9772ceac71 True 2019-07-03 14:50:11 -06:00
Travis Ralston
ec84dc5172 Cheap way of soft logout (untested) 2019-07-03 14:43:25 -06:00
4 changed files with 31 additions and 6 deletions

View File

@@ -519,6 +519,15 @@ class Auth(object):
if not ret:
defer.returnValue(None)
if ret.get("expired", False):
logger.warn("Doing soft logout on user")
raise AuthError(
401,
"Token soft logged out",
errcode=Codes.UNKNOWN_TOKEN,
soft_logout=True,
)
# we use ret.get() below because *lots* of unit tests stub out
# get_user_by_access_token in a way where it only returns a couple of
# the fields.

View File

@@ -85,7 +85,7 @@ class SynapseError(CodeMessageException):
errcode (str): Matrix error code e.g 'M_FORBIDDEN'
"""
def __init__(self, code, msg, errcode=Codes.UNKNOWN):
def __init__(self, code, msg, errcode=Codes.UNKNOWN, soft_logout=False):
"""Constructs a synapse error.
Args:
@@ -95,9 +95,10 @@ class SynapseError(CodeMessageException):
"""
super(SynapseError, self).__init__(code, msg)
self.errcode = errcode
self.soft_logout = soft_logout
def error_dict(self):
return cs_error(self.msg, self.errcode)
return cs_error(self.msg, self.errcode, self.soft_logout)
class ProxiedRequestError(SynapseError):
@@ -383,7 +384,7 @@ class RequestSendFailed(RuntimeError):
self.can_retry = can_retry
def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
def cs_error(msg, code=Codes.UNKNOWN, soft_logout=False, **kwargs):
""" Utility method for constructing an error response for client-server
interactions.
@@ -394,7 +395,7 @@ def cs_error(msg, code=Codes.UNKNOWN, **kwargs):
Returns:
A dict representing the error response JSON.
"""
err = {"error": msg, "errcode": code}
err = {"error": msg, "errcode": code, "soft_logout": soft_logout}
for key, value in iteritems(kwargs):
err[key] = value
return err

View File

@@ -82,7 +82,6 @@ class RegistrationWorkerStore(SQLBaseStore):
is_trial = (now - info["creation_ts"] * 1000) < trial_duration_ms
defer.returnValue(is_trial)
@cached()
def get_user_by_access_token(self, token):
"""Get a user from the given access token.
@@ -284,7 +283,7 @@ class RegistrationWorkerStore(SQLBaseStore):
def _query_for_auth(self, txn, token):
sql = (
"SELECT users.name, users.is_guest, access_tokens.id as token_id,"
" access_tokens.device_id"
" access_tokens.device_id, access_tokens.expired"
" FROM users"
" INNER JOIN access_tokens on users.name = access_tokens.user_id"
" WHERE token = ?"

View File

@@ -0,0 +1,16 @@
/* Copyright 2019 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
ALTER TABLE access_tokens ADD expired SMALLINT DEFAULT 0 NOT NULL;