mindroot.lib.auth package

Submodules

mindroot.lib.auth.api_key module

async mindroot.lib.auth.api_key.verify_api_key(api_key: str) Dict | None[source]

Verify an API key and return user data if valid.

Parameters:

api_key – The API key to verify

Returns:

Dict containing user data if valid, None otherwise

mindroot.lib.auth.auth module

async mindroot.lib.auth.auth.get_current_user(request: Request) Any | None[source]

Get the current authenticated user from the request state.

Parameters:

request – The FastAPI request object

Returns:

The user object if authenticated, None otherwise

async mindroot.lib.auth.auth.require_admin(request: Request, redirect_to_login: bool = False) Any[source]

Dependency to require an authenticated admin user for a route.

Parameters:
  • request – The FastAPI request object

  • redirect_to_login – If True, redirects to /login when not authenticated If False, raises an HTTPException with 401/403 status

Returns:

The user object if authenticated and has admin role

Raises:
  • HTTPException – If the user is not authenticated or lacks admin privileges

  • RedirectResponse – If the user is not authenticated (when redirect_to_login is True)

async mindroot.lib.auth.auth.require_user(request: Request, redirect_to_login: bool = False) Any[source]

Dependency to require an authenticated user for a route.

Parameters:
  • request – The FastAPI request object

  • redirect_to_login – If True, redirects to /login when not authenticated If False, raises an HTTPException with 401 status

Returns:

The user object if authenticated

Raises:
  • HTTPException – If the user is not authenticated (when redirect_to_login is False)

  • RedirectResponse – If the user is not authenticated (when redirect_to_login is True)

Module contents