ForcePilot/backend/package/yuxi/channel/extensions/confluence/auth.py

50 lines
1.3 KiB
Python
Raw Normal View History

import logging
import httpx
logger = logging.getLogger(__name__)
ATLASSIAN_TOKEN_URL = "https://auth.atlassian.com/oauth/token"
class ConfluenceOAuth2Flow:
@staticmethod
async def get_access_token(
client_id: str,
client_secret: str,
code: str,
redirect_uri: str,
) -> dict:
async with httpx.AsyncClient() as c:
resp = await c.post(
ATLASSIAN_TOKEN_URL,
json={
"grant_type": "authorization_code",
"client_id": client_id,
"client_secret": client_secret,
"code": code,
"redirect_uri": redirect_uri,
},
)
resp.raise_for_status()
return resp.json()
@staticmethod
async def refresh_token(
client_id: str,
client_secret: str,
refresh_token: str,
) -> dict:
async with httpx.AsyncClient() as c:
resp = await c.post(
ATLASSIAN_TOKEN_URL,
json={
"grant_type": "refresh_token",
"client_id": client_id,
"client_secret": client_secret,
"refresh_token": refresh_token,
},
)
resp.raise_for_status()
return resp.json()