Initialize the MemoryRefreshRepository.
This repository uses an in-memory dictionary to store refresh tokens.
It provides methods to create, retrieve, delete and delete all refresh
tokens for a given subject. The tokens are stored in a dictionary where
the keys are the token values and the values are the token objects.
| Parameters: |
-
token_model
(type[Token], default:
Token
)
–
The model class for tokens, by default Token. The model class
should have a from_dict class method that takes a dictionary and
returns an instance of the model. The dictionary will have the same
structure as the token data in the JSON file. The model class
should also have a to_dict method that converts an instance of
the model to a dictionary with the same structure as the token data
in the JSON file. The model class should also have a
create_refresh class method that creates a new refresh token.
-
token_max_age_seconds
(int, default:
7 * 24 * 3600
)
–
The maximum age of a token in seconds, by default the equivalent of
7 days in seconds
-
token_length
(int, default:
32
)
–
The length of the generated token string, by default 32 characters
|
Source code in src/alpha/repositories/refresh/memory_repository.py
| def __init__(
self,
token_model: type[Token] = Token,
token_max_age_seconds: int = 7 * 24 * 3600,
token_length: int = 32,
):
"""Initialize the MemoryRefreshRepository.
This repository uses an in-memory dictionary to store refresh tokens.
It provides methods to create, retrieve, delete and delete all refresh
tokens for a given subject. The tokens are stored in a dictionary where
the keys are the token values and the values are the token objects.
Parameters
----------
token_model
The model class for tokens, by default Token. The model class
should have a `from_dict` class method that takes a dictionary and
returns an instance of the model. The dictionary will have the same
structure as the token data in the JSON file. The model class
should also have a `to_dict` method that converts an instance of
the model to a dictionary with the same structure as the token data
in the JSON file. The model class should also have a
`create_refresh` class method that creates a new refresh token.
token_max_age_seconds
The maximum age of a token in seconds, by default the equivalent of
7 days in seconds
token_length
The length of the generated token string, by default 32 characters
"""
self._token_model = token_model
self._token_max_age_seconds = token_max_age_seconds
self._token_length = token_length
self._refresh_tokens: dict[str, Token] = {}
|