THE ORIONIS API
Build with clarity.
Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.
class AccessTokenRepository(IAccessTokenRepository): (source)
Constructor: AccessTokenRepository(app, db)
Persist personal access tokens through the Orionis query builder.
Tokens are opaque: the client receives a random secret and the store only keeps its SHA-256 digest in a unique column. Verification is a single indexed lookup on that digest, so no plain text secret ever needs to be compared.
Concurrency
Issuance uses a unique digest, with an optional ID lookup for drivers that do not return generated keys. Revocation and usage confirmation use conditional updates. Usage cannot reactivate a revoked token; concurrent timestamps are last-writer-wins. Purging uses two deletes.
| Static Method | _from |
Validate stored metadata equally for separate and combined reads. |
| Method | __init__ |
Initialise the repository from the token configuration. |
| Async Method | create |
Issue a new personal access token for an identity. |
| Async Method | find |
Resolve a token from the value presented by the client. |
| Async Method | find |
Combine native ORM reads, or opt out for custom implementations. |
| Async Method | purge |
Delete tokens that expired or were revoked. |
| Async Method | revoke |
Revoke a single token. |
| Async Method | revoke |
Revoke every active token of an identity. |
| Async Method | touch |
Confirm token validity and record its use atomically. |
| Class Variable | __slots__ |
Declare the instance attribute slots reserved by this class. |
| Instance Variable | __db |
Gateway used to build queries over the token table. |
| Instance Variable | __expiration |
Expiration produced by app.config. |
| Instance Variable | __secret |
Encoded application secret used to protect token lookups. |
| Instance Variable | __table |
Database table used to persist access-token records. |
Validate stored metadata equally for separate and combined reads.
| Parameters | |
row:dict | Stored token metadata returned by the database. |
| Returns | |
orionis.auth.entities.AccessToken | None | Validated token, or None for invalid, revoked or expired metadata. |
Initialise the repository from the token configuration.
| Parameters | |
app:orionis.IApplication | Application exposing the auth.tokens configuration. |
db:orionis.orm.contracts.query_builder.IQueryBuilder | Gateway used to build queries over the token table. |
| Returns | |
None | No return value. |
Self, tokenable: IAuthorizable, name: str, *, abilities: Iterable[ str] | None = None, expires_at: datetime | None = None) -> NewAccessToken:
(source)
¶
Issue a new personal access token for an identity.
| Parameters | |
tokenable:orionis.auth.contracts.IAuthorizable | Identity the token belongs to. |
name:str | Human readable label describing the token. |
abilities:collections.abc.Iterable[str] | None, optional | Abilities the token may use, or None to keep the full authorization of the identity. |
expiresdatetime.datetime | None, optional | Explicit expiration. None applies the configured default. |
| Returns | |
orionis.auth.entities.NewAccessToken | Stored metadata plus the plain text value of the token. |
| Raises | |
orionis.auth.TokenException | When the token name is empty. |
Resolve a token from the value presented by the client.
| Parameters | |
plainstr | Value received in the Authorization header. |
| Returns | |
orionis.auth.entities.AccessToken | None | Matching token, or None when the value is unknown, has been revoked or has already expired. |
Combine native ORM reads, or opt out for custom implementations.
| Parameters | |
plainstr | Presented credential, hashed before constructing the query. |
identities:object | Identity provider whose lookup semantics must be preserved. |
| Returns | |
object | (token, identity), None for no match, or NotImplemented for fallback. |
Revoke every active token of an identity.
| Parameters | |
tokenable:orionis.auth.contracts.IAuthorizable | Identity whose tokens must be revoked. |
| Returns | |
int | Number of tokens revoked by this call. |