Auth Logic
Authentication and authorization business logic.
Token Management
token
Token endpoint implementation.
Attributes
BASE_64_URL_SAFE_PATTERN = '(?:[A-Za-z0-9\\-_]{4})*(?:[A-Za-z0-9\\-_]{2}==|[A-Za-z0-9\\-_]{3}=)?'
module-attribute
LEGACY_EXCHANGE_PATTERN = f'Bearer diracx:legacy:({BASE_64_URL_SAFE_PATTERN})'
module-attribute
Classes
Functions
get_oidc_token(grant_type, client_id, auth_db, config, settings, available_properties, device_code=None, code=None, redirect_uri=None, code_verifier=None, refresh_token=None)
async
Token endpoint to retrieve the token at the end of a flow.
Source code in diracx-logic/src/diracx/logic/auth/token.py
get_oidc_token_info_from_device_flow(device_code, client_id, auth_db, settings)
async
Get OIDC token information from the device flow DB and check few parameters before returning it.
Source code in diracx-logic/src/diracx/logic/auth/token.py
get_oidc_token_info_from_authorization_flow(code, client_id, redirect_uri, code_verifier, auth_db, settings)
async
Get OIDC token information from the authorization flow DB and check few parameters before returning it.
Source code in diracx-logic/src/diracx/logic/auth/token.py
get_oidc_token_info_from_refresh_flow(refresh_token, auth_db, settings)
async
Get OIDC token information from the refresh token DB and check few parameters before returning it.
Source code in diracx-logic/src/diracx/logic/auth/token.py
perform_legacy_exchange(expected_api_key, preferred_username, scope, authorization, auth_db, available_properties, settings, config, expires_minutes=None)
async
Endpoint used by legacy DIRAC to mint tokens for proxy -> token exchange.
Source code in diracx-logic/src/diracx/logic/auth/token.py
exchange_token(auth_db, scope, oidc_token_info, config, settings, available_properties, *, refresh_token_expire_minutes=None, legacy_exchange=False, include_refresh_token=True)
async
Method called to exchange the OIDC token for a DIRAC generated access token.
Source code in diracx-logic/src/diracx/logic/auth/token.py
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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
create_token(payload, settings)
Create a JWT token with the given payload and settings.
Source code in diracx-logic/src/diracx/logic/auth/token.py
insert_refresh_token(auth_db, subject, scope)
async
Insert a refresh token into the database and return the JWT ID.
Source code in diracx-logic/src/diracx/logic/auth/token.py
get_device_flow(auth_db, device_code, max_validity)
async
Get the device flow from the DB and check few parameters before returning it.
Source code in diracx-logic/src/diracx/logic/auth/token.py
get_authorization_flow(auth_db, code, max_validity)
async
Get the authorization flow from the DB and check few parameters before returning it.
Source code in diracx-logic/src/diracx/logic/auth/token.py
Authorization Code Flow
authorize_code_flow
Authorization code flow.
Classes
Functions
initiate_authorization_flow(request_url, code_challenge, code_challenge_method, client_id, redirect_uri, scope, state, auth_db, config, settings, available_properties)
async
Initiate the authorization flow.
Source code in diracx-logic/src/diracx/logic/auth/authorize_code_flow.py
complete_authorization_flow(code, state, request_url, auth_db, config, settings)
async
Complete the authorization flow.
Source code in diracx-logic/src/diracx/logic/auth/authorize_code_flow.py
Device Flow
device_flow
Device flow.
Classes
Functions
initiate_device_flow(client_id, scope, verification_uri, auth_db, config, available_properties, settings)
async
Initiate the device flow against DIRAC authorization Server.
Source code in diracx-logic/src/diracx/logic/auth/device_flow.py
do_device_flow(request_url, auth_db, user_code, config, available_properties, settings)
async
This is called as the verification URI for the device flow.
Source code in diracx-logic/src/diracx/logic/auth/device_flow.py
finish_device_flow(request_url, code, state, auth_db, config, settings)
async
This the url callbacked by IAM/CheckIn after the authorization flow was granted.
Source code in diracx-logic/src/diracx/logic/auth/device_flow.py
User Management
management
This module contains the auth management functions.
Classes
Functions
get_refresh_tokens(auth_db, subject)
async
Get all refresh tokens bound to a given subject. If there is no subject, then all the refresh tokens are retrieved.
Source code in diracx-logic/src/diracx/logic/auth/management.py
revoke_refresh_token_by_jti(auth_db, subject, jti)
async
Revoke a refresh token. If a subject is provided, then the refresh token must be owned by that subject.
Source code in diracx-logic/src/diracx/logic/auth/management.py
revoke_refresh_token_by_refresh_token(auth_db, subject, token, token_type_hint, client_id, settings)
async
Revoke a refresh token following RFC7009.
Source code in diracx-logic/src/diracx/logic/auth/management.py
Well Known Endpoints
well_known
Classes
Functions
get_openid_configuration(token_endpoint, userinfo_endpoint, authorization_endpoint, device_authorization_endpoint, revoke_refresh_token_endpoint, jwks_endpoint, config, settings)
async
OpenID Connect discovery endpoint.
Source code in diracx-logic/src/diracx/logic/auth/well_known.py
get_jwks(settings)
async
get_installation_metadata(config)
async
Get metadata about the dirac installation.
Source code in diracx-logic/src/diracx/logic/auth/well_known.py
Auth Utilities
utils
Classes
ScopeInfoDict
Functions
get_server_metadata(url)
async
Get the server metadata from the IAM.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
encrypt_state(state_dict, cipher_suite)
Encrypt the state dict and return it as a string.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
decrypt_state(state, cipher_suite)
Decrypt the state string and return it as a dict.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
fetch_jwk_set(url)
async
Fetch the JWK set from the IAM.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
parse_id_token(config, vo, raw_id_token)
async
Parse and validate the ID token from IAM.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
initiate_authorization_flow_with_iam(config, vo, redirect_uri, state, cipher_suite)
async
Initiate the authorization flow with the IAM. Return the URL to redirect the user to.
The state dict is encrypted and passed to the IAM. It is then decrypted when the user is redirected back to the redirect_uri.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
get_token_from_iam(config, vo, code, state, redirect_uri)
async
Get the token from the IAM using the code and state. Return the ID token.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
read_token(payload, jwks, allowed_algorithms, claims_requests=None)
Source code in diracx-logic/src/diracx/logic/auth/utils.py
verify_dirac_refresh_token(refresh_token, settings)
async
Verify dirac user token and return a UserInfo class Used for each API endpoint.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
get_allowed_user_properties(config, sub, vo)
Retrieve all properties of groups a user is registered in.
Source code in diracx-logic/src/diracx/logic/auth/utils.py
parse_and_validate_scope(scope, config, available_properties)
Check
- At most one VO
- At most one group
- group belongs to VO
- properties are known
return dict with group and properties.
:raises: * ValueError in case the scope isn't valid