Skip to content

Commit

Permalink
Merge pull request #58 from Colin-b/develop
Browse files Browse the repository at this point in the history
Release 5.1.0
  • Loading branch information
Colin-b authored Mar 4, 2020
2 parents e9e7c48 + c4dcd42 commit 42cc20e
Show file tree
Hide file tree
Showing 22 changed files with 1,591 additions and 166 deletions.
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.1.0] - 2020-03-04
### Added
- [`pytest`](https://docs.pytest.org/en/latest/) fixtures in `requests_auth.testing`. Refer to documentation for more details.

## [5.0.2] - 2019-12-12
### Fixed
- Handle expires_in sent as str instead of int.
Expand Down Expand Up @@ -118,7 +122,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.2...HEAD
[Unreleased]: https://github.com/Colin-b/requests_auth/compare/v5.1.0...HEAD
[5.1.0]: https://github.com/Colin-b/requests_auth/compare/v5.0.2...v5.1.0
[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
Expand Down
187 changes: 153 additions & 34 deletions README.md

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions requests_auth/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def _add_parameters(initial_url: str, extra_parameters: dict) -> str:
"""
scheme, netloc, path, query_string, fragment = urlsplit(initial_url)
query_params = parse_qs(query_string)

for parameter_name in extra_parameters.keys():
# TODO Handle parameters with a list as a value and submit PR to requests or Python
query_params[parameter_name] = [extra_parameters[parameter_name]]
query_params.update(
{
parameter_name: [parameter_value]
for parameter_name, parameter_value in extra_parameters.items()
}
)

new_query_string = urlencode(query_params, doseq=True)

Expand Down Expand Up @@ -791,22 +793,22 @@ def __init__(self, tenant_id: str, client_id: str, **kwargs):

class OktaImplicit(OAuth2Implicit):
"""
Describes an OKTA (OAuth 2) "Access Token" implicit flow requests authentication.
Describes an Okta (OAuth 2) "Access Token" implicit flow requests authentication.
https://developer.okta.com/docs/guides/implement-implicit/overview/
"""

def __init__(self, instance: str, client_id: str, **kwargs):
"""
:param instance: OKTA instance (like "testserver.okta-emea.com")
:param client_id: OKTA Application Identifier (formatted as an Universal Unique Identifier)
:param instance: Okta instance (like "testserver.okta-emea.com")
:param client_id: Okta Application Identifier (formatted as an Universal Unique Identifier)
:param response_type: Value of the response_type query parameter.
token by default.
:param token_field_name: Name of the expected field containing the token.
access_token by default.
:param nonce: Refer to http://openid.net/specs/openid-connect-core-1_0.html#IDToken for more details
(formatted as an Universal Unique Identifier - UUID). Use a newly generated UUID by default.
:param authorization_server: OKTA authorization server.
:param authorization_server: Okta authorization server.
default by default.
:param scope: Scope parameter sent in query. Can also be a list of scopes.
Request ['openid', 'profile', 'email'] by default.
Expand Down Expand Up @@ -846,20 +848,20 @@ def __init__(self, instance: str, client_id: str, **kwargs):

class OktaImplicitIdToken(OAuth2Implicit):
"""
Describes an OKTA (OpenID Connect) "ID Token" implicit flow requests authentication.
Describes an Okta (OpenID Connect) "ID Token" implicit flow requests authentication.
"""

def __init__(self, instance: str, client_id: str, **kwargs):
"""
:param instance: OKTA instance (like "testserver.okta-emea.com")
:param client_id: OKTA Application Identifier (formatted as an Universal Unique Identifier)
:param instance: Okta instance (like "testserver.okta-emea.com")
:param client_id: Okta Application Identifier (formatted as an Universal Unique Identifier)
:param response_type: Value of the response_type query parameter.
id_token by default.
:param token_field_name: Name of the expected field containing the token.
id_token by default.
:param nonce: Refer to http://openid.net/specs/openid-connect-core-1_0.html#IDToken for more details
(formatted as an Universal Unique Identifier - UUID). Use a newly generated UUID by default.
:param authorization_server: OKTA authorization server
:param authorization_server: Okta authorization server
default by default.
:param scope: Scope parameter sent in query. Can also be a list of scopes.
Request ['openid', 'profile', 'email'] by default.
Expand Down Expand Up @@ -901,20 +903,20 @@ def __init__(self, instance: str, client_id: str, **kwargs):

class OktaAuthorizationCode(OAuth2AuthorizationCode):
"""
Describes an OKTA (OAuth 2) "Access Token" authorization code flow requests authentication.
Describes an Okta (OAuth 2) "Access Token" authorization code flow requests authentication.
"""

def __init__(self, instance: str, client_id: str, **kwargs):
"""
:param instance: OKTA instance (like "testserver.okta-emea.com")
:param client_id: OKTA Application Identifier (formatted as an Universal Unique Identifier)
:param instance: Okta instance (like "testserver.okta-emea.com")
:param client_id: Okta Application Identifier (formatted as an Universal Unique Identifier)
:param response_type: Value of the response_type query parameter.
token by default.
:param token_field_name: Name of the expected field containing the token.
access_token by default.
:param nonce: Refer to http://openid.net/specs/openid-connect-core-1_0.html#IDToken for more details
(formatted as an Universal Unique Identifier - UUID). Use a newly generated UUID by default.
:param authorization_server: OKTA authorization server
:param authorization_server: Okta authorization server
default by default.
:param scope: Scope parameter sent in query. Can also be a list of scopes.
Request 'openid' by default.
Expand Down Expand Up @@ -954,21 +956,21 @@ def __init__(self, instance: str, client_id: str, **kwargs):

class OktaAuthorizationCodePKCE(OAuth2AuthorizationCodePKCE):
"""
Describes an OKTA (OAuth 2) "Access Token" Proof Key for Code Exchange (PKCE) flow requests authentication.
Describes an Okta (OAuth 2) "Access Token" Proof Key for Code Exchange (PKCE) flow requests authentication.
"""

def __init__(self, instance: str, client_id: str, **kwargs):
"""
:param instance: OKTA instance (like "testserver.okta-emea.com")
:param client_id: OKTA Application Identifier (formatted as an Universal Unique Identifier)
:param instance: Okta instance (like "testserver.okta-emea.com")
:param client_id: Okta Application Identifier (formatted as an Universal Unique Identifier)
:param response_type: Value of the response_type query parameter.
code by default.
:param token_field_name: Name of the expected field containing the token.
access_token by default.
:param code_field_name: Field name containing the code. code by default.
:param nonce: Refer to http://openid.net/specs/openid-connect-core-1_0.html#IDToken for more details
(formatted as an Universal Unique Identifier - UUID). Use a newly generated UUID by default.
:param authorization_server: OKTA authorization server
:param authorization_server: Okta authorization server
default by default.
:param scope: Scope parameter sent in query. Can also be a list of scopes.
Request 'openid' by default.
Expand Down Expand Up @@ -1009,15 +1011,15 @@ def __init__(self, instance: str, client_id: str, **kwargs):

class OktaClientCredentials(OAuth2ClientCredentials):
"""
Describes an OKTA (OAuth 2) client credentials (also called application) flow requests authentication.
Describes an Okta (OAuth 2) client credentials (also called application) flow requests authentication.
"""

def __init__(self, instance: str, client_id: str, client_secret: str, **kwargs):
"""
:param instance: OKTA instance (like "testserver.okta-emea.com")
:param client_id: OKTA Application Identifier (formatted as an Universal Unique Identifier)
:param instance: Okta instance (like "testserver.okta-emea.com")
:param client_id: Okta Application Identifier (formatted as an Universal Unique Identifier)
:param client_secret: Resource owner password.
:param authorization_server: OKTA authorization server
:param authorization_server: Okta authorization server
default by default.
:param timeout: Maximum amount of seconds to wait for a token to be received once requested.
Wait for 1 minute by default.
Expand Down
20 changes: 16 additions & 4 deletions tests/oauth2_helper.py → requests_auth/testing.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import logging
import urllib.request
import threading
from urllib.parse import urlsplit
from typing import Dict, Optional
import datetime

import pytest
import jwt

import requests_auth

logger = logging.getLogger(__name__)

def create_token(expiry: Optional[datetime.datetime]) -> str:
import jwt # Consider jwt an optional dependency for testing

def create_token(expiry: Optional[datetime.datetime]):
token = (
jwt.encode({"exp": expiry}, "secret") if expiry else jwt.encode({}, "secret")
)
Expand Down Expand Up @@ -122,3 +120,17 @@ def browser_mock(monkeypatch) -> BrowserMock:
)
yield mock
mock.assert_checked()


@pytest.fixture
def token_mock() -> str:
return "2YotnFZFEjr1zCsicMWpAA"


@pytest.fixture
def token_cache_mock(monkeypatch, token_mock: str):
class TokenCacheMock:
def get_token(self, *args, **kwargs) -> str:
return token_mock

monkeypatch.setattr(requests_auth.OAuth2, "token_cache", TokenCacheMock())
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.2"
__version__ = "5.1.0"
2 changes: 1 addition & 1 deletion tests/test_add_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests

import requests_auth
from tests.oauth2_helper import token_cache, browser_mock, BrowserMock, create_token
from requests_auth.testing import BrowserMock, create_token, token_cache, browser_mock
from tests.auth_helper import get_header


Expand Down
2 changes: 1 addition & 1 deletion tests/test_and_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests

import requests_auth
from tests.oauth2_helper import token_cache, browser_mock, BrowserMock, create_token
from requests_auth.testing import BrowserMock, create_token, token_cache, browser_mock
from tests.auth_helper import get_header


Expand Down
2 changes: 1 addition & 1 deletion tests/test_oauth2_authorization_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests

import requests_auth
from tests.oauth2_helper import token_cache, browser_mock, BrowserMock
from requests_auth.testing import BrowserMock, browser_mock, token_cache
from tests.auth_helper import get_header, get_request


Expand Down
Loading

0 comments on commit 42cc20e

Please sign in to comment.