Skip to content

Commit 440d528

Browse files
authored
[Authlib] Improve requests integrations (#16369)
1 parent 2fd0f31 commit 440d528

3 files changed

Lines changed: 90 additions & 20 deletions

File tree

stubs/Authlib/authlib/integrations/requests_client/assertion_session.pyi

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
from _typeshed import Incomplete
2+
from http.cookiejar import CookieJar
23

34
from authlib.oauth2.rfc7521 import AssertionClient
5+
from requests import Response, Session
6+
from requests._types import (
7+
AuthType,
8+
CertType,
9+
DataType,
10+
FilesType,
11+
HeadersType,
12+
HooksInputType,
13+
JsonType,
14+
ParamsType,
15+
TimeoutType,
16+
UriType,
17+
VerifyType,
18+
)
19+
from requests.cookies import RequestsCookieJar
420

521
from .oauth2_session import OAuth2Auth
622

723
class AssertionAuth(OAuth2Auth):
824
def ensure_active_token(self): ...
925

10-
# Inherits from requests.Session
11-
class AssertionSession(AssertionClient):
26+
class AssertionSession(AssertionClient, Session):
1227
token_auth_class = AssertionAuth
1328
JWT_BEARER_GRANT_TYPE: Incomplete
1429
ASSERTION_METHODS: Incomplete
@@ -29,4 +44,24 @@ class AssertionSession(AssertionClient):
2944
leeway=60,
3045
**kwargs,
3146
) -> None: ...
32-
def request(self, method, url, withhold_token=False, auth=None, **kwargs): ...
47+
def request( # type: ignore[override]
48+
self,
49+
method: str,
50+
url: UriType,
51+
withhold_token: bool = False,
52+
auth: AuthType | None = None,
53+
*,
54+
params: ParamsType = None,
55+
data: DataType = None,
56+
headers: HeadersType = None,
57+
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
58+
files: FilesType = None,
59+
timeout: TimeoutType = None,
60+
allow_redirects: bool = True,
61+
proxies: dict[str, str] | None = None,
62+
hooks: HooksInputType | None = None,
63+
stream: bool | None = None,
64+
verify: VerifyType | None = None,
65+
cert: CertType = None,
66+
json: JsonType = None,
67+
) -> Response: ...

stubs/Authlib/authlib/integrations/requests_client/oauth1_session.pyi

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ from typing_extensions import Never
22

33
from authlib.oauth1 import ClientAuth
44
from authlib.oauth1.client import OAuth1Client
5+
from requests import PreparedRequest, Response, Session
6+
from requests.auth import AuthBase
57

6-
# Inherits from requests.auth.AuthBase
7-
class OAuth1Auth(ClientAuth):
8-
def __call__(self, req): ...
8+
class OAuth1Auth(AuthBase, ClientAuth):
9+
def __call__(self, req: PreparedRequest) -> PreparedRequest: ...
910

10-
# Inherits from requests.Session
11-
class OAuth1Session(OAuth1Client):
11+
# Incompatible definitions of "auth" in the base classes
12+
class OAuth1Session(OAuth1Client, Session): # type: ignore[misc] # pyrefly: ignore [inconsistent-inheritance]
1213
auth_class = OAuth1Auth
1314
def __init__(
1415
self,
@@ -19,11 +20,11 @@ class OAuth1Session(OAuth1Client):
1920
redirect_uri=None,
2021
rsa_key=None,
2122
verifier=None,
22-
signature_method=...,
23-
signature_type=...,
23+
signature_method="HMAC-SHA1",
24+
signature_type="HEADER",
2425
force_include_body=False,
2526
**kwargs,
2627
) -> None: ...
27-
def rebuild_auth(self, prepared_request, response) -> None: ...
28+
def rebuild_auth(self, prepared_request: PreparedRequest, response: Response) -> None: ...
2829
@staticmethod
2930
def handle_error(error_type: str | None, error_description: str | None) -> Never: ...

stubs/Authlib/authlib/integrations/requests_client/oauth2_session.pyi

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
11
from _typeshed import Incomplete
2+
from http.cookiejar import CookieJar
23

34
from authlib.oauth2.auth import ClientAuth, TokenAuth
45
from authlib.oauth2.client import OAuth2Client
6+
from requests import PreparedRequest, Response, Session
7+
from requests._types import (
8+
AuthType,
9+
CertType,
10+
DataType,
11+
FilesType,
12+
HeadersType,
13+
HooksInputType,
14+
JsonType,
15+
ParamsType,
16+
TimeoutType,
17+
UriType,
18+
VerifyType,
19+
)
20+
from requests.auth import AuthBase
21+
from requests.cookies import RequestsCookieJar
522

623
from ..base_client import OAuthError
724

825
__all__ = ["OAuth2Session", "OAuth2Auth"]
926

10-
# Inherits from requests.auth.AuthBase
11-
class OAuth2Auth(TokenAuth):
27+
class OAuth2Auth(AuthBase, TokenAuth):
1228
def ensure_active_token(self) -> None: ...
13-
def __call__(self, req): ...
29+
def __call__(self, req: PreparedRequest) -> PreparedRequest: ...
1430

15-
# Inherits from requests.auth.AuthBase
16-
class OAuth2ClientAuth(ClientAuth):
17-
def __call__(self, req): ...
31+
class OAuth2ClientAuth(AuthBase, ClientAuth):
32+
def __call__(self, req: PreparedRequest) -> PreparedRequest: ...
1833

19-
# Inherits from requests.Session
20-
class OAuth2Session(OAuth2Client):
34+
class OAuth2Session(OAuth2Client, Session):
2135
client_auth_class = OAuth2ClientAuth
2236
token_auth_class = OAuth2Auth
2337
oauth_error_class = OAuthError # type: ignore[assignment]
@@ -40,4 +54,24 @@ class OAuth2Session(OAuth2Client):
4054
**kwargs,
4155
) -> None: ...
4256
def fetch_access_token(self, url=None, **kwargs): ...
43-
def request(self, method, url, withhold_token=False, auth=None, **kwargs): ...
57+
def request( # type: ignore[override]
58+
self,
59+
method: str,
60+
url: UriType,
61+
withhold_token: bool = False,
62+
auth: AuthType = None,
63+
*,
64+
params: ParamsType = None,
65+
data: DataType = None,
66+
headers: HeadersType = None,
67+
cookies: RequestsCookieJar | CookieJar | dict[str, str] | None = None,
68+
files: FilesType = None,
69+
timeout: TimeoutType = None,
70+
allow_redirects: bool = True,
71+
proxies: dict[str, str] | None = None,
72+
hooks: HooksInputType | None = None,
73+
stream: bool | None = None,
74+
verify: VerifyType | None = None,
75+
cert: CertType = None,
76+
json: JsonType = None,
77+
) -> Response: ...

0 commit comments

Comments
 (0)