summary refs log tree commit diff
path: root/synapse/storage/databases/main/openid.py
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-10-16 18:07:27 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2020-10-16 18:21:05 +0100
commitd174faacc74df95ad72a3ef711cd65d4637b9e1e (patch)
treeb43240da414660c87a8bb0e904cdd33c782d7d8e /synapse/storage/databases/main/openid.py
parentMerge commit '0a86850ba' into anoa/dinsic_release_1_21_x (diff)
parentRename database classes to make some sense (#8033) (diff)
downloadsynapse-d174faacc74df95ad72a3ef711cd65d4637b9e1e.tar.xz
Merge commit 'a7bdf98d0' into anoa/dinsic_release_1_21_x
* commit 'a7bdf98d0':
  Rename database classes to make some sense (#8033)
Diffstat (limited to 'synapse/storage/databases/main/openid.py')
-rw-r--r--synapse/storage/databases/main/openid.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/openid.py b/synapse/storage/databases/main/openid.py
new file mode 100644

index 0000000000..dcd1ff911a --- /dev/null +++ b/synapse/storage/databases/main/openid.py
@@ -0,0 +1,33 @@ +from synapse.storage._base import SQLBaseStore + + +class OpenIdStore(SQLBaseStore): + def insert_open_id_token(self, token, ts_valid_until_ms, user_id): + return self.db_pool.simple_insert( + table="open_id_tokens", + values={ + "token": token, + "ts_valid_until_ms": ts_valid_until_ms, + "user_id": user_id, + }, + desc="insert_open_id_token", + ) + + 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] + + return self.db_pool.runInteraction( + "get_user_id_for_token", get_user_id_for_token_txn + )