| 1234567891011121314151617181920212223242526272829303132 |
- import httpx
- from app.config import get_settings
- settings = get_settings()
- async def exchange_code_for_token(code: str) -> dict:
- async with httpx.AsyncClient() as client:
- resp = await client.post(
- f"{settings.sso_base_url}/oauth/token",
- data={
- "grant_type": "authorization_code",
- "code": code,
- "redirect_uri": settings.sso_redirect_uri,
- "client_id": settings.sso_client_id,
- "client_secret": settings.sso_client_secret,
- },
- headers={"Content-Type": "application/x-www-form-urlencoded"},
- )
- resp.raise_for_status()
- return resp.json()
- async def fetch_sso_userinfo(access_token: str) -> dict:
- async with httpx.AsyncClient() as client:
- resp = await client.get(
- f"{settings.sso_base_url}/oauth/userinfo",
- headers={"Authorization": f"Bearer {access_token}"},
- )
- resp.raise_for_status()
- return resp.json()
|