Skip to content

Commit

Permalink
Expose everything required (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-b authored Jun 17, 2024
1 parent 6a53852 commit b48154b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Adding explicit support for Python `3.12`.
- Publicly expose `requests_auth.SupportMultiAuth`, allowing multiple authentication support for every `requests` authentication class that exists.
- Publicly expose `requests_auth.TokenMemoryCache`, allowing to create custom Oauth2 token cache based on this default implementation.

### Changed
- Except for `requests_auth.testing`, only direct access via `requests_auth.` was considered publicly exposed. This is now explicit, as inner packages are now using private prefix (`_`).
Expand All @@ -17,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed
- Removing support for Python `3.7`.
- Deprecated `requests_auth.Auths` class has been removed.

## [7.0.0] - 2023-04-27
### Changed
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,17 @@ oauth2 = OAuth2Implicit('https://www.example.com')
requests.get('https://www.example.com', auth=api_key + oauth2)
```

This is supported on every authentication class exposed by `requests_auth`, but you can also enable it on your own authentication classes by using `requests_auth.SupportMultiAuth` as in the following sample:

```python
from requests_auth import SupportMultiAuth
# TODO Import your own auth here
from my_package import MyAuth

class MyMultiAuth(MyAuth, SupportMultiAuth):
pass
```

## Available pytest fixtures

Testing the code using `requests_auth` authentication classes can be achieved using provided [`pytest`][6] fixtures.
Expand Down
7 changes: 4 additions & 3 deletions requests_auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HeaderApiKey,
QueryApiKey,
NTLM,
Auths,
SupportMultiAuth,
)
from requests_auth._oauth2.common import OAuth2
from requests_auth._oauth2.authorization_code import (
Expand All @@ -29,7 +29,7 @@
OAuth2ResourceOwnerPasswordCredentials,
OktaResourceOwnerPasswordCredentials,
)
from requests_auth._oauth2.tokens import JsonTokenFileCache
from requests_auth._oauth2.tokens import JsonTokenFileCache, TokenMemoryCache
from requests_auth._errors import (
GrantNotProvided,
TimeoutOccurred,
Expand Down Expand Up @@ -60,8 +60,9 @@
"OAuth2ResourceOwnerPasswordCredentials",
"OktaResourceOwnerPasswordCredentials",
"NTLM",
"Auths",
"SupportMultiAuth",
"JsonTokenFileCache",
"TokenMemoryCache",
"GrantNotProvided",
"TimeoutOccurred",
"AuthenticationFailed",
Expand Down
10 changes: 0 additions & 10 deletions requests_auth/_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import requests
import requests.auth
import warnings


class SupportMultiAuth:
Expand Down Expand Up @@ -124,15 +123,6 @@ def __and__(self, other):
return _MultiAuth(*self.authentication_modes, other)


class Auths(_MultiAuth):
def __init__(self, *authentication_modes):
warnings.warn(
"Auths class will be removed in the future. Use + instead.",
DeprecationWarning,
)
super().__init__(*authentication_modes)


def _add_parameters(initial_url: str, extra_parameters: dict) -> str:
"""
Add parameters to an URL and return the new URL.
Expand Down
2 changes: 1 addition & 1 deletion requests_auth/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create_token(expiry: Optional[datetime.datetime]) -> str:


@pytest.fixture
def token_cache():
def token_cache() -> requests_auth.TokenMemoryCache:
yield requests_auth.OAuth2.token_cache
requests_auth.OAuth2.token_cache.clear()

Expand Down
16 changes: 0 additions & 16 deletions tests/test_auths.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_json_token_file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@pytest.fixture
def token_cache(request):
def token_cache(request) -> requests_auth.JsonTokenFileCache:
_token_cache = requests_auth.JsonTokenFileCache(request.node.name + ".cache")
yield _token_cache
_token_cache.clear()
Expand Down

0 comments on commit b48154b

Please sign in to comment.