studio / publisher /token_refresher.py
Ava2lon's picture
Upload 170 files
345855e verified
Raw
History Blame Contribute Delete
681 Bytes
# 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