~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/scripts/revoke-expired-tokens -rwxr-xr-x 685 bytes
72548bd7Drew DeVault API: Updates per core-go auth changes 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python3
import json
from datetime import datetime
from metasrht.app import db
from metasrht.types import OAuthToken, RevocationUrl
from srht.webhook.celery import async_request

cutoff = datetime.utcnow()

for token in OAuthToken.query.filter(OAuthToken.expires < cutoff).all():
    print(f"Issuing revocations for expired token {token.token_hash}")
    for revocation in (RevocationUrl.query
            .filter(RevocationUrl.token_id == token.id)).all():
        async_request.delay(revocation.url, json.dumps({
            "token_hash": token.token_hash,
        }), {"Content-Type": "application/json"})
        db.session.delete(revocation)
    db.session.commit()