TokenStore¶
-
class
gafaelfawr.token_store.
TokenStore
(redis: Redis, logger: BoundLogger)¶ Bases:
object
Store, retrieve, revoke, and expire user-created tokens.
Parameters: - redis (
aioredis.Redis
) – Redis client used to store and retrieve tokens. - logger (
structlog.BoundLogger
) – Logger to report any errors.
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: - user_id (
-
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: - user_id (
str
) – User ID who is issuing the token. - session (
gafaelfawr.session.Session
) – The newly-issued token to store an index entry for. - pipeline (
aioredis.commands.Pipeline
) – The pipeline in which to store the session.
- user_id (
- redis (