Buckets:

download
raw
1.29 kB
import json
from datetime import UTC, datetime
from typing import Any
from jwcrypto import jwk, jwt
from jwcrypto.common import JWException
from fief.models import Client, User
from fief.services.acr import ACR
class InvalidAccessToken(Exception):
pass
def generate_access_token(
key: jwk.JWK,
host: str,
client: Client,
authenticated_at: datetime,
acr: ACR,
user: User,
scope: list[str],
permissions: list[str],
lifetime_seconds: int,
) -> str:
iat = int(datetime.now(UTC).timestamp())
exp = iat + lifetime_seconds
claims = {
"iss": host,
"sub": str(user.id),
"aud": [client.client_id],
"exp": exp,
"iat": iat,
"auth_time": int(authenticated_at.timestamp()),
"acr": str(acr),
"azp": client.client_id,
"scope": " ".join(scope),
"permissions": permissions,
}
token = jwt.JWT(header={"alg": "RS256", "kid": key["kid"]}, claims=claims)
token.make_signed_token(key)
return token.serialize()
def read_access_token(key: jwk.JWK, token: str) -> dict[str, Any]:
try:
decoded_jwt = jwt.JWT(jwt=token, key=key)
return json.loads(decoded_jwt.claims)
except JWException as e:
raise InvalidAccessToken() from e

Xet Storage Details

Size:
1.29 kB
·
Xet hash:
daddbd9d08df31eb50fcf8cf4665f7d33ba9fcee7e5ae4050f82af26e2b1502a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.