TokenStore

class gafaelfawr.token_store.TokenStore(redis: Redis, logger: BoundLogger)

Bases: object

Store, retrieve, revoke, and expire user-created tokens.

Parameters:

Methods Summary

expire_tokens(user_id) Delete expired tokens for a user.
get_tokens(user_id) Retrieve index entries for all tokens for a given user.
revoke_token(user_id, key, pipeline) Revoke a token.
store_session(user_id, session, pipeline) Store an index entry for a user authentication session.

Methods Documentation

expire_tokens(user_id: str) → None

Delete expired tokens for a user.

Parameters:user_id (str) – The user ID.
get_tokens(user_id: str) → List[TokenEntry]

Retrieve index entries for all tokens for a given user.

Parameters:user_id (str) – Retrieve the tokens of this User ID.
Returns:token_entries – The index entries for all of that user’s tokens.
Return type:List[TokenEntry]
revoke_token(user_id: str, key: str, pipeline: Pipeline) → bool

Revoke a token.

To allow the caller to batch this with other Redis modifications, the session will be stored but the pipeline will not be executed. The caller is responsible for executing the pipeline.

Parameters:
  • user_id (str) – User ID to whom the token was issued.
  • key (str) – Session handle of the issued token.
  • pipeline (aioredis.commands.Pipeline) – The pipeline to use for token deletion.
Returns:

success – True if the token was found and revoked, False otherwise.

Return type:

bool

store_session(user_id: str, session: Session, pipeline: Pipeline) → None

Store an index entry for a user authentication session.

Used to populate the token list. To allow the caller to batch this with other Redis modifications, the session will be stored but the pipeline will not be executed. The caller is responsible for executing the pipeline.

Parameters: