Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ApiClient.auth to access the currently configured Auth Scheme for or an ApiClient #38

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions requests_oauth2client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(
self.timeout = timeout

self.session = session or requests.Session()
self.session.auth = auth
self.auth = auth

for key, val in kwargs.items():
setattr(self.session, key, val)
Expand Down Expand Up @@ -194,7 +194,7 @@ def request( # noqa: C901
headers=headers,
cookies=cookies,
files=files,
auth=auth,
auth=auth or self.auth,
timeout=timeout,
allow_redirects=allow_redirects,
proxies=proxies,
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def test_flask(
from requests_oauth2client.flask import FlaskOAuth2ClientCredentialsAuth
except ImportError:
pytest.skip("Flask is not available")
return

oauth_client = OAuth2Client(token_endpoint, ClientSecretPost(client_id, client_secret))
auth = FlaskOAuth2ClientCredentialsAuth(
Expand All @@ -34,7 +33,7 @@ def test_flask(
)
api_client = ApiClient(target_api, auth=auth)

assert isinstance(api_client.session.auth, FlaskOAuth2ClientCredentialsAuth)
assert isinstance(api_client.auth, FlaskOAuth2ClientCredentialsAuth)

app = Flask("testapp")
app.config["TESTING"] = True
Expand All @@ -57,7 +56,7 @@ def get() -> Any:
assert resp.json == json_resp
resp = client.get("/api?call=2")
assert resp.json == json_resp
api_client.session.auth.forget_token()
api_client.auth.forget_token()
# assert api_client.session.auth.token is None
with client.session_transaction() as sess:
sess.pop(auth.session_key)
Expand Down
14 changes: 5 additions & 9 deletions tests/unit_tests/vendor_specific/test_auth0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

def test_auth0_management() -> None:
auth0api = Auth0ManagementApiClient("test.eu.auth0.com", ("client_id", "client_secret"))
assert auth0api.session.auth is not None
assert isinstance(auth0api.session.auth, OAuth2ClientCredentialsAuth)
assert auth0api.session.auth.client is not None
assert (
auth0api.session.auth.client.token_endpoint == "https://test.eu.auth0.com/oauth/token"
)
assert auth0api.session.auth.token_kwargs == {
"audience": "https://test.eu.auth0.com/api/v2/"
}
assert auth0api.auth is not None
assert isinstance(auth0api.auth, OAuth2ClientCredentialsAuth)
assert auth0api.auth.client is not None
assert auth0api.auth.client.token_endpoint == "https://test.eu.auth0.com/oauth/token"
assert auth0api.auth.token_kwargs == {"audience": "https://test.eu.auth0.com/api/v2/"}


def test_auth0_client() -> None:
Expand Down
Loading