Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
from typing import Any, Dict, Optional, Tuple

from authlib.integrations.starlette_client import OAuth
from authlib.jose import JsonWebKey
from authlib.jose import jwt as jose_jwt
from fief_client import FiefAsync

from carbonserver.config import settings

DEFAULT_SIGNATURE_CACHE_TTL = 3600 # seconds
OAUTH_SCOPES = ["openid", "email", "profile"]

fief = FiefAsync(
settings.fief_url, settings.fief_client_id, settings.fief_client_secret
)

oauth = OAuth()
oauth.register(
Expand Down Expand Up @@ -44,3 +50,20 @@ async def get_authorize_url(self, request, login_url):

def get_client_credentials(self) -> Tuple[str, str]:
return (self.client.client_id, self.client.client_secret)

async def _decode_token(self, token: str) -> Dict[str, Any]:
try:
access_token_info = await fief.validate_access_token(token)
return access_token_info
except Exception:
...

jwks_data = await self.client.fetch_jwk_set()
keyset = JsonWebKey.import_key_set(jwks_data)
claims = jose_jwt.decode(token, keyset)
claims.validate()
return dict(claims)

async def validate_access_token(self, token: str) -> bool:
await self._decode_token(token)
return True
Loading
Loading