app.middlewares.authentication module

async app.middlewares.authentication.auth_api_key_or_oauth2(api_key=Depends(get_api_key_header), oauth_2_scheme=Depends(CustomOAuth2AuthorizationCodeBearer))[source]

Authenticate a request using an API key or, failing that, OAuth2.

The API key is tried first: if a valid key is present the request is authenticated immediately. Otherwise the request falls back to OAuth2 bearer-token validation.

Parameters:
  • api_key (str) – The API key resolved from the X-API-Key header via ApiKeyService.get_api_key_header.

  • oauth_2_scheme (str) – The OAuth2 bearer token extracted from the Authorization header.

Returns:

boolTrue if either credential is valid.

Raises:

HTTPException401 if both mechanisms fail.

async app.middlewares.authentication.auth_oauth2(oauth_2_scheme=Depends(CustomOAuth2AuthorizationCodeBearer))[source]

Authenticate a request using an OAuth2 bearer token.

Parameters:

oauth_2_scheme (str) – The OAuth2 bearer token extracted from the Authorization header.

Returns:

boolTrue if the token is valid.

Raises:

HTTPException401 if OAuth2 authentication fails.