imaging_api.utils.xnat_token
Classes
Factory class for retrieving and caching XNAT authentication tokens. |
Module Contents
- class imaging_api.utils.xnat_token.XnatTokenFactory(url: str, username: str, password: str, expiry_hours: int = 24)
Factory class for retrieving and caching XNAT authentication tokens.
- url
- username
- password
- expiry_hours = 24
- xnat_cookie: dict[str, Any]
- get_xnat_cookie() str
Retrieves a new XNAT authentication token if expired or not set. Caches the token for reuse.
- Returns:
A valid XNAT session token.
- Return type:
str
- Raises:
HTTPException – If there is an error during the authentication process or if the token cannot be retrieved.
- is_token_valid(token: str) bool
Checks if a given XNAT session token is still valid.
- Parameters:
token (str) – The XNAT session token to validate.
- Returns:
True if the token is valid, False otherwise.
- Return type:
bool