Skip to content

Commit a69621f

Browse files
authored
Improve oauthlib.oauth2.rfc6749 (#13793)
1 parent 1552ada commit a69621f

21 files changed

+334
-163
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
from _typeshed import Incomplete
2-
3-
from .base import Client as Client
1+
from .base import Client
42

53
class BackendApplicationClient(Client):
64
grant_type: str
75
def prepare_request_body(
8-
self, body: str = "", scope: Incomplete | None = None, include_client_id: bool = False, **kwargs
9-
): ...
6+
self,
7+
body: str = "",
8+
scope: str | set[object] | tuple[object] | list[object] | None = None,
9+
include_client_id: bool = False,
10+
*,
11+
code_verifier: str | None = None,
12+
client_id: str | None = None,
13+
client_secret: str | None = None,
14+
**kwargs,
15+
) -> str: ...

stubs/oauthlib/oauthlib/oauth2/rfc6749/clients/base.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Client:
2727
state_generator: Callable[[], str]
2828
state: str | None
2929
redirect_url: str | None
30-
code: Incomplete
30+
code: str | None
3131
expires_in: ConvertibleToInt | None
3232
code_verifier: str | None
3333
code_challenge: str | None
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,42 @@
11
from _typeshed import Incomplete
2+
from collections.abc import Callable
23

3-
from .base import Client as Client
4+
from .base import Client, _TokenPlacement
45

56
class LegacyApplicationClient(Client):
67
grant_type: str
7-
def __init__(self, client_id, **kwargs) -> None: ...
8+
def __init__(
9+
self,
10+
client_id: str,
11+
*,
12+
default_token_placement: _TokenPlacement = "auth_header",
13+
token_type: str = "Bearer",
14+
access_token: str | None = None,
15+
refresh_token: str | None = None,
16+
mac_key: str | bytes | bytearray | None = None,
17+
mac_algorithm: str | None = None,
18+
token: dict[str, Incomplete] | None = None,
19+
scope: str | set[object] | tuple[object] | list[object] | None = None,
20+
state: str | None = None,
21+
redirect_url: str | None = None,
22+
state_generator: Callable[[], str] = ...,
23+
code_verifier: str | None = None,
24+
code_challenge: str | None = None,
25+
code_challenge_method: str | None = None,
26+
**kwargs,
27+
) -> None: ...
828
def prepare_request_body(
9-
self, username, password, body: str = "", scope: Incomplete | None = None, include_client_id: bool = False, **kwargs
10-
): ...
29+
self,
30+
username: str,
31+
password: str,
32+
body: str = "",
33+
scope: str | set[object] | tuple[object] | list[object] | None = None,
34+
include_client_id: bool = False,
35+
*,
36+
code_verifier: str | None = None,
37+
client_id: str | None = None,
38+
client_secret: str | None = None,
39+
code: str | None = None,
40+
redirect_uri: str | None = None,
41+
**kwargs,
42+
) -> str: ...
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
from _typeshed import Incomplete
2-
from typing import Any
1+
from oauthlib.oauth2.rfc6749.tokens import OAuth2Token
32

4-
from .base import Client as Client
3+
from .base import Client
54

65
class MobileApplicationClient(Client):
76
response_type: str
87
def prepare_request_uri(
98
self,
109
uri,
11-
redirect_uri: Incomplete | None = None,
12-
scope: Incomplete | None = None,
13-
state: Incomplete | None = None,
10+
redirect_uri: str | None = None,
11+
scope: str | set[object] | tuple[object] | list[object] | None = None,
12+
state: str | None = None,
1413
**kwargs,
15-
): ...
16-
token: Any
17-
def parse_request_uri_response(self, uri, state: Incomplete | None = None, scope: Incomplete | None = None): ...
14+
) -> str: ...
15+
token: OAuth2Token
16+
def parse_request_uri_response(
17+
self, uri: str, state: str | None = None, scope: str | set[object] | tuple[object] | list[object] | None = None
18+
) -> OAuth2Token: ...
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,56 @@
11
from _typeshed import Incomplete
2-
from typing import Any
2+
from collections.abc import Callable
33

4-
from .base import Client as Client
4+
from .base import Client, _TokenPlacement
55

66
class ServiceApplicationClient(Client):
77
grant_type: str
8-
private_key: Any
9-
subject: Any
10-
issuer: Any
11-
audience: Any
8+
private_key: str | None
9+
subject: str | None
10+
issuer: str | None
11+
audience: str | None
1212
def __init__(
1313
self,
14-
client_id,
15-
private_key: Incomplete | None = None,
16-
subject: Incomplete | None = None,
17-
issuer: Incomplete | None = None,
18-
audience: Incomplete | None = None,
14+
client_id: str,
15+
private_key: str | None = None,
16+
subject: str | None = None,
17+
issuer: str | None = None,
18+
audience: str | None = None,
19+
*,
20+
default_token_placement: _TokenPlacement = "auth_header",
21+
token_type: str = "Bearer",
22+
access_token: str | None = None,
23+
refresh_token: str | None = None,
24+
mac_key: str | bytes | bytearray | None = None,
25+
mac_algorithm: str | None = None,
26+
token: dict[str, Incomplete] | None = None,
27+
scope: str | set[object] | tuple[object] | list[object] | None = None,
28+
state: str | None = None,
29+
redirect_url: str | None = None,
30+
state_generator: Callable[[], str] = ...,
31+
code_verifier: str | None = None,
32+
code_challenge: str | None = None,
33+
code_challenge_method: str | None = None,
1934
**kwargs,
2035
) -> None: ...
2136
def prepare_request_body(
2237
self,
23-
private_key: Incomplete | None = None,
24-
subject: Incomplete | None = None,
25-
issuer: Incomplete | None = None,
26-
audience: Incomplete | None = None,
27-
expires_at: Incomplete | None = None,
28-
issued_at: Incomplete | None = None,
29-
extra_claims: Incomplete | None = None,
38+
private_key: str | None = None,
39+
subject: str | None = None,
40+
issuer: str | None = None,
41+
audience: str | None = None,
42+
expires_at: float | None = None,
43+
issued_at: float | None = None,
44+
extra_claims: dict[str, Incomplete] | None = None,
3045
body: str = "",
31-
scope: Incomplete | None = None,
46+
scope: str | set[object] | tuple[object] | list[object] | None = None,
3247
include_client_id: bool = False,
48+
*,
49+
not_before: int | None = None,
50+
jwt_id: str | None = None,
51+
client_id: str | None = None,
52+
client_secret: str | None = None,
53+
code: str | None = None,
54+
redirect_uri: str | None = None,
3355
**kwargs,
34-
): ...
56+
) -> str: ...
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
11
from _typeshed import Incomplete
2-
from typing import Any
2+
from collections.abc import Callable
33

4-
from .base import Client as Client
4+
from .base import Client, _TokenPlacement
55

66
class WebApplicationClient(Client):
77
grant_type: str
8-
code: Any
9-
def __init__(self, client_id, code: Incomplete | None = None, **kwargs) -> None: ...
8+
code: str | None
9+
def __init__(
10+
self,
11+
client_id: str,
12+
code: str | None = None,
13+
*,
14+
default_token_placement: _TokenPlacement = "auth_header",
15+
token_type: str = "Bearer",
16+
access_token: str | None = None,
17+
refresh_token: str | None = None,
18+
mac_key: str | bytes | bytearray | None = None,
19+
mac_algorithm: str | None = None,
20+
token: dict[str, Incomplete] | None = None,
21+
scope: str | set[object] | tuple[object] | list[object] | None = None,
22+
state: str | None = None,
23+
redirect_url: str | None = None,
24+
state_generator: Callable[[], str] = ...,
25+
code_verifier: str | None = None,
26+
code_challenge: str | None = None,
27+
code_challenge_method: str | None = None,
28+
**kwargs,
29+
) -> None: ...
1030
def prepare_request_uri(
1131
self,
12-
uri,
13-
redirect_uri: Incomplete | None = None,
14-
scope: Incomplete | None = None,
15-
state: Incomplete | None = None,
32+
uri: str,
33+
redirect_uri: str | None = None,
34+
scope: str | set[object] | tuple[object] | list[object] | None = None,
35+
state: str | None = None,
1636
code_challenge: str | None = None,
1737
code_challenge_method: str | None = "plain",
1838
**kwargs,
19-
): ...
39+
) -> str: ...
2040
def prepare_request_body(
2141
self,
22-
code: Incomplete | None = None,
23-
redirect_uri: Incomplete | None = None,
42+
code: str | None = None,
43+
redirect_uri: str | None = None,
2444
body: str = "",
2545
include_client_id: bool = True,
2646
code_verifier: str | None = None,
47+
*,
48+
scope: str | set[object] | tuple[object] | list[object] | None = None,
49+
client_id: str | None = None,
50+
client_secret: str | None = None,
2751
**kwargs,
28-
): ...
29-
def parse_request_uri_response(self, uri, state: Incomplete | None = None): ...
52+
) -> str: ...
53+
def parse_request_uri_response(self, uri: str, state: str | None = None) -> dict[str, str]: ...
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from _typeshed import Incomplete
2-
from typing import Any
2+
from logging import Logger
33

4-
from .base import BaseEndpoint as BaseEndpoint
4+
from oauthlib.common import _HTTPMethod
55

6-
log: Any
6+
from .base import BaseEndpoint
7+
8+
log: Logger
79

810
class AuthorizationEndpoint(BaseEndpoint):
9-
def __init__(self, default_response_type, default_token_type, response_types) -> None: ...
11+
def __init__(self, default_response_type, default_token_type, response_types: dict[str, Incomplete]) -> None: ...
1012
@property
1113
def response_types(self): ...
1214
@property
@@ -17,13 +19,13 @@ class AuthorizationEndpoint(BaseEndpoint):
1719
def default_token_type(self): ...
1820
def create_authorization_response(
1921
self,
20-
uri,
21-
http_method: str = "GET",
22-
body: Incomplete | None = None,
23-
headers: Incomplete | None = None,
22+
uri: str,
23+
http_method: _HTTPMethod = "GET",
24+
body: str | None = None,
25+
headers: dict[str, str] | None = None,
2426
scopes: Incomplete | None = None,
25-
credentials: Incomplete | None = None,
27+
credentials: dict[str, Incomplete] | None = None,
2628
): ...
2729
def validate_authorization_request(
28-
self, uri, http_method: str = "GET", body: Incomplete | None = None, headers: Incomplete | None = None
30+
self, uri: str, http_method: _HTTPMethod = "GET", body: str | None = None, headers: dict[str, str] | None = None
2931
): ...
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
from typing import Any
1+
from _typeshed import Incomplete
2+
from collections.abc import Callable, Sequence
3+
from logging import Logger
24

3-
log: Any
5+
log: Logger
46

57
class BaseEndpoint:
68
def __init__(self) -> None: ...
79
@property
8-
def valid_request_methods(self): ...
10+
def valid_request_methods(self) -> Sequence[str] | None: ...
911
@valid_request_methods.setter
10-
def valid_request_methods(self, valid_request_methods) -> None: ...
12+
def valid_request_methods(self, valid_request_methods: Sequence[str] | None) -> None: ...
1113
@property
12-
def available(self): ...
14+
def available(self) -> bool: ...
1315
@available.setter
14-
def available(self, available) -> None: ...
16+
def available(self, available: bool) -> None: ...
1517
@property
16-
def catch_errors(self): ...
18+
def catch_errors(self) -> bool: ...
1719
@catch_errors.setter
18-
def catch_errors(self, catch_errors) -> None: ...
20+
def catch_errors(self, catch_errors: bool) -> None: ...
1921

20-
def catch_errors_and_unavailability(f): ...
22+
def catch_errors_and_unavailability(
23+
f: Callable[..., tuple[dict[str, Incomplete], str, int]],
24+
) -> Callable[..., tuple[dict[str, Incomplete], str, int]]: ...
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from _typeshed import Incomplete
2+
from logging import Logger
23
from typing import Any
34

4-
from .base import BaseEndpoint as BaseEndpoint
5+
from oauthlib.common import Request, _HTTPMethod
56

6-
log: Any
7+
from .base import BaseEndpoint
8+
9+
log: Logger
710

811
class IntrospectEndpoint(BaseEndpoint):
912
valid_token_types: Any
@@ -12,6 +15,6 @@ class IntrospectEndpoint(BaseEndpoint):
1215
supported_token_types: Any
1316
def __init__(self, request_validator, supported_token_types: Incomplete | None = None) -> None: ...
1417
def create_introspect_response(
15-
self, uri, http_method: str = "POST", body: Incomplete | None = None, headers: Incomplete | None = None
18+
self, uri: str, http_method: _HTTPMethod = "POST", body: str | None = None, headers: dict[str, str] | None = None
1619
): ...
17-
def validate_introspect_request(self, request) -> None: ...
20+
def validate_introspect_request(self, request: Request) -> None: ...

stubs/oauthlib/oauthlib/oauth2/rfc6749/endpoints/metadata.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from _typeshed import Incomplete
1+
from logging import Logger
22
from typing import Any
33

4-
from .base import BaseEndpoint as BaseEndpoint
4+
from .base import BaseEndpoint
55

6-
log: Any
6+
log: Logger
77

88
class MetadataEndpoint(BaseEndpoint):
99
raise_errors: Any
@@ -12,7 +12,7 @@ class MetadataEndpoint(BaseEndpoint):
1212
claims: Any
1313
def __init__(self, endpoints, claims={}, raise_errors: bool = True) -> None: ...
1414
def create_metadata_response(
15-
self, uri, http_method: str = "GET", body: Incomplete | None = None, headers: Incomplete | None = None
15+
self, uri: str, http_method: str = "GET", body: str | None = None, headers: dict[str, str] | None = None
1616
): ...
1717
def validate_metadata(
1818
self, array, key, is_required: bool = False, is_list: bool = False, is_url: bool = False, is_issuer: bool = False

stubs/oauthlib/oauthlib/oauth2/rfc6749/endpoints/pre_configured.pyi

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from _typeshed import Incomplete
22
from typing import Any
33

4-
from .authorization import AuthorizationEndpoint as AuthorizationEndpoint
5-
from .introspect import IntrospectEndpoint as IntrospectEndpoint
6-
from .resource import ResourceEndpoint as ResourceEndpoint
7-
from .revocation import RevocationEndpoint as RevocationEndpoint
8-
from .token import TokenEndpoint as TokenEndpoint
4+
from .authorization import AuthorizationEndpoint
5+
from .introspect import IntrospectEndpoint
6+
from .resource import ResourceEndpoint
7+
from .revocation import RevocationEndpoint
8+
from .token import TokenEndpoint
99

1010
class Server(AuthorizationEndpoint, IntrospectEndpoint, TokenEndpoint, ResourceEndpoint, RevocationEndpoint):
1111
auth_grant: Any

0 commit comments

Comments
 (0)