Skip to content

Commit 0704228

Browse files
authored
Merge pull request #79 from Colin-b/develop
Release 0.20.0
2 parents 5def556 + e928e2b commit 0704228

File tree

91 files changed

+13635
-1782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+13635
-1782
lines changed

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
python -m pip install .[testing]
2626
- name: Test with pytest
2727
run: |
28-
pytest --cov=httpx_auth --cov-fail-under=100 --cov-report=term-missing
28+
pytest --doctest-modules --cov=httpx_auth --cov-fail-under=100 --cov-report=term-missing
2929
- name: Create packages
3030
run: |
3131
python -m pip install build

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
python -m pip install .[testing]
2323
- name: Test with pytest
2424
run: |
25-
pytest --cov=httpx_auth --cov-fail-under=100 --cov-report=term-missing
25+
pytest --doctest-modules --cov=httpx_auth --cov-fail-under=100 --cov-report=term-missing
2626
- name: Create packages
2727
run: |
2828
python -m pip install build

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 23.12.1
3+
rev: 24.1.1
44
hooks:
55
- id: black

CHANGELOG.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.20.0] - 2024-02-12
10+
### Fixed
11+
- Remove deprecation warnings due to usage of `utcnow` and `utcfromtimestamp`. Thanks to [`Raphael Krupinski`](https://github.com/rafalkrupinski).
12+
- `httpx_auth.AWS4Auth.default_include_headers` value kept growing in size every time a new `httpx_auth.AWS4Auth` instance was created with `security_token` parameter provided. Thanks to [`Miikka Koskinen`](https://github.com/miikka).
13+
- `httpx_auth.AWS4Auth` is now based almost entirely on AWS documentation, diverging from the original implementation based on `requests-aws4auth` and solving implementation issues in the process.
14+
- As the AWS documentation might be wrong or not exhaustive enough, feel free to open issues, should you encounter edge cases.
15+
16+
### Changed
17+
- `httpx_auth.AWS4Auth.default_include_headers` is not available anymore, use `httpx_auth.AWS4Auth` `include_headers` parameter instead to include additional headers if the default does not fit your need (refer to documentation for an exhaustive list).
18+
- `httpx_auth.AWS4Auth` `include_headers` values will not be stripped anymore, meaning that you can now include headers prefixed and/or suffixed with blank spaces.
19+
- `httpx_auth.AWS4Auth` does not includes `date` header by default anymore. You will have to provide it via `include_headers` yourself if you need to.
20+
- Note that it should not be required as `httpx_auth.AWS4Auth` is sending `x-amz-date` by default and AWS documentation states that the request date can be specified by using either the HTTP `Date` or the `x-amz-date` header. If both headers are present, `x-amz-date` takes precedence.
21+
- `httpx_auth.AWS4Auth` `include_headers` does not needs to include `host`, `content-type` or `x-amz-*` anymore as those headers will always be included. It is now expected to be provided as a list of additional headers.
22+
- `httpx_auth.AWS4Auth` will not modify the headers values spaces when computing the canonical headers, only trim leading and trailing whitespaces as per AWS documentation.
23+
924
## [0.19.0] - 2024-01-09
1025
### Added
1126
- Explicit support for Python 3.12
@@ -112,7 +127,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
112127

113128
### Changed
114129
- `get_token` cache method now requires `on_missing_token` function args to be provided as kwargs instead of args.
115-
- `get_token` cache method now requires `on_missing_token` parameter to be provided as a non positional argument.
130+
- `get_token` cache method now requires `on_missing_token` parameter to be provided as a non-positional argument.
116131
- `get_token` cache method now expose `early_expiry` parameter, defaulting to 30 seconds.
117132

118133
### Fixed
@@ -164,13 +179,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
164179
### Added
165180
- Still under development, subject to breaking changes without notice: `AWS4Auth` authentication class for AWS. Ported from [`requests-aws4auth`](https://github.com/sam-washington/requests-aws4auth) by [`Michael E. Martinka`](https://github.com/martinka).
166181
Note that a few changes were made:
167-
- deprecated `amz_date` attribute has been removed.
168-
- it is not possible to provide an `AWSSigningKey` instance, use explicit parameters instead.
169-
- it is not possible to provide a `date`. It will default to now.
170-
- it is not possible to provide `raise_invalid_date` parameter anymore as the date will always be valid.
182+
- Deprecated `amz_date` attribute has been removed.
183+
- It is not possible to provide an `AWSSigningKey` instance, use explicit parameters instead.
184+
- It is not possible to provide a `date`. It will default to now.
185+
- It is not possible to provide `raise_invalid_date` parameter anymore as the date will always be valid.
171186
- `include_hdrs` parameter was renamed into `include_headers`
172187
- `host` is not considered as a specific Amazon service anymore (no test specific code).
173-
- Each request now has it's own signing key and x-amz-date. Meaning you can use the same auth instance for more than one request.
188+
- 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.
174189
- `session_token` was renamed into `security_token` for consistency with the underlying name at Amazon.
175190

176191
## [0.3.0] - 2020-05-26
@@ -193,7 +208,8 @@ Note that a few changes were made:
193208
### Added
194209
- Placeholder for port of requests_auth to httpx
195210

196-
[Unreleased]: https://github.com/Colin-b/httpx_auth/compare/v0.19.0...HEAD
211+
[Unreleased]: https://github.com/Colin-b/httpx_auth/compare/v0.20.0...HEAD
212+
[0.20.0]: https://github.com/Colin-b/httpx_auth/compare/v0.19.0...v0.20.0
197213
[0.19.0]: https://github.com/Colin-b/httpx_auth/compare/v0.18.0...v0.19.0
198214
[0.18.0]: https://github.com/Colin-b/httpx_auth/compare/v0.17.0...v0.18.0
199215
[0.17.0]: https://github.com/Colin-b/httpx_auth/compare/v0.16.0...v0.17.0

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Before creating an issue please make sure that it was not already reported.
2121

2222
1) Go to the *Issues* tab and click on the *New issue* button.
2323
2) Title should be a small sentence describing the request.
24-
3) The comment should contains as much information as possible
24+
3) The comment should contain as much information as possible
2525
* Actual behavior (including the version you used)
2626
* Expected behavior
2727
* Steps to reproduce
@@ -56,7 +56,7 @@ Before creating an issue please make sure that it was not already reported.
5656
1) Go to the *Pull requests* tab and click on the *New pull request* button.
5757
2) *base* should always be set to `develop` and it should be compared to your branch.
5858
3) Title should be a small sentence describing the request.
59-
3) The comment should contains as much information as possible
59+
4) The comment should contain as much information as possible
6060
* Actual behavior (before the new code)
6161
* Expected behavior (with the new code)
6262
* Steps to reproduce (with and without the new code to see the difference)

README.md

+30-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="https://github.com/Colin-b/httpx_auth/actions"><img alt="Build status" src="https://github.com/Colin-b/httpx_auth/workflows/Release/badge.svg"></a>
66
<a href="https://github.com/Colin-b/httpx_auth/actions"><img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"></a>
77
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
8-
<a href="https://github.com/Colin-b/httpx_auth/actions"><img alt="Number of tests" src="https://img.shields.io/badge/tests-335 passed-blue"></a>
8+
<a href="https://github.com/Colin-b/httpx_auth/actions"><img alt="Number of tests" src="https://img.shields.io/badge/tests-681 passed-blue"></a>
99
<a href="https://pypi.org/project/httpx-auth/"><img alt="Number of downloads" src="https://img.shields.io/pypi/dm/httpx_auth"></a>
1010
</p>
1111

@@ -18,7 +18,8 @@ Provides authentication classes to be used with [`httpx`][1] [authentication par
1818
<p align="center">
1919
<a href="https://oauth.net/2/"><img alt="OAuth2" src="https://oauth.net/images/oauth-2-sm.png"></a>
2020
<a href="https://www.okta.com"><img alt="Okta" src="https://www.okta.com/sites/all/themes/Okta/images/logos/developer/Dev_Logo-03_Large.png" height="120"></a>
21-
<a href="https://azure.microsoft.com/en-us/services/active-directory/"><img alt="Azure Active Directory (AD)" src="https://azurecomcdn.azureedge.net/cvt-cda59ccd0aa5ced6ff5a2052417cf596b92980921e88e667127eaca2232a31ab/images/shared/services/pricing-glyph-lock.svg" height="120"></a>
21+
<a href="https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id"><img alt="Microsoft Entra ID, formerly Azure Active Directory (AD)" src="https://svgshare.com/i/12u_.svg" height="120"></a>
22+
<a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html"><img alt="AWS Signature Version 4" src="https://upload.wikimedia.org/wikipedia/commons/9/93/Amazon_Web_Services_Logo.svg" height="120"></a>
2223
</p>
2324
<p align="center">Some of the supported authentication</p>
2425

@@ -34,8 +35,8 @@ Provides authentication classes to be used with [`httpx`][1] [authentication par
3435
- [Client Credentials Flow](#client-credentials-flow)
3536
- [Okta](#okta-oauth2-client-credentials)
3637
- [Implicit Flow](#implicit-flow)
37-
- [Azure AD (Access Token)](#microsoft---azure-active-directory-oauth2-access-token)
38-
- [Azure AD (ID token)](#microsoft---azure-active-directory-openid-connect-id-token)
38+
- [Microsoft Entra (Access Token)](#microsoft---azure-active-directory-oauth2-access-token)
39+
- [Microsoft Entra (ID token)](#microsoft---azure-active-directory-openid-connect-id-token)
3940
- [Okta (Access Token)](#okta-oauth2-implicit-access-token)
4041
- [Okta (ID token)](#okta-openid-connect-implicit-id-token)
4142
- [Managing token cache](#managing-token-cache)
@@ -667,7 +668,7 @@ OAuth2.token_cache = JsonTokenFileCache('path/to/my_token_cache.json')
667668

668669
## AWS Signature v4
669670

670-
Amazon 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](https://github.com/sam-washington/requests-aws4auth).
671+
Amazon 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).
671672

672673
Use `httpx_auth.AWS4Auth` to configure this kind of authentication.
673674

@@ -680,15 +681,31 @@ with httpx.Client() as client:
680681
client.get('http://s3-eu-west-1.amazonaws.com', auth=aws)
681682
```
682683

684+
Note that the following changes were made compared to `requests-aws4auth`:
685+
- 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**.
686+
- `session_token` was renamed into `security_token` for consistency with the underlying name at Amazon.
687+
- `include_hdrs` parameter was renamed into `include_headers`. When using this parameter:
688+
- Provided values will not be stripped, [WYSIWYG](https://en.wikipedia.org/wiki/WYSIWYG).
689+
- 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`.
690+
- `amz_date` attribute has been removed.
691+
- It is not possible to provide a `date`. It will default to now.
692+
- It is not possible to provide an `AWSSigningKey` instance, use explicit parameters instead.
693+
- It is not possible to provide `raise_invalid_date` parameter anymore as the date will always be valid.
694+
- `host` is not considered as a specific Amazon service anymore (no test specific code).
695+
- Canonical query string computation is entirely based on AWS documentation (and consider undocumented fragment (`#` and following characters) as part of the query string).
696+
- Canonical uri computation is entirely based on AWS documentation.
697+
- Canonical headers computation is entirely based on AWS documentation.
698+
683699
### Parameters
684700

685-
| Name | Description | Mandatory | Default value |
686-
|:-----------------|:---------------------------|:----------|:--------------|
687-
| `access_id` | AWS access ID. | Mandatory | |
688-
| `secret_key` | AWS secret access key. | Mandatory | |
689-
| `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 | |
690-
| `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 | |
691-
| `security_token` | Used for the `x-amz-security-token` header, for use with STS temporary credentials. | Optional | |
701+
| Name | Description | Mandatory | Default value |
702+
|:-------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------|:-------------------------------------------------------------------------------------------------------------------------|
703+
| `access_id` | AWS access ID. | Mandatory | |
704+
| `secret_key` | AWS secret access key. | Mandatory | |
705+
| `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 | |
706+
| `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 | |
707+
| `security_token` | Used for the `x-amz-security-token` header, for use with STS temporary credentials. | Optional | |
708+
| `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`. |
692709

693710
## API key in header
694711

@@ -859,7 +876,7 @@ import datetime
859876
from httpx_auth.testing import browser_mock, BrowserMock, create_token
860877

861878
def test_something(browser_mock: BrowserMock):
862-
token_expiry = datetime.datetime.utcnow() + datetime.timedelta(hours=1)
879+
token_expiry = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(hours=1)
863880
token = create_token(token_expiry)
864881
tab = browser_mock.add_response(
865882
opened_url="http://url_opened_by_browser?state=1234",

0 commit comments

Comments
 (0)