2019-10-21 11:56:42 +00:00
|
|
|
from synapse.storage._base import SQLBaseStore
|
2016-05-05 12:42:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OpenIdStore(SQLBaseStore):
|
|
|
|
def insert_open_id_token(self, token, ts_valid_until_ms, user_id):
|
2019-12-04 10:15:55 +00:00
|
|
|
return self.simple_insert(
|
2016-05-05 12:42:44 +00:00
|
|
|
table="open_id_tokens",
|
|
|
|
values={
|
|
|
|
"token": token,
|
|
|
|
"ts_valid_until_ms": ts_valid_until_ms,
|
|
|
|
"user_id": user_id,
|
|
|
|
},
|
2019-04-03 09:07:29 +00:00
|
|
|
desc="insert_open_id_token",
|
2016-05-05 12:42:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_user_id_for_open_id_token(self, token, ts_now_ms):
|
|
|
|
def get_user_id_for_token_txn(txn):
|
|
|
|
sql = (
|
|
|
|
"SELECT user_id FROM open_id_tokens"
|
|
|
|
" WHERE token = ? AND ? <= ts_valid_until_ms"
|
|
|
|
)
|
|
|
|
|
|
|
|
txn.execute(sql, (token, ts_now_ms))
|
|
|
|
|
|
|
|
rows = txn.fetchall()
|
|
|
|
if not rows:
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return rows[0][0]
|
2019-04-03 09:07:29 +00:00
|
|
|
|
|
|
|
return self.runInteraction("get_user_id_for_token", get_user_id_for_token_txn)
|