-
-
Notifications
You must be signed in to change notification settings - Fork 457
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
authlib 0.15.1 does not send authorizaton header #283
Comments
Another reproduction: from unittest.mock import Mock
import httpx._config
import pytest
from authlib.integrations.starlette_client import OAuth
from authlib.integrations.httpx_client.oauth2_client import AsyncClient, OAuth2Auth
oauth = OAuth()
oauth.register(
name="sso",
client_id="id",
client_secret="secret",
api_base_url="https://api.example.com/",
authorize_url="https://example.com/oauth/authorize",
access_token_url="https://example.com/oauth/access_token",
userinfo_endpoint="https://example.com/openid/userinfo",
)
class InterruptRequest(Exception):
pass
token = {
"token_type": "Bearer",
"expires_in": 30000,
"access_token": "ACCESS_TOKEN",
"refresh_token": "REFRESH_TOKEN",
}
@pytest.mark.asyncio
async def test_userinfo_ignores_token(monkeypatch):
# Prevent resolving example.com
request_mock = Mock(side_effect=InterruptRequest())
AsyncClient.request = request_mock
with pytest.raises(InterruptRequest):
await oauth.sso.userinfo(token=token)
assert request_mock.call_count == 1
assert request_mock.call_args.kwargs["auth"] is not None
@pytest.mark.asyncio
async def test_userinfo_accepts_token(monkeypatch):
# Prevent resolving example.com
request_mock = Mock(side_effect=InterruptRequest())
AsyncClient.request = request_mock
with pytest.raises(InterruptRequest):
await oauth.sso.userinfo(token=token, auth=httpx._config.UNSET)
assert request_mock.call_count == 1
assert request_mock.call_args.kwargs["auth"] is not None I've intercepted the call to I'm not sure of the intended behaviour here, but it makes sense to convert Noticed in: |
Please lock your httpx to 0.14.x. httpx has breaking change again. |
It is caused by 0.16.0:
|
Thanks @lepture , I tested the code in the description with httpx==0.14.1 with the same results (no auth header for authlib 0.15.1). The test by @firesock do not pass either when I install authlib 0.15.1 and httpx 0.14.1. My environment:
results of the test:
both tests pass after downgrading authlib to 0.14.3 |
Thanks for following up @lepture. Is this correct though? httpx fixed their issue with casing in encode/httpx#1351 which was released with 0.16.1, which works with the work around for me. When I followed up more by examining the request going out, the Authorization header wasn't there at all, not even in the wrong case without the work around. @btel's original trace shows the same behaviour. |
Thanks @lepture, that branch fixes it! |
0.15.2 released. |
Describe the bug
authlib 0.15.1 does not seem to send authentication token with the request
Error Stacks
with authlib 0.15.1
with authlib 0.14.3 it's ok (the code was not changed otherwise)
To Reproduce
this is a piece of code that triggered this issue:
Expected behavior
authentication token is sent and the response from api.github.com/user returns with code 200
Environment:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: