Skip to content

Class swarmauri_core.tokens.ITokenService.ITokenService

swarmauri_core.tokens.ITokenService.ITokenService

Bases: ABC

Stable interface to mint and verify tokens.

Supports operations such as JSON Web Tokens (JWT) and JSON Web Signatures (JWS). The interface keeps crypto-agnostic policy fields explicit (iss, aud, exp, scope).

supports abstractmethod

supports()

Return formats and algorithms supported by the service.

Source code in swarmauri_core/tokens/ITokenService.py
15
16
17
@abstractmethod
def supports(self) -> Mapping[str, Iterable[str]]:
    """Return formats and algorithms supported by the service."""

mint abstractmethod async

mint(
    claims,
    *,
    alg,
    kid=None,
    key_version=None,
    headers=None,
    lifetime_s=3600,
    issuer=None,
    subject=None,
    audience=None,
    scope=None,
)

Return a compact JWS/JWT string with normalized timestamps.

Source code in swarmauri_core/tokens/ITokenService.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@abstractmethod
async def mint(
    self,
    claims: Dict[str, Any],
    *,
    alg: str,
    kid: str | None = None,
    key_version: int | None = None,
    headers: Optional[Dict[str, Any]] = None,
    lifetime_s: Optional[int] = 3600,
    issuer: Optional[str] = None,
    subject: Optional[str] = None,
    audience: Optional[str | list[str]] = None,
    scope: Optional[str] = None,
) -> str:
    """Return a compact JWS/JWT string with normalized timestamps."""

verify abstractmethod async

verify(token, *, issuer=None, audience=None, leeway_s=60)

Return validated claims or raise an exception on failure.

Source code in swarmauri_core/tokens/ITokenService.py
36
37
38
39
40
41
42
43
44
45
@abstractmethod
async def verify(
    self,
    token: str,
    *,
    issuer: Optional[str] = None,
    audience: Optional[str | list[str]] = None,
    leeway_s: int = 60,
) -> Dict[str, Any]:
    """Return validated claims or raise an exception on failure."""

jwks abstractmethod async

jwks()

Return a JWKS mapping ({"keys": [...]}) for signing key discovery.

Source code in swarmauri_core/tokens/ITokenService.py
47
48
49
@abstractmethod
async def jwks(self) -> dict:
    """Return a JWKS mapping (``{"keys": [...]}``) for signing key discovery."""