Auth Router
Authentication and authorization endpoints.
auth
Attributes
router = DiracxRouter(require_auth=False)
module-attribute
__all__ = ['has_properties', 'verify_dirac_access_token']
module-attribute
Classes
Functions
verify_dirac_access_token(authorization, settings)
async
Verify dirac user token and return a UserInfo class Used for each API endpoint.
Source code in diracx-routers/src/diracx/routers/utils/users.py
has_properties(expression)
Check if the user has the given properties.
Source code in diracx-routers/src/diracx/routers/auth/utils.py
Token Management
token
Token endpoint.
Attributes
router = DiracxRouter(require_auth=False)
module-attribute
logger = logging.getLogger(__name__)
module-attribute
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
mint_token(access_payload, refresh_payload, existing_refresh_token, all_access_policies, settings)
async
Enrich the token with policy specific content and mint it.
Source code in diracx-routers/src/diracx/routers/auth/token.py
get_oidc_token(grant_type, client_id, auth_db, config, settings, available_properties, all_access_policies, 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. This is the endpoint being pulled by dirac-login when doing the device flow.
Source code in diracx-routers/src/diracx/routers/auth/token.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
perform_legacy_exchange(preferred_username, scope, authorization, auth_db, available_properties, settings, config, all_access_policies, expires_minutes=None)
async
Endpoint used by legacy DIRAC to mint tokens for proxy -> token exchange.
This route is disabled if DIRACX_LEGACY_EXCHANGE_HASHED_API_KEY is not set in the environment.
Source code in diracx-routers/src/diracx/routers/auth/token.py
Authorization Code Flow
authorize_code_flow
Authorization code flow.
See docs/admin/explanations/authentication.md
Attributes
router = DiracxRouter(require_auth=False)
module-attribute
Classes
Functions
initiate_authorization_flow(request, response_type, code_challenge, code_challenge_method, client_id, redirect_uri, scope, state, auth_db, config, available_properties, settings)
async
Initiate the authorization flow. It will redirect to the actual OpenID server (IAM, CheckIn) to perform a authorization code flow.
Scope details: - If only VO is provided: Uses the default group and its properties for the VO.
-
If VO and group are provided: Uses the specified group and its properties for the VO.
-
If VO and properties are provided: Uses the default group and combines its properties with the provided properties.
-
If VO, group, and properties are provided: Uses the specified group and combines its properties with the provided properties.
We set the user details obtained from the user authorize flow in a cookie to be able to map the authorization flow with the corresponding user authorize flow.
Source code in diracx-routers/src/diracx/routers/auth/authorize_code_flow.py
complete_authorization_flow(code, state, request, auth_db, config, settings)
async
Complete the authorization flow.
The user is redirected back to the DIRAC auth service after completing the IAM's authorization flow. We retrieve the original flow details from the decrypted state and store the ID token requested from the IAM. The user is then redirected to the client's redirect URI.
Source code in diracx-routers/src/diracx/routers/auth/authorize_code_flow.py
Device Flow
device_flow
Device flow.
See docs/admin/explanations/authentication.md
Attributes
router = DiracxRouter(require_auth=False)
module-attribute
Classes
Functions
initiate_device_flow(client_id, scope, request, auth_db, config, available_properties, settings)
async
Initiate the device flow against DIRAC authorization Server.
Scope details: - If only VO is provided: Uses the default group and its properties for the VO.
-
If VO and group are provided: Uses the specified group and its properties for the VO.
-
If VO and properties are provided: Uses the default group and combines its properties with the provided properties.
-
If VO, group, and properties are provided: Uses the specified group and combines its properties with the provided properties.
Offers the user to go with the browser to
auth/<vo>/device?user_code=XYZ
Source code in diracx-routers/src/diracx/routers/auth/device_flow.py
do_device_flow(request, auth_db, user_code, config, available_properties, settings)
async
This is called as the verification URI for the device flow. It will redirect to the actual OpenID server (IAM, CheckIn) to perform a authorization code flow.
We set the user_code obtained from the device flow in a cookie to be able to map the authorization flow with the corresponding device flow. (note: it can't be put as parameter or in the URL)
Source code in diracx-routers/src/diracx/routers/auth/device_flow.py
finish_device_flow(request, code, state, auth_db, config, settings)
async
This the url callbacked by IAM/CheckIn after the authorization flow was granted. It gets us the code we need for the authorization flow, and we can map it to the corresponding device flow using the user_code in the cookie/session.
Source code in diracx-routers/src/diracx/routers/auth/device_flow.py
finished(response)
This is the final step of the device flow.
Source code in diracx-routers/src/diracx/routers/auth/device_flow.py
Management
management
This module contains the auth management endpoints.
These endpoints are used to manage the user's authentication tokens and to get information about the user's identity.
Attributes
router = DiracxRouter(require_auth=False)
module-attribute
logger = logging.getLogger(__name__)
module-attribute
Classes
UserInfoResponse
Bases: TypedDict
Response for the userinfo endpoint.
Source code in diracx-routers/src/diracx/routers/auth/management.py
Attributes
sub
instance-attribute
vo
instance-attribute
dirac_group
instance-attribute
policies
instance-attribute
properties
instance-attribute
preferred_username
instance-attribute
Functions
get_refresh_tokens(auth_db, user_info)
async
Get all refresh tokens for the user. If the user has the proxy_management property, then
the subject is not used to filter the refresh tokens.
Source code in diracx-routers/src/diracx/routers/auth/management.py
revoke_refresh_token_by_refresh_token(auth_db, settings, token, token_type_hint=None, client_id='myDIRACClientID')
async
Revoke a refresh token. Closely follows RFC 7009 (or try to, at least).
Source code in diracx-routers/src/diracx/routers/auth/management.py
revoke_refresh_token_by_jti(auth_db, user_info, jti)
async
Revoke a refresh token. If the user has the proxy_management property, then
the subject is not used to filter the refresh tokens.
Source code in diracx-routers/src/diracx/routers/auth/management.py
userinfo(user_info)
async
Get information about the user's identity.
Source code in diracx-routers/src/diracx/routers/auth/management.py
Well Known
well_known
Attributes
router = DiracxRouter(require_auth=False, path_root='')
module-attribute
Classes
Functions
get_openid_configuration(request, config, settings)
async
OpenID Connect discovery endpoint.
Source code in diracx-routers/src/diracx/routers/auth/well_known.py
get_jwks(settings)
async
get_installation_metadata(config)
async
Get metadata about the dirac installation.
get_security_txt()
async
Get the security.txt file.
Source code in diracx-routers/src/diracx/routers/auth/well_known.py
Utilities
utils
Classes
Functions
has_properties(expression)
Check if the user has the given properties.