Space tokens

class atproto_space.tokens.SpaceToken(iss: str, sub: str, exp: float, jti: str, iat: float | None = None, aud: str | None = None, key_id: str | None = None)

Bases: object

Claims of a delegation token, a space credential or a client attestation.

iss

Issuer: the account, the space authority or the client ID.

Type:

str

sub

URI of the space, or the client ID in a client attestation.

Type:

str

exp

Expiration as a Unix timestamp.

Type:

float

jti

Unique ID of the token.

Type:

str

iat

Time of issue as a Unix timestamp. A space credential always has it.

Type:

float | None

aud

Audience. A space credential has none.

Type:

str | None

key_id

DID key that a space credential is bound to.

Type:

str | None

atproto_space.tokens.get_space_host_audience(space_did: str) → str

Get the audience that names the host of a space in delegation tokens and client attestations.

Parameters:

space_did – DID of the space authority.

Returns:

Audience.

Return type:

str

atproto_space.tokens.parse_space_token(kind: Literal['delegation', 'credential', 'client_attestation'], token: str) → SpaceToken

Parse a space token and check its structure.

Note

The signature and the expiration are not verified.

Parameters:
  • kind – 'delegation', 'credential' or 'client_attestation'.

  • token – JWT in the compact serialization.

Returns:

Claims of the token.

Return type:

SpaceToken

Raises:

atproto_space.exceptions.SpaceTokenError – The token is not a well-formed token of this kind.

atproto_space.tokens.create_client_attestation(client_id: str, audience: str, private_key: EllipticCurvePrivateKey, kid: str | None = None, expires_in: int = 60) → str

Create a proof of the identity of an OAuth client for the host of a space.

Parameters:
  • client_id – Client ID of the OAuth client.

  • audience – Audience that names the host of the space. See get_space_host_audience().

  • private_key – P-256 private key from the JWKS of the client.

  • kid – ID of the key in the JWKS of the client.

  • expires_in – Lifetime of the attestation in seconds.

Returns:

Client attestation, a JWT in the compact serialization.

Return type:

str

Raises:

atproto_crypto.exceptions.UnsupportedKeyTypeError – The private key is not a P-256 key.