Exceptions#

All exceptions raised by the py_oidc_auth_client library.

exception py_oidc_auth_client.exceptions.AuthError(message: str, detail: Dict[str, Any] | None = None, status_code: int = 500)#

Bases: Exception

Authentication or token exchange failed.

Parameters:
  • message (str) – Human readable summary of what went wrong.

  • detail (dict, optional) – Raw error payload from the OIDC provider, typically containing "error" and "error_description" keys.

  • status_code (int) – HTTP status code from the upstream response. Defaults to 500 when the error did not originate from an HTTP call.

message#

The error summary.

Type:

str

detail#

Provider error payload (empty dict if not available).

Type:

dict

status_code#

HTTP status code.

Type:

int

Examples

Catching authentication failures:

from py_oidc_auth_client import authenticate
from py_oidc_auth_client.exceptions import AuthError

try:
    token = authenticate(host="https://myapp.example.com")
except AuthError as exc:
    print(f"Login failed ({exc.status_code}): {exc}")