{"id":4567,"library":"httpx-auth","title":"HTTPX Auth","description":"httpx-auth is a Python library that provides a collection of authentication classes designed for use with the HTTPX client library. It supports various authentication schemes, including OAuth2 (Authorization Code, PKCE, Client Credentials, Resource Owner Password Credentials, Implicit flows), Okta, Microsoft Entra ID (formerly Azure AD), and AWS Signature Version 4. While a 1.0.0 release is pending HTTPX's own 1.0.0, the library is considered stable and is actively maintained.","status":"active","version":"0.23.1","language":"en","source_language":"en","source_url":"https://github.com/Colin-b/httpx_auth","tags":["http","authentication","httpx","oauth","oauth2","aws","okta"],"install":[{"cmd":"pip install httpx-auth","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core HTTP client library extended by httpx-auth.","package":"httpx","optional":false}],"imports":[{"symbol":"OAuth2AuthorizationCode","correct":"from httpx_auth import OAuth2AuthorizationCode"},{"symbol":"AWS4Auth","correct":"from httpx_auth import AWS4Auth"},{"symbol":"OktaAuthorizationCodePKCE","correct":"from httpx_auth import OktaAuthorizationCodePKCE"},{"symbol":"MicrosoftEntraID","correct":"from httpx_auth import MicrosoftEntraID"}],"quickstart":{"code":"import httpx\nimport os\nfrom httpx_auth import OAuth2AuthorizationCode\n\n# In a real application, these would come from environment variables or a secure configuration\n# For this example, we use placeholders. Replace with your actual OAuth2 application details.\nCLIENT_ID = os.environ.get(\"OAUTH_CLIENT_ID\", \"your_client_id\")\nAUTHORIZATION_URL = os.environ.get(\"OAUTH_AUTH_URL\", \"https://example.com/oauth/authorize\")\nTOKEN_URL = os.environ.get(\"OAUTH_TOKEN_URL\", \"https://example.com/oauth/token\")\n\ntry:\n    auth = OAuth2AuthorizationCode(\n        client_id=CLIENT_ID,\n        authorization_url=AUTHORIZATION_URL,\n        token_url=TOKEN_URL,\n        # For local development, redirect_uri would typically be a local callback URL.\n        # httpx-auth will start a local server to capture the redirect.\n        # Ensure this matches what's configured for your OAuth2 client application.\n        # Example: redirect_uri=\"http://localhost:8000/callback\", port=8000\n    )\n\n    with httpx.Client() as client:\n        # The first request will trigger the OAuth2 flow:\n        # 1. Opens a browser for user consent.\n        # 2. User grants permission, browser redirects to redirect_uri.\n        # 3. httpx-auth captures the code and exchanges it for a token.\n        # 4. The request to the protected resource is then made with the acquired token.\n        response = client.get(\"https://api.example.com/protected-resource\", auth=auth)\n        response.raise_for_status()\n        print(f\"Successfully authenticated and fetched data: {response.json()}\")\n\nexcept httpx.HTTPStatusError as e:\n    print(f\"HTTP error occurred: {e.response.status_code} - {e.response.text}\")\nexcept httpx.RequestError as e:\n    print(f\"An error occurred while making the request: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to use `OAuth2AuthorizationCode` with HTTPX. It sets up an authentication object with placeholder OAuth2 URLs and a client ID. When `client.get()` is called, `httpx-auth` will manage the OAuth2 Authorization Code flow, typically by opening a browser for user interaction to obtain an access token, which is then used for the request. Remember to replace placeholder URLs and client ID with your actual values and configure the `redirect_uri` for your OAuth2 application if running locally."},"warnings":[{"fix":"Ensure you manage the lifecycle of `httpx.Client` instances passed to `httpx-auth` authentication classes. Wrap client usage in a `with httpx.Client() as client:` block or explicitly call `client.close()`.","message":"When providing an `httpx.Client` instance as a parameter to any `httpx-auth` OAuth2 authentication class (e.g., `client` parameter in `OAuth2AuthorizationCode`), `httpx-auth` no longer closes this client automatically. Users are now responsible for explicitly closing these client instances when they are no longer needed to prevent resource leaks.","severity":"breaking","affected_versions":"0.23.0 and later"},{"fix":"Review the `AWS4Auth` documentation for `httpx-auth` to understand the current parameter requirements and behaviors. Adjust your code to use explicit `access_id`, `secret_key`, and `region` parameters, and avoid relying on previously supported `requests-aws4auth` specific attributes or behaviors.","message":"The `AWS4Auth` class, ported from `requests-aws4auth`, has specific behavioral changes and deprecated attributes compared to its origin. Notably, the `amz_date` attribute has been removed, direct provision of `AWSSigningKey` instances is not supported (use explicit parameters instead), and the `date` parameter now defaults to `now()` without options to override or raise on invalid date.","severity":"gotcha","affected_versions":"All versions supporting AWS4Auth (0.22.0 and later)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}