rs_server_common/authentication/token_auth.md¶
Authentication token for the staging.
TokenAuth
¶
Bases: AuthBase
Custom authentication class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
AuthBase
|
ABC
|
Base auth class |
required |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
__call__(request)
¶
Add the Authorization header to the request
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
request to be modified |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Request |
request with modified headers |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
__init__(token)
¶
Init token auth
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Token value |
required |
TokenDataNotFound
¶
Bases: HTTPException
Raised if there are missing data in the dictionary to handle information about the token
__request_token(external_auth_config, data_to_send)
¶
Subfunction of get_station_token. Request either access or refresh token.
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
get_station_token(external_auth_config, original_token_dict)
¶
Retrieve and validate an authentication token for a specific station and service. Thee are two main use cases: - If the token shared variable is empty, it means that we don't have any token for now so we will retrieve one by requesting the authorisation server of the station - If the token shared variable is not empty, it means we already have a token. If it is still valid, we use it to request data to the resource server of the station. If it is not valid anymore, we use the refresh token to request a new token to the authorisation server
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_auth_config
|
StationExternalAuthenticationConfig
|
The configuration object loaded |
required |
original_token_dict
|
dict
|
The current token dictionary (empty if no token exists yet). |
required |
Returns: str: The token as string.
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the external authentication configuration cannot be retrieved, if the token request fails, or if the token format is invalid. |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
prepare_data(external_auth_config, call_refresh)
¶
Prepare data for token requests based on authentication configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_auth_config
|
StationExternalAuthenticationConfig
|
Configuration object containing authentication details. |
required |
call_refresh
|
bool
|
If True, prepare a refresh-token grant request; otherwise prepare a new password/credential grant request. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict[str, str]: Dictionary containing the prepared data for the request. |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
prepare_headers(external_auth_config)
¶
Prepare HTTP headers for token requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_auth_config
|
StationExternalAuthenticationConfig
|
Configuration object containing authentication details. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict[str, str]: Dictionary containing the prepared headers. |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
validate_token_dict(token_dict, config)
¶
Check if the token variable contains the mandatory attributes
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_dict
|
Any
|
|
required |
config
|
StationExternalAuthenticationConfig
|
external_auth_config (StationExternalAuthenticationConfig): The configuration object loaded |
required |
token_dict
|
Dict
|
dictionary containing information about the current token |
required |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
validate_token_format(token)
¶
Validate the format of a given token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
The token string to be validated. |
required |
Raises:
| Type | Description |
|---|---|
HTTPException
|
If the token format does not match the expected pattern. |