diff --git a/bumper/__init__.py b/bumper/__init__.py index 950e1cb..8a1ffee 100644 --- a/bumper/__init__.py +++ b/bumper/__init__.py @@ -265,6 +265,7 @@ async def start(): async def maintenance(): revoke_expired_tokens() + revoke_expired_oauths() async def shutdown(): diff --git a/bumper/db.py b/bumper/db.py index 90324e4..304add3 100644 --- a/bumper/db.py +++ b/bumper/db.py @@ -203,6 +203,21 @@ def user_revoke_authcode(userid, token, authcode): ) +def revoke_expired_oauths(): + opendb = db_get() + with opendb: + table = opendb.table("oauth") + entries = table.all() + + for i in entries: + oauth = OAuth(**i) + if datetime.now() >= datetime.fromisoformat(oauth.expire_at): + bumperlog.debug( + "Removing oauth {} due to expiration".format(oauth.access_token) + ) + table.remove(doc_ids=[i.doc_id]) + + def user_revoke_expired_oauths(userid): opendb = db_get() with opendb: