File size: 681 Bytes
345855e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# publisher/token_refresher.py

import httpx
from publisher.oauth.storage import save_tokens


async def refresh_google(user_id, token):

    if "refresh_token" not in token:
        return token

    async with httpx.AsyncClient() as client:
        r = await client.post(
            "https://oauth2.googleapis.com/token",
            data={
                "client_id": token["client_id"],
                "client_secret": token["client_secret"],
                "refresh_token": token["refresh_token"],
                "grant_type": "refresh_token",
            },
        )

    new = r.json()
    token.update(new)

    save_tokens(user_id, "google", token)

    return token