{"id":13602684,"url":"https://github.com/Colin-b/httpx_auth","last_synced_at":"2025-04-11T09:30:46.195Z","repository":{"id":39298191,"uuid":"238206599","full_name":"Colin-b/httpx_auth","owner":"Colin-b","description":"Authentication classes to be used with httpx","archived":false,"fork":false,"pushed_at":"2025-01-07T18:48:52.000Z","size":615,"stargazers_count":122,"open_issues_count":13,"forks_count":30,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-03-30T13:36:47.352Z","etag":null,"topics":["active-directory","api-key","auth","aws","azure","hacktoberfest","httpx","oauth2","okta","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Colin-b.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-04T12:58:14.000Z","updated_at":"2025-03-30T04:28:51.000Z","dependencies_parsed_at":"2024-01-14T04:37:35.778Z","dependency_job_id":"a364e8ef-0e47-4613-a647-13cc130ca255","html_url":"https://github.com/Colin-b/httpx_auth","commit_stats":{"total_commits":88,"total_committers":7,"mean_commits":"12.571428571428571","dds":"0.20454545454545459","last_synced_commit":"75e0d19491df124e0808fd1c09cc7a18a87ec0c4"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colin-b%2Fhttpx_auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colin-b%2Fhttpx_auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colin-b%2Fhttpx_auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Colin-b%2Fhttpx_auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Colin-b","download_url":"https://codeload.github.com/Colin-b/httpx_auth/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248368186,"owners_count":21092314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active-directory","api-key","auth","aws","azure","hacktoberfest","httpx","oauth2","okta","python"],"created_at":"2024-08-01T18:01:33.747Z","updated_at":"2025-04-11T09:30:46.182Z","avatar_url":"https://github.com/Colin-b.png","language":"Python","readme":"\u003ch2 align=\"center\"\u003eAuthentication for HTTPX\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://pypi.org/project/httpx-auth/\"\u003e\u003cimg alt=\"pypi version\" src=\"https://img.shields.io/pypi/v/httpx_auth\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Colin-b/httpx_auth/actions\"\u003e\u003cimg alt=\"Build status\" src=\"https://github.com/Colin-b/httpx_auth/workflows/Release/badge.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Colin-b/httpx_auth/actions\"\u003e\u003cimg alt=\"Coverage\" src=\"https://img.shields.io/badge/coverage-100%25-brightgreen\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg alt=\"Code style: black\" src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/Colin-b/httpx_auth/actions\"\u003e\u003cimg alt=\"Number of tests\" src=\"https://img.shields.io/badge/tests-783 passed-blue\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/httpx-auth/\"\u003e\u003cimg alt=\"Number of downloads\" src=\"https://img.shields.io/pypi/dm/httpx_auth\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e [!NOTE]  \n\u003e Version 1.0.0 will be released once httpx is considered as stable (release of 1.0.0).\n\u003e\n\u003e However, current state can be considered as stable.\n\nProvides authentication classes to be used with [`httpx`][1] [authentication parameter][2].\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://oauth.net/2/\"\u003e\u003cimg alt=\"OAuth2\" src=\"https://oauth.net/images/oauth-2-sm.png\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.okta.com\"\u003e\u003cimg alt=\"Okta\" src=\"https://www.okta.com/sites/all/themes/Okta/images/logos/developer/Dev_Logo-03_Large.png\" height=\"120\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id\"\u003e\u003cimg alt=\"Microsoft Entra ID, formerly Azure Active Directory (AD)\" src=\"https://svgshare.com/i/12u_.svg\" height=\"120\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html\"\u003e\u003cimg alt=\"AWS Signature Version 4\" src=\"https://upload.wikimedia.org/wikipedia/commons/9/93/Amazon_Web_Services_Logo.svg\" height=\"120\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eSome of the supported authentication\u003c/p\u003e\n\n## Available authentication\n\n- [OAuth2](#oauth-2)\n  - [Authorization Code Flow](#authorization-code-flow)\n    - [Okta](#okta-oauth2-authorization-code)\n    - [WakaTime](#wakatime-oauth2-authorization-code)\n  - [Authorization Code Flow with PKCE](#authorization-code-flow-with-proof-key-for-code-exchange)\n    - [Okta](#okta-oauth2-proof-key-for-code-exchange)\n  - [Resource Owner Password Credentials flow](#resource-owner-password-credentials-flow)\n  - [Client Credentials Flow](#client-credentials-flow)\n    - [Okta](#okta-oauth2-client-credentials)\n  - [Implicit Flow](#implicit-flow)\n    - [Microsoft Entra (Access Token)](#microsoft---azure-active-directory-oauth2-access-token)\n    - [Microsoft Entra (ID token)](#microsoft---azure-active-directory-openid-connect-id-token)\n    - [Okta (Access Token)](#okta-oauth2-implicit-access-token)\n    - [Okta (ID token)](#okta-openid-connect-implicit-id-token)\n  - [Managing token cache](#managing-token-cache)\n  - [Managing browser](#managing-the-web-browser)\n- [Amazon](#aws-signature-v4)\n- API key\n  - [In header](#api-key-in-header)\n  - [In query](#api-key-in-query)\n- [Basic](#basic)\n- [Multiple authentication at once](#multiple-authentication-at-once)\n\n## OAuth 2\n\nMost of [OAuth2](https://oauth.net/2/) flows are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n### Authorization Code flow\n\nAuthorization Code Grant is implemented following [rfc6749](https://tools.ietf.org/html/rfc6749#section-4.1).\n\nUse `httpx_auth.OAuth2AuthorizationCode` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OAuth2AuthorizationCode\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=OAuth2AuthorizationCode('https://www.authorization.url', 'https://www.token.url'))\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n#### Parameters\n\n| Name                    | Description                                                                                                                                                                                                                                                                                       | Mandatory  | Default value  |\n|:------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------|:---------------|\n| `authorization_url`     | OAuth 2 authorization URL.                                                                                                                                                                                                                                                                        | Mandatory  |                |\n| `token_url`             | OAuth 2 token URL.                                                                                                                                                                                                                                                                                | Mandatory  |                |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 code will be started.                                                                                                                                                                                                                      | Optional   | 5000           |\n| `timeout`               | Maximum amount of seconds to wait for a code or a token to be received once requested.                                                                                                                                                                                                            | Optional   | 60             |\n| `header_name`           | Name of the header field used to send token.                                                                                                                                                                                                                                                      | Optional   | Authorization  |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token.                                                                                                                                                                                        | Optional   | Bearer {token} |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL.                                                                                                                                                                                                          | Optional   | code           |\n| `token_field_name`      | Field name containing the token.                                                                                                                                                                                                                                                                  | Optional   | access_token   |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional   | 30.0           |\n| `code_field_name`       | Field name containing the code.                                                                                                                                                                                                                                                                   | Optional   | code           |\n| `username`              | User name in case basic authentication should be used to retrieve token.                                                                                                                                                                                                                          | Optional   |                |\n| `password`              | User password in case basic authentication should be used to retrieve token.                                                                                                                                                                                                                      | Optional   |                |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance.                                                                                                                                                                            | Optional   |                |\n\nAny other parameter will be put as query parameter in the authorization URL and as body parameters in the token URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `client_id`     | Corresponding to your Application ID (in Microsoft Azure app portal) |\n| `client_secret` | If client is not authenticated with the authorization server         |\n| `nonce`         | Refer to [OpenID ID Token specifications][3] for more details        |\n\n#### Common providers\n\nMost of [OAuth2](https://oauth.net/2/) Authorization Code Grant providers are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n##### Okta (OAuth2 Authorization Code)\n\n[Okta Authorization Code Grant](https://developer.okta.com/docs/guides/implement-auth-code/overview/) providing access tokens is supported.\n\nUse `httpx_auth.OktaAuthorizationCode` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaAuthorizationCode\n\n\nokta = OktaAuthorizationCode(instance='testserver.okta-emea.com', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | token |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details. | Optional | Newly generated Universal Unique Identifier. |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Optional | openid |\n| `authorization_server`  | Okta authorization server. | Optional | 'default' |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional |  |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n##### WakaTime (OAuth2 Authorization Code)\n\n[WakaTime Authorization Code Grant](https://wakatime.com/developers#authentication) providing access tokens is supported.\n\nUse `httpx_auth.WakaTimeAuthorizationCode` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import WakaTimeAuthorizationCode\n\n\nwaka_time = WakaTimeAuthorizationCode(client_id=\"aPJQV0op6Pu3b66MWDi9b1wB\", client_secret=\"waka_sec_0c5MB\", scope=\"email\")\nwith httpx.Client() as client:\n    client.get('https://wakatime.com/api/v1/users/current', auth=waka_time)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value                                |\n|:------------------------|:---------------------------|:----------|:---------------------------------------------|\n| `client_id`             | WakaTime Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |                                              |\n| `client_secret`         | WakaTime Application Secret (formatted as waka_sec_ followed by an Universal Unique Identifier). | Mandatory |                                              |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Mandatory |                                              |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional  | token                                        |\n| `token_field_name`      | Field name containing the token. | Optional  | access_token                                 |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0                                         |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details. | Optional  | Newly generated Universal Unique Identifier. |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional  | 5000                                         |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional  | 60                                           |\n| `header_name`           | Name of the header field used to send token. | Optional  | Authorization                                |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional  | Bearer {token}                               |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional  |                                              |\n\nAny other parameter will be put as query parameter in the authorization URL.\n\n### Authorization Code Flow with Proof Key for Code Exchange\n\nProof Key for Code Exchange is implemented following [rfc7636](https://tools.ietf.org/html/rfc7636).\n\nUse `httpx_auth.OAuth2AuthorizationCodePKCE` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OAuth2AuthorizationCodePKCE\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=OAuth2AuthorizationCodePKCE('https://www.authorization.url', 'https://www.token.url'))\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n#### Parameters \n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `authorization_url`     | OAuth 2 authorization URL. | Mandatory |               |\n| `token_url`             | OAuth 2 token URL.         | Mandatory |               |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 code will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a code or a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | code |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `code_field_name`       | Field name containing the code. | Optional | code |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional |  |\n\nAny other parameter will be put as query parameter in the authorization URL and as body parameters in the token URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `client_id`     | Corresponding to your Application ID (in Microsoft Azure app portal) |\n| `client_secret` | If client is not authenticated with the authorization server         |\n| `nonce`         | Refer to [OpenID ID Token specifications][3] for more details        |\n\n#### Common providers\n\nMost of [OAuth2](https://oauth.net/2/) Proof Key for Code Exchange providers are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n##### Okta (OAuth2 Proof Key for Code Exchange)\n\n[Okta Proof Key for Code Exchange](https://developer.okta.com/docs/guides/implement-auth-code-pkce/overview/) providing access tokens is supported.\n\nUse `httpx_auth.OktaAuthorizationCodePKCE` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaAuthorizationCodePKCE\n\n\nokta = OktaAuthorizationCodePKCE(instance='testserver.okta-emea.com', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | code |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `code_field_name`      | Field name containing the code. | Optional | code |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details. | Optional | Newly generated Universal Unique Identifier. |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Optional | openid |\n| `authorization_server`  | Okta authorization server. | Optional | 'default' |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional |  |\n\nAny other parameter will be put as query parameter in the authorization URL and as body parameters in the token URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `client_secret`        | If client is not authenticated with the authorization server     |\n| `nonce`        | Refer to [OpenID ID Token specifications][3] for more details     |\n\n### Resource Owner Password Credentials flow\n\nResource Owner Password Credentials Grant is implemented following [rfc6749](https://tools.ietf.org/html/rfc6749#section-4.3).\n\nUse `httpx_auth.OAuth2ResourceOwnerPasswordCredentials` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OAuth2ResourceOwnerPasswordCredentials\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=OAuth2ResourceOwnerPasswordCredentials('https://www.token.url', 'user name', 'user password'))\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n\n#### Parameters\n\n| Name                 | Description                                                                                                                                                                                                                                                                                       | Mandatory | Default value |\n|:---------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:----------|:--------------|\n| `token_url`          | OAuth 2 token URL.                                                                                                                                                                                                                                                                                | Mandatory |               |\n| `username`           | Resource owner user name.                                                                                                                                                                                                                                                                         | Mandatory |               |\n| `password`           | Resource owner password.                                                                                                                                                                                                                                                                          | Mandatory |               |\n| `client_auth`        | Client authentication if the client type is confidential or the client was issued client credentials (or assigned other authentication requirements). Can be a tuple or any httpx authentication class instance.                                                                                  | Optional  |               |\n| `timeout`            | Maximum amount of seconds to wait for a token to be received once requested.                                                                                                                                                                                                                      | Optional  | 60            |\n| `header_name`        | Name of the header field used to send token.                                                                                                                                                                                                                                                      | Optional  | Authorization |\n| `header_value`       | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token.                                                                                                                                                                                        | Optional  | Bearer {token} |\n| `scope`              | Scope parameter sent to token URL as body. Can also be a list of scopes.                                                                                                                                                                                                                          | Optional  |  |\n| `token_field_name`   | Field name containing the token.                                                                                                                                                                                                                                                                  | Optional  | access_token  |\n| `early_expiry`       | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `client`             | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance.                                                                                                                                                                            | Optional  |  |\n\nAny other parameter will be put as body parameter in the token URL.\n\n#### Common providers\n\nMost of [OAuth2](https://oauth.net/2/) Resource Owner Password Credentials providers are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n##### Okta (OAuth2 Resource Owner Password Credentials)\n\n[Okta Resource Owner Password Credentials](https://developer.okta.com/docs/guides/implement-grant-type/ropassword/main/) providing access tokens is supported.\n\nUse `httpx_auth.OktaResourceOwnerPasswordCredentials` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaResourceOwnerPasswordCredentials\n\n\nokta = OktaResourceOwnerPasswordCredentials(instance='testserver.okta-emea.com', username='user name', password='user password', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd', client_secret=\"0c5MB\")\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `username`           | Resource owner user name.                                                                                                                                                                                                                                                                         | Mandatory |               |\n| `password`           | Resource owner password.                                                                                                                                                                                                                                                                          | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `client_secret`        | Resource owner password.     | Mandatory |               |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Optional | openid |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional |  |\n\nAny other parameter will be put as body parameters in the token URL.\n\n\n### Client Credentials flow\n\nClient Credentials Grant is implemented following [rfc6749](https://tools.ietf.org/html/rfc6749#section-4.4).\n\nUse `httpx_auth.OAuth2ClientCredentials` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OAuth2ClientCredentials\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=OAuth2ClientCredentials('https://www.token.url', client_id='id', client_secret='secret'))\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n\n#### Parameters\n\n| Name               | Description                                  | Mandatory | Default value |\n|:-------------------|:---------------------------------------------|:----------|:--------------|\n| `token_url`        | OAuth 2 token URL.                           | Mandatory |               |\n| `client_id`         | Resource owner user name.                    | Mandatory |               |\n| `client_secret`         | Resource owner password.                     | Mandatory |               |\n| `timeout`          | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60            |\n| `header_name`      | Name of the header field used to send token. | Optional  | Authorization |\n| `header_value`     | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n| `scope`            | Scope parameter sent to token URL as body. Can also be a list of scopes. | Optional |  |\n| `token_field_name` | Field name containing the token.             | Optional  | access_token  |\n| `early_expiry`     | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `client`           | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional |  |\n\nAny other parameter will be put as body parameter in the token URL.\n\n#### Common providers\n\nMost of [OAuth2](https://oauth.net/2/) Client Credentials Grant providers are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n##### Okta (OAuth2 Client Credentials)\n\n[Okta Client Credentials Grant](https://developer.okta.com/docs/guides/implement-grant-type/clientcreds/main/) providing access tokens is supported.\n\nUse `httpx_auth.OktaClientCredentials` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaClientCredentials\n\n\nokta = OktaClientCredentials(instance='testserver.okta-emea.com', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd', client_secret=\"secret\", scope=[\"scope1\", \"scope2\"])\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `client_secret`         | Resource owner password.                     | Mandatory |               |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Mandatory |  |\n| `authorization_server`  | Okta authorization server. | Optional  | 'default' |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional  | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional  | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional  | Bearer {token} |\n| `token_field_name`      | Field name containing the token. | Optional  | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `client`                | `httpx.Client` instance that will be used to request the token. Use it to provide a custom proxying rule for instance. | Optional  |  |\n\nAny other parameter will be put as query parameter in the token URL.        \n\n### Implicit flow\n\nImplicit Grant is implemented following [rfc6749](https://tools.ietf.org/html/rfc6749#section-4.2).\n\nUse `httpx_auth.OAuth2Implicit` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OAuth2Implicit\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=OAuth2Implicit('https://www.authorization.url'))\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n#### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `authorization_url`     | OAuth 2 authorization URL. | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | token |\n| `token_field_name`      | Field name containing the token. | Optional | id_token if response_type is id_token, otherwise access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `client_id`     | Corresponding to your Application ID (in Microsoft Azure app portal) |\n| `nonce`         | Refer to [OpenID ID Token specifications][3] for more details        |\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n#### Common providers\n\nMost of [OAuth2](https://oauth.net/2/) Implicit Grant providers are supported.\n\nIf the one you are looking for is not yet supported, feel free to [ask for its implementation](https://github.com/Colin-b/httpx_auth/issues/new).\n\n##### Microsoft - Azure Active Directory (OAuth2 Access Token)\n\n[Microsoft identity platform access tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/access-tokens) are supported.\n\nUse `httpx_auth.AzureActiveDirectoryImplicit` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import AzureActiveDirectoryImplicit\n\n\naad = AzureActiveDirectoryImplicit(tenant_id='45239d18-c68c-4c47-8bdd-ce71ea1d50cd', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=aad)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\nYou can retrieve Microsoft Azure Active Directory application information thanks to the [application list on Azure portal](https://portal.azure.com/#blade/Microsoft_AAD_IAM/StartboardApplicationsMenuBlade/AllApps/menuId/).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `tenant_id`             | Microsoft Tenant Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `client_id`             | Microsoft Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | token |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details | Optional | Newly generated Universal Unique Identifier. |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n##### Microsoft - Azure Active Directory (OpenID Connect ID token)\n\n[Microsoft identity platform ID tokens](https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens) are supported.\n\nUse `httpx_auth.AzureActiveDirectoryImplicitIdToken` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import AzureActiveDirectoryImplicitIdToken\n\n\naad = AzureActiveDirectoryImplicitIdToken(tenant_id='45239d18-c68c-4c47-8bdd-ce71ea1d50cd', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=aad)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\nYou can retrieve Microsoft Azure Active Directory application information thanks to the [application list on Azure portal](https://portal.azure.com/#blade/Microsoft_AAD_IAM/StartboardApplicationsMenuBlade/AllApps/menuId/).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `tenant_id`             | Microsoft Tenant Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `client_id`             | Microsoft Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | id_token |\n| `token_field_name`      | Field name containing the token. | Optional | id_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details | Optional | Newly generated Universal Unique Identifier. |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n##### Okta (OAuth2 Implicit Access Token)\n\n[Okta Implicit Grant](https://developer.okta.com/docs/guides/implement-implicit/overview/) providing access tokens is supported.\n\nUse `httpx_auth.OktaImplicit` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaImplicit\n\n\nokta = OktaImplicit(instance='testserver.okta-emea.com', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | token |\n| `token_field_name`      | Field name containing the token. | Optional | access_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details. | Optional | Newly generated Universal Unique Identifier. |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Optional | ['openid', 'profile', 'email'] |\n| `authorization_server`  | Okta authorization server. | Optional | 'default' |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n##### Okta (OpenID Connect Implicit ID token)\n\n[Okta Implicit Grant](https://developer.okta.com/docs/guides/implement-implicit/overview/) providing ID tokens is supported.\n\nUse `httpx_auth.OktaImplicitIdToken` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import OktaImplicitIdToken\n\n\nokta = OktaImplicitIdToken(instance='testserver.okta-emea.com', client_id='54239d18-c68c-4c47-8bdd-ce71ea1d50cd')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=okta)\n```\n\nNote:\n* You can persist tokens thanks to [the token cache](#managing-token-cache).\n* You can tweak web browser interaction thanks to [the display settings](#managing-the-web-browser).\n\n###### Parameters\n\n| Name                    | Description                | Mandatory | Default value |\n|:------------------------|:---------------------------|:----------|:--------------|\n| `instance`              | Okta instance (like \"testserver.okta-emea.com\"). | Mandatory |               |\n| `client_id`             | Okta Application Identifier (formatted as an Universal Unique Identifier). | Mandatory |               |\n| `response_type`         | Value of the response_type query parameter if not already provided in authorization URL. | Optional | id_token |\n| `token_field_name`      | Field name containing the token. | Optional | id_token |\n| `early_expiry`          | Number of seconds before actual token expiry where token will be considered as expired. Used to ensure token will not expire between the time of retrieval and the time the request reaches the actual server. Set it to 0 to deactivate this feature and use the same token until actual expiry. | Optional  | 30.0  |\n| `nonce`                 | Refer to [OpenID ID Token specifications][3] for more details. | Optional | Newly generated Universal Unique Identifier. |\n| `scope`                 | Scope parameter sent in query. Can also be a list of scopes. | Optional | ['openid', 'profile', 'email'] |\n| `authorization_server`  | Okta authorization server. | Optional | 'default' |\n| `redirect_uri_domain`   | [FQDN](https://en.wikipedia.org/wiki/Fully_qualified_domain_name) to use in the redirect_uri when localhost is not allowed.                                                                                                                                                                       | Optional   | localhost      |\n| `redirect_uri_endpoint` | Custom endpoint that will be used as redirect_uri the following way: http://\u003credirect_uri_domain\u003e:\u003credirect_uri_port\u003e/\u003credirect_uri_endpoint\u003e.                                                                                                                                                    | Optional   | ''             |\n| `redirect_uri_port`     | The port on which the server listening for the OAuth 2 token will be started. | Optional | 5000 |\n| `timeout`               | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |\n| `header_name`           | Name of the header field used to send token. | Optional | Authorization |\n| `header_value`          | Format used to send the token value. \"{token}\" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |\n\nAny other parameter will be put as query parameter in the authorization URL.        \n\nUsual extra parameters are:\n        \n| Name            | Description                                                          |\n|:----------------|:---------------------------------------------------------------------|\n| `prompt`        | none to avoid prompting the user if a session is already opened.     |\n\n### Managing token cache\n\nTo avoid asking for a new token every new request, a token cache is used.\n\nDefault cache is in memory, but it is also possible to use a physical cache.\n\nYou need to provide the location of your token cache file. It can be a full or relative path (`str` or `pathlib.Path`).\n\nIf the file already exists it will be used, if the file do not exist it will be created.\n\n```python\nfrom httpx_auth import OAuth2, JsonTokenFileCache\n\nOAuth2.token_cache = JsonTokenFileCache('path/to/my_token_cache.json')\n```\n\n### Managing the web browser\n\n#### Authentication response pages\n\nYou can configure the browser display settings thanks to `httpx_auth.OAuth2.display` as in the following:\n```python\nfrom httpx_auth import OAuth2, DisplaySettings\n\nOAuth2.display = DisplaySettings()\n```\n\nThe following parameters can be provided to `DisplaySettings`:\n\n| Name                   | Description                                                                                                                                                                      | Default value |\n|:-----------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------|\n| `success_display_time` | In case a code or token is successfully received, this is the maximum amount of milliseconds the success page will be displayed in your browser.                                 | 1             |\n| `success_html`         | In case a code or token is successfully received, this is the success page that will be displayed in your browser. `{display_time}` is expected in this content.                 |               |\n| `failure_display_time` | In case received code or token is not valid, this is the maximum amount of milliseconds the failure page will be displayed in your browser.                                      | 10_000        |\n| `failure_html`         | In case received code or token is not valid, this is the failure page that will be displayed in your browser. `{information}` and `{display_time}` are expected in this content. |               |\n\n#### Text-mode web browser\n\nThis project uses [`webbrowser.open()`][4] to open a web browser to support authentication flows like OAuth's Authorization Code grant. When running graphically, `webbrowser.open()` does not block. But when run in text mode, `webbrowser.open()` blocks until the opened browser is closed, which leads to a deadlock when httpx-auth cannot serve the auth response pages to the webbrowser. To work around this, you can specify a `BROWSER` environment variable that contains a `%s` and ends with a `\u0026`, and the `webbrowser` module will open the text-mode browser in a subprocess and allow httpx-auth to serve the auth response pages to the browser without deadlocking.\n\n```bash\nBROWSER=\"/usr/bin/links %s \u0026\"\n```\n\nFor more information, please see the implementation of [`webbrowser.get()`][5].\n\n## AWS Signature v4\n\nAmazon Web Service Signature version 4 is implemented following [Amazon S3 documentation](https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html) and [request-aws4auth 1.2.3](https://github.com/sam-washington/requests-aws4auth) (with some changes, see below).\n\nUse `httpx_auth.AWS4Auth` to configure this kind of authentication.\n\n```python\nimport httpx\nfrom httpx_auth import AWS4Auth\n\naws = AWS4Auth(access_id=\"my-access-id\", secret_key=\"my-secret-key\", region=\"eu-west-1\", service=\"s3\")\nwith httpx.Client() as client:\n    client.get('http://s3-eu-west-1.amazonaws.com', auth=aws)\n```\n\nNote that the following changes were made compared to `requests-aws4auth`:\n  - Each request now has its own signing key and `x-amz-date`. Meaning **you can use the same auth instance for more than one request**.\n  - `session_token` was renamed into `security_token` for consistency with the underlying name at Amazon.\n  - `include_hdrs` parameter was renamed into `include_headers`. When using this parameter:\n    - Provided values will not be stripped, [WYSIWYG](https://en.wikipedia.org/wiki/WYSIWYG).\n    - If multiple values are provided for a same header, the computation will be based on the value order you provided and value separated by `, `. Instead of ordered values separated by comma for `requests-aws4auth`.\n  - `amz_date` attribute has been removed.\n  - It is not possible to provide a `date`. It will default to now.\n  - It is not possible to provide an `AWSSigningKey` instance, use explicit parameters instead.\n  - It is not possible to provide `raise_invalid_date` parameter anymore as the date will always be valid.\n  - `host` is not considered as a specific Amazon service anymore (no test specific code).\n  - Canonical query string computation is entirely based on AWS documentation (and consider undocumented fragment (`#` and following characters) as part of the query string).\n  - Canonical uri computation is entirely based on AWS documentation.\n  - Canonical headers computation is entirely based on AWS documentation.\n\n### Parameters\n\n| Name               | Description                                                                                                                                                                                    | Mandatory  | Default value                                                                                                            |\n|:-------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------|:-------------------------------------------------------------------------------------------------------------------------|\n| `access_id`        | AWS access ID.                                                                                                                                                                                 | Mandatory  |                                                                                                                          |\n| `secret_key`       | AWS secret access key.                                                                                                                                                                         | Mandatory  |                                                                                                                          |\n| `region`           | The region you are connecting to, as per [this list](http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region). For services which do not require a region (e.g. IAM), use us-east-1. | Mandatory  |                                                                                                                          |\n| `service`          | The name of the service you are connecting to, as per [this list](http://docs.aws.amazon.com/general/latest/gr/rande.html). e.g. elasticbeanstalk.                                             | Mandatory  |                                                                                                                          |\n| `security_token`   | Used for the `x-amz-security-token` header, for use with STS temporary credentials.                                                                                                            | Optional   |                                                                                                                          |\n| `include_headers`  | Set of headers to include in the canonical and signed headers (in addition to the default). Note that `x-amz-client-context` is not included by default and `*` will include all headers.      | Optional   | {\"host\", \"content-type\", \"x-amz-*\"} and if `security_token` is provided, `x-amz-security-token`. |\n\n### Dynamically retrieving credentials using boto3\n\nWhile `httpx-auth` does not want to include support for `botocore`, the following authentication class should allow you to automatically retrieve up-to-date credentials.\n\n```python\nimport httpx\nfrom botocore.session import Session\nfrom httpx_auth import AWS4Auth\n\nclass AWS4BotoAuth(AWS4Auth):\n    def __init__(self, region: str, service: str = \"s3\", **kwargs):\n        self.refreshable_credentials = Session().get_credentials()\n        AWS4Auth.__init__(self, access_id=kwargs.pop(\"access_id\", \"_\"), secret_key=kwargs.pop(\"secret_key\", \"_\"), region=region, service=service, **kwargs)\n\n    def auth_flow(self, request):\n        self.refresh_credentials()\n        return super().auth_flow(request)\n\n    def refresh_credentials(self):\n        credentials = self.refreshable_credentials.get_frozen_credentials()\n        self.access_id = credentials.access_key\n        self.secret_key = credentials.secret_key\n        self.security_token = credentials.token\n\n\naws = AWS4BotoAuth(region=\"eu-west-1\")\nwith httpx.Client() as client:\n    client.get('http://s3-eu-west-1.amazonaws.com', auth=aws)\n```\n\n## API key in header\n\nYou can send an API key inside the header of your request using `httpx_auth.HeaderApiKey`.\n\n```python\nimport httpx\nfrom httpx_auth import HeaderApiKey\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=HeaderApiKey('my_api_key'))\n```\n\n### Parameters\n\n| Name                    | Description                    | Mandatory | Default value |\n|:------------------------|:-------------------------------|:----------|:--------------|\n| `api_key`               | The API key that will be sent. | Mandatory |               |\n| `header_name`           | Name of the header field.      | Optional  | \"X-API-Key\"   |\n\n## API key in query\n\nYou can send an API key inside the query parameters of your request using `httpx_auth.QueryApiKey`.\n\n```python\nimport httpx\nfrom httpx_auth import QueryApiKey\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=QueryApiKey('my_api_key'))\n```\n\n### Parameters\n\n| Name                    | Description                    | Mandatory | Default value |\n|:------------------------|:-------------------------------|:----------|:--------------|\n| `api_key`               | The API key that will be sent. | Mandatory |               |\n| `query_parameter_name`  | Name of the query parameter.   | Optional  | \"api_key\"     |\n\n## Basic\n\nYou can use basic authentication using `httpx_auth.Basic`.\n\nThe only advantage of using this class instead of `httpx` native support of basic authentication, is to be able to use it in [multiple authentication](#multiple-authentication-at-once).\n\n```python\nimport httpx\nfrom httpx_auth import Basic\n\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=Basic('username', 'password'))\n```\n\n### Parameters\n\n| Name                    | Description                    | Mandatory | Default value |\n|:------------------------|:-------------------------------|:----------|:--------------|\n| `username`              | User name.                     | Mandatory |               |\n| `password`              | User password.                 | Mandatory |               |\n\n## Multiple authentication at once\n\nYou can also use a combination of authentication using `+`or `\u0026`  as in the following sample:\n\n```python\nimport httpx\nfrom httpx_auth import HeaderApiKey, OAuth2Implicit\n\napi_key = HeaderApiKey('my_api_key')\noauth2 = OAuth2Implicit('https://www.example.com')\nwith httpx.Client() as client:\n    client.get('https://www.example.com', auth=api_key + oauth2)\n```\n\nThis is supported on every authentication class exposed by `httpx_auth`, but you can also enable it on your own authentication classes by using `httpx_auth.SupportMultiAuth` as in the following sample:\n\n```python\nfrom httpx_auth import SupportMultiAuth\n# TODO Import your own auth here\nfrom my_package import MyAuth\n\nclass MyMultiAuth(MyAuth, SupportMultiAuth):\n    pass\n```\n\n\n## Available pytest fixtures\n\nTesting the code using `httpx_auth` authentication classes can be achieved using provided [`pytest`][6] fixtures.\n\n### token_cache_mock\n\n```python\nfrom httpx_auth.testing import token_cache_mock, token_mock\n\ndef test_something(token_cache_mock):\n    # perform code using authentication\n    pass\n```\n\nUse this fixture to mock authentication success for any of the following classes:\n * `OAuth2AuthorizationCodePKCE`\n * `OktaAuthorizationCodePKCE`\n * `OAuth2Implicit`\n * `OktaImplicit`\n * `OktaImplicitIdToken`\n * `AzureActiveDirectoryImplicit`\n * `AzureActiveDirectoryImplicitIdToken`\n * `OAuth2AuthorizationCode`\n * `OktaAuthorizationCode`\n * `WakaTimeAuthorizationCode`\n * `OAuth2ClientCredentials`\n * `OktaClientCredentials`\n * `OAuth2ResourceOwnerPasswordCredentials`\n * `OktaResourceOwnerPasswordCredentials`\n\nBy default, an access token with value `2YotnFZFEjr1zCsicMWpAA` is generated.\n\nYou can however return your custom token by providing your own `token_mock` fixture as in the following sample:\n\n```python\nimport pytest\n\nfrom httpx_auth.testing import token_cache_mock\n\n\n@pytest.fixture\ndef token_mock() -\u003e str:\n    return \"MyCustomTokenValue\"\n\n\ndef test_something(token_cache_mock):\n    # perform code using authentication\n    pass\n```\n\nYou can even return a more complex token by using the `create_token` function.\n\nNote that [`pyjwt`](https://pypi.org/project/PyJWT/) is a required dependency in this case as it is used to generate the token returned by the authentication.\n\n```python\nimport pytest\nfrom httpx_auth.testing import token_cache_mock, create_token\n\n\n@pytest.fixture\ndef token_mock() -\u003e str:\n    expiry = None  # TODO Compute your expiry\n    return create_token(expiry)\n\n\ndef test_something(token_cache_mock):\n    # perform code using authentication\n    pass\n```\n\n### Advanced testing\n\n#### token_cache\n\nThis [`pytest`][6] fixture will return the token cache and ensure it is reset at the end of the test case.\n\n```python\nfrom httpx_auth.testing import token_cache\n\ndef test_something(token_cache):\n    # perform code using authentication\n    pass\n```\n\n#### browser_mock\n\nThis [`pytest`][6] fixture will allow to mock the behavior of a web browser.\n\nWith this [`pytest`][6] fixture you will be allowed to fine tune your authentication related failures handling.\n\n[`pyjwt`](https://pypi.org/project/PyJWT/) is a required dependency if you use `create_token` helper function.\n\n```python\nimport datetime\n\nfrom httpx_auth.testing import browser_mock, BrowserMock, create_token\n\ndef test_something(browser_mock: BrowserMock):\n    token_expiry = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)\n    token = create_token(token_expiry)\n    tab = browser_mock.add_response(\n        opened_url=\"http://url_opened_by_browser?state=1234\",\n        reply_url=f\"http://localhost:5000#access_token={token}\u0026state=1234\",\n    )\n\n    # perform code using authentication\n\n    tab.assert_success()\n```\n\n[1]: https://pypi.python.org/pypi/httpx \"httpx module\"\n[2]: https://www.python-httpx.org/advanced/#customizing-authentication \"authentication parameter on httpx module\"\n[3]: https://openid.net/specs/openid-connect-core-1_0.html#IDToken \"OpenID ID Token specifications\"\n[4]: https://docs.python.org/3/library/webbrowser.html#webbrowser.open \"Python webbrowser module\"\n[5]: https://github.com/python/cpython/blob/main/Lib/webbrowser.py \"Python webbrowser module code\"\n[6]: https://docs.pytest.org/en/latest/ \"pytest module\"\n","funding_links":[],"categories":["Python","azure"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColin-b%2Fhttpx_auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FColin-b%2Fhttpx_auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FColin-b%2Fhttpx_auth/lists"}