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
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
__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
84 85 86 87 88 89 90 91 92 93 94 | |
__init__(token)
Init token auth
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
str
|
Token value |
required |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
76 77 78 79 80 81 82 | |
TokenDataNotFound
Bases: HTTPException
Raised if there are missing data in the dictionary to handle information about the token
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
64 65 | |
__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
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
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 |
token_var
|
Variable
|
variable shared between all workers containing |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
dict
|
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
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 325 326 327 328 329 330 331 332 | |
log_http_exception(*args, **kwargs)
Log error and return an HTTP exception to be raised by the caller
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
44 45 46 | |
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 |
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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
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
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
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. |
Source code in docs/rs-server/services/common/rs_server_common/authentication/token_auth.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |