Skip to content

Commit

Permalink
Merge pull request #53 from Colin-b/develop
Browse files Browse the repository at this point in the history
Release 5.0.2
  • Loading branch information
Colin-b authored Dec 12, 2019
2 parents 0aad9c2 + 4734752 commit e9e7c48
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ python:
install:
- pip install .[testing]
script:
- pytest
- pytest --cov=requests_auth --cov-fail-under=100
deploy:
provider: pypi
username: __token__
edge: true
distributions: "sdist bdist_wheel"
distributions: "sdist bdist_wheel"
skip_existing: true
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.0.2] - 2019-12-12
### Fixed
- Handle expires_in sent as str instead of int.

## [5.0.1] - 2019-11-28
### Added
- Allow to use & between authentication classes.
Expand Down Expand Up @@ -114,7 +118,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Public release

[Unreleased]: https://github.com/Colin-b/requests_auth/compare/v5.0.1...HEAD
[Unreleased]: https://github.com/Colin-b/requests_auth/compare/v5.0.2...HEAD
[5.0.2]: https://github.com/Colin-b/requests_auth/compare/v5.0.1...v5.0.2
[5.0.1]: https://github.com/Colin-b/requests_auth/compare/v5.0.0...v5.0.1
[5.0.0]: https://github.com/Colin-b/requests_auth/compare/v4.1.0...v5.0.0
[4.1.0]: https://github.com/Colin-b/requests_auth/compare/v4.0.1...v4.1.0
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

<p align="center">
<a href="https://pypi.org/project/requests-auth/"><img alt="pypi version" src="https://img.shields.io/pypi/v/requests_auth"></a>
<img alt="Build status" src="https://img.shields.io/badge/build-passing-brightgreen">
<img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen">
<a href="https://travis-ci.org/Colin-b/requests_auth"><img alt="Build status" src="https://api.travis-ci.org/Colin-b/requests_auth.svg?branch=master"></a>
<a href="https://travis-ci.org/Colin-b/requests_auth"><img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<img alt="Number of tests" src="https://img.shields.io/badge/tests-167 passed-blue">
<a href="https://travis-ci.org/Colin-b/requests_auth"><img alt="Number of tests" src="https://img.shields.io/badge/tests-187 passed-blue"></a>
<a href="https://pypi.org/project/requests-auth/"><img alt="Number of downloads" src="https://img.shields.io/pypi/dm/requests_auth"></a>
</p>

Expand Down
2 changes: 1 addition & 1 deletion requests_auth/oauth2_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def add_access_token(self, key: str, token: str, expires_in: int):
"""
expiry = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc
) + datetime.timedelta(seconds=expires_in)
) + datetime.timedelta(seconds=int(expires_in))
self._add_token(key, token, expiry.timestamp())

def _add_token(self, key: str, token: str, expiry: float):
Expand Down
2 changes: 1 addition & 1 deletion requests_auth/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Major should be incremented in case there is a breaking change. (eg: 2.5.8 -> 3.0.0)
# Minor should be incremented in case there is an enhancement. (eg: 2.5.8 -> 2.6.0)
# Patch should be incremented in case there is a bug fix. (eg: 2.5.8 -> 2.5.9)
__version__ = "5.0.1"
__version__ = "5.0.2"
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"pyjwt==1.*",
# Used to mock responses to requests
"pytest-responses==0.4.*",
# Used to check coverage
"pytest-cov==2.*",
]
},
python_requires=">=3.6",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_oauth2_authorization_code_pkce.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,41 @@ def test_oauth2_pkce_flow_get_code_is_sent_in_authorization_header_by_default(
)


def test_expires_in_sent_as_str(
token_cache, responses: RequestsMock, monkeypatch, browser_mock: BrowserMock
):
monkeypatch.setattr(requests_auth.authentication.os, "urandom", lambda x: b"1" * 63)
auth = requests_auth.OAuth2AuthorizationCodePKCE(
"http://provide_code", "http://provide_access_token"
)
tab = browser_mock.add_response(
opened_url="http://provide_code?response_type=code&state=163f0455b3e9cad3ca04254e5a0169553100d3aa0756c7964d897da316a695ffed5b4f46ef305094fd0a88cfe4b55ff257652015e4aa8f87b97513dba440f8de&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&code_challenge=5C_ph_KZ3DstYUc965SiqmKAA-ShvKF4Ut7daKd3fjc&code_challenge_method=S256",
reply_url="http://localhost:5000#code=SplxlOBeZQQYbYS6WxSbIA&state=163f0455b3e9cad3ca04254e5a0169553100d3aa0756c7964d897da316a695ffed5b4f46ef305094fd0a88cfe4b55ff257652015e4aa8f87b97513dba440f8de",
)
responses.add(
responses.POST,
"http://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": "3600",
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
)
assert (
get_header(responses, auth).get("Authorization")
== "Bearer 2YotnFZFEjr1zCsicMWpAA"
)
assert (
get_request(responses, "http://provide_access_token/").body
== "code_verifier=MTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&response_type=code&code=SplxlOBeZQQYbYS6WxSbIA"
)
tab.assert_success(
"You are now authenticated on 163f0455b3e9cad3ca04254e5a0169553100d3aa0756c7964d897da316a695ffed5b4f46ef305094fd0a88cfe4b55ff257652015e4aa8f87b97513dba440f8de. You may close this tab."
)


def test_nonce_is_sent_if_provided_in_authorization_url(
token_cache, responses: RequestsMock, monkeypatch, browser_mock: BrowserMock
):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_oauth2_client_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ def test_oauth2_client_credentials_flow_token_is_sent_in_authorization_header_by
)


def test_expires_in_sent_as_str(token_cache, responses: RequestsMock):
auth = requests_auth.OAuth2ClientCredentials(
"http://provide_access_token", client_id="test_user", client_secret="test_pwd"
)
responses.add(
responses.POST,
"http://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": "3600",
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
)
assert (
get_header(responses, auth).get("Authorization")
== "Bearer 2YotnFZFEjr1zCsicMWpAA"
)


def test_with_invalid_grant_request_no_json(token_cache, responses: RequestsMock):
auth = requests_auth.OAuth2ClientCredentials(
"http://provide_access_token", client_id="test_user", client_secret="test_pwd"
Expand Down
21 changes: 21 additions & 0 deletions tests/test_oauth2_client_credential_okta.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ def test_okta_client_credentials_flow_token_is_sent_in_authorization_header_by_d
get_header(responses, auth).get("Authorization")
== "Bearer 2YotnFZFEjr1zCsicMWpAA"
)


def test_expires_in_sent_as_str(token_cache, responses: RequestsMock):
auth = requests_auth.OktaClientCredentials(
"test_okta", client_id="test_user", client_secret="test_pwd"
)
responses.add(
responses.POST,
"https://test_okta/oauth2/default/v1/token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": "3600",
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
)
assert (
get_header(responses, auth).get("Authorization")
== "Bearer 2YotnFZFEjr1zCsicMWpAA"
)
25 changes: 25 additions & 0 deletions tests/test_oauth2_resource_owner_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,31 @@ def test_oauth2_password_credentials_flow_token_is_sent_in_authorization_header_
)


def test_expires_in_sent_as_str(token_cache, responses: RequestsMock):
auth = requests_auth.OAuth2ResourceOwnerPasswordCredentials(
"http://provide_access_token", username="test_user", password="test_pwd"
)
responses.add(
responses.POST,
"http://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": "3600",
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
)
assert (
get_header(responses, auth).get("Authorization")
== "Bearer 2YotnFZFEjr1zCsicMWpAA"
)
assert (
get_request(responses, "http://provide_access_token/").body
== "grant_type=password&username=test_user&password=test_pwd"
)


def test_scope_is_sent_as_is_when_provided_as_str(token_cache, responses: RequestsMock):
auth = requests_auth.OAuth2ResourceOwnerPasswordCredentials(
"http://provide_access_token",
Expand Down

0 comments on commit e9e7c48

Please sign in to comment.