diff --git a/stubs/Authlib/METADATA.toml b/stubs/Authlib/METADATA.toml index 5a87ffbbc384..bdcd3d3372a3 100644 --- a/stubs/Authlib/METADATA.toml +++ b/stubs/Authlib/METADATA.toml @@ -1,8 +1,8 @@ -version = "1.8.0" +version = "1.9.6" upstream-repository = "https://github.com/authlib/authlib" dependencies = ["cryptography"] # Requires a version of flask with a `py.typed` file -optional-dependencies = ["django-stubs", "Flask>=2.0.0", "httpx2", "requests", "starlette", "types-oauthlib"] +optional-dependencies = ["django-stubs", "Flask>=2.0.0", "httpx2", "joserfc", "requests", "starlette", "types-oauthlib"] [tool.stubtest] mypy-plugins = ["mypy_django_plugin.main"] diff --git a/stubs/Authlib/authlib/integrations/django_oauth1/authorization_server.pyi b/stubs/Authlib/authlib/integrations/django_oauth1/authorization_server.pyi index 7b8bac2aecd2..e21150d67e9a 100644 --- a/stubs/Authlib/authlib/integrations/django_oauth1/authorization_server.pyi +++ b/stubs/Authlib/authlib/integrations/django_oauth1/authorization_server.pyi @@ -1,5 +1,6 @@ import logging from _typeshed import Incomplete +from collections.abc import Iterable from authlib.oauth1 import AuthorizationServer as _AuthorizationServer, OAuth1Request, TemporaryCredential from django.http import HttpResponse @@ -17,7 +18,9 @@ class BaseServer(_AuthorizationServer): def create_token_credential(self, request): ... def check_authorization_request(self, request) -> OAuth1Request: ... def create_oauth1_request(self, request) -> OAuth1Request: ... - def handle_response(self, status_code, payload, headers) -> HttpResponse: ... + def handle_response( + self, status_code: int, payload: Iterable[tuple[str, str]], headers: list[tuple[str, str]] + ) -> HttpResponse: ... class CacheAuthorizationServer(BaseServer): def __init__(self, client_model, token_model, token_generator=None) -> None: ... diff --git a/stubs/Authlib/authlib/integrations/django_oauth2/authorization_server.pyi b/stubs/Authlib/authlib/integrations/django_oauth2/authorization_server.pyi index c85f197288ba..4cdc78170ae5 100644 --- a/stubs/Authlib/authlib/integrations/django_oauth2/authorization_server.pyi +++ b/stubs/Authlib/authlib/integrations/django_oauth2/authorization_server.pyi @@ -1,6 +1,6 @@ from _typeshed import Incomplete, SupportsKeysAndGetItem, Unused from collections.abc import Callable -from typing import Literal, ParamSpec, TypeVar, overload +from typing import Any, Literal, ParamSpec, TypeVar, overload from authlib.oauth2 import AuthorizationServer as _AuthorizationServer from authlib.oauth2.rfc6750 import BearerTokenGenerator @@ -19,7 +19,9 @@ class AuthorizationServer(_AuthorizationServer): def save_token(self, token, request): ... def create_oauth2_request(self, request) -> DjangoOAuth2Request: ... def create_json_request(self, request) -> DjangoJsonRequest: ... - def handle_response(self, status_code, payload, headers) -> HttpResponse: ... + def handle_response( + self, status_code: int, payload: str | dict[str, Any], headers: list[tuple[str, str]] + ) -> HttpResponse: ... def send_signal(self, name, *args, **kwargs) -> None: ... def create_bearer_token_generator(self) -> BearerTokenGenerator: ... diff --git a/stubs/Authlib/authlib/integrations/flask_oauth1/authorization_server.pyi b/stubs/Authlib/authlib/integrations/flask_oauth1/authorization_server.pyi index be1e84f6d4fe..533a85e39d87 100644 --- a/stubs/Authlib/authlib/integrations/flask_oauth1/authorization_server.pyi +++ b/stubs/Authlib/authlib/integrations/flask_oauth1/authorization_server.pyi @@ -1,6 +1,6 @@ import logging from _typeshed import Incomplete -from collections.abc import Callable +from collections.abc import Callable, Iterable from authlib.oauth1 import AuthorizationServer as _AuthorizationServer, OAuth1Request from flask import Flask, Response @@ -27,4 +27,6 @@ class AuthorizationServer(_AuthorizationServer): def create_authorization_response(self, request=None, grant_user=None): ... def create_token_response(self, request=None): ... def create_oauth1_request(self, request) -> OAuth1Request: ... - def handle_response(self, status_code, payload, headers) -> Response: ... + def handle_response( + self, status_code: int, payload: Iterable[tuple[str, str]], headers: list[tuple[str, str]] + ) -> Response: ... diff --git a/stubs/Authlib/authlib/integrations/flask_oauth2/authorization_server.pyi b/stubs/Authlib/authlib/integrations/flask_oauth2/authorization_server.pyi index fa3ff6e4e6ce..2ce7307b2e63 100644 --- a/stubs/Authlib/authlib/integrations/flask_oauth2/authorization_server.pyi +++ b/stubs/Authlib/authlib/integrations/flask_oauth2/authorization_server.pyi @@ -1,6 +1,7 @@ from _typeshed import Incomplete +from typing import Any -from authlib.oauth2 import AuthorizationServer as _AuthorizationServer +from authlib.oauth2.rfc6749 import AuthorizationServer as _AuthorizationServer from authlib.oauth2.rfc6750 import BearerTokenGenerator from flask import Flask, Response @@ -16,7 +17,7 @@ class AuthorizationServer(_AuthorizationServer): def get_error_uri(self, request, error): ... def create_oauth2_request(self, request) -> FlaskOAuth2Request: ... def create_json_request(self, request) -> FlaskJsonRequest: ... - def handle_response(self, status_code, payload, headers) -> Response: ... + def handle_response(self, status_code: int, payload: str | dict[str, Any], headers: list[tuple[str, str]]) -> Response: ... def send_signal(self, name, *args, **kwargs) -> None: ... def create_bearer_token_generator(self, config) -> BearerTokenGenerator: ... diff --git a/stubs/Authlib/authlib/oauth1/rfc5849/authorization_server.pyi b/stubs/Authlib/authlib/oauth1/rfc5849/authorization_server.pyi index e77bd50c9227..96b08c4fec7a 100644 --- a/stubs/Authlib/authlib/oauth1/rfc5849/authorization_server.pyi +++ b/stubs/Authlib/authlib/oauth1/rfc5849/authorization_server.pyi @@ -4,7 +4,7 @@ class AuthorizationServer(BaseServer): TOKEN_RESPONSE_HEADER: list[tuple[str, str]] TEMPORARY_CREDENTIALS_METHOD: str def create_oauth1_request(self, request): ... - def handle_response(self, status_code, payload, headers): ... + def handle_response(self, status_code: int, payload: list[tuple[str, str]], headers: list[tuple[str, str]]): ... def handle_error_response(self, error): ... def validate_temporary_credentials_request(self, request): ... def create_temporary_credentials_response(self, request=None): ... diff --git a/stubs/Authlib/authlib/oauth2/drafts/__init__.pyi b/stubs/Authlib/authlib/oauth2/drafts/__init__.pyi new file mode 100644 index 000000000000..6974f1b49624 --- /dev/null +++ b/stubs/Authlib/authlib/oauth2/drafts/__init__.pyi @@ -0,0 +1,3 @@ +from .id_jag import IDJAGGrant as IDJAGGrant + +__all__ = ["IDJAGGrant"] diff --git a/stubs/Authlib/authlib/oauth2/drafts/id_jag.pyi b/stubs/Authlib/authlib/oauth2/drafts/id_jag.pyi new file mode 100644 index 000000000000..cf14db6d6722 --- /dev/null +++ b/stubs/Authlib/authlib/oauth2/drafts/id_jag.pyi @@ -0,0 +1,29 @@ +from _typeshed import Incomplete +from logging import Logger +from typing import Any, ClassVar, Final, Literal + +from authlib.oauth2.rfc6749.grants.base import BaseGrant, TokenEndpointMixin +from authlib.oauth2.rfc6750.token import _Token +from joserfc import jwk + +log: Logger + +class IDJAGGrant(BaseGrant, TokenEndpointMixin): + GRANT_TYPE: ClassVar[str] + REQUIRED_TYP: Final[str] + CLAIMS_OPTIONS: Final[dict[str, dict[str, Any]]] + LEEWAY: int + + request: Incomplete + + @staticmethod + def sign( + key, issuer, audience, subject, client_id, jti=None, issued_at=None, expires_at=None, claims=None, *, header={}, **kwargs + ): ... + def validate_token_request(self) -> None: ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... + def get_audiences(self) -> list[Incomplete]: ... + def resolve_issuer_key(self, issuer, headers) -> jwk.Key | jwk.KeySet: ... + def authenticate_user(self, subject): ... + def check_jti(self, claims, jti) -> bool: ... + def check_id_jag_permission(self, client, user, scopes) -> bool: ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/authorization_server.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/authorization_server.pyi index 932bec1278f1..2844a70ca95a 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/authorization_server.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/authorization_server.pyi @@ -1,10 +1,10 @@ -from collections.abc import Callable, Collection, Mapping -from typing import TypeAlias, overload +from collections.abc import Callable, Collection +from typing import Any, TypeAlias, overload from typing_extensions import deprecated from authlib.oauth2 import JsonRequest, OAuth2Error, OAuth2Request from authlib.oauth2.rfc6749 import BaseGrant, ClientMixin -from authlib.oauth2.rfc6750 import BearerTokenGenerator +from authlib.oauth2.rfc6750.token import BearerTokenGenerator, _Token from .endpoint import Endpoint, EndpointRequest from .hooks import Hookable @@ -24,7 +24,7 @@ class AuthorizationServer(Hookable): scope: str | None = None, expires_in: int | None = None, include_refresh_token: bool = True, - ) -> dict[str, str | int]: ... + ) -> _Token: ... def register_token_generator(self, grant_type: str, func: BearerTokenGenerator) -> None: ... def authenticate_client(self, request: OAuth2Request, methods: Collection[str], endpoint: str = "token") -> ClientMixin: ... def register_client_auth_method(self, method, func) -> None: ... @@ -33,7 +33,7 @@ class AuthorizationServer(Hookable): def send_signal(self, name, *args: object, **kwargs: object) -> None: ... def create_oauth2_request(self, request) -> OAuth2Request: ... def create_json_request(self, request) -> JsonRequest: ... - def handle_response(self, status: int, body: Mapping[str, object], headers: Mapping[str, str]) -> object: ... + def handle_response(self, status: int, body: str | dict[str, Any], headers: list[tuple[str, str]]) -> object: ... def validate_requested_scope(self, scope: str) -> None: ... def register_grant( self, grant_cls: type[BaseGrant], extensions: Collection[Callable[[BaseGrant], None]] | None = None diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/endpoint.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/endpoint.pyi index 6fb13da985f7..bf6392a47a0a 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/endpoint.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/endpoint.pyi @@ -14,6 +14,6 @@ class Endpoint: def __init__(self, server=None) -> None: ... def create_endpoint_request(self, request): ... def validate_request(self, request: OAuth2Request) -> EndpointRequest: ... - def create_response(self, validated_request: EndpointRequest) -> tuple[int, Incomplete, list[Incomplete]] | None: ... - def create_endpoint_response(self, request: OAuth2Request) -> tuple[int, Incomplete, list[Incomplete]] | None: ... - def __call__(self, request: OAuth2Request) -> tuple[int, Incomplete, list[Incomplete]] | None: ... + def create_response(self, validated_request: EndpointRequest) -> tuple[int, str, list[tuple[str, str]]] | None: ... + def create_endpoint_response(self, request: OAuth2Request) -> tuple[int, str, list[tuple[str, str]]] | None: ... + def __call__(self, request: OAuth2Request) -> tuple[int, str, list[tuple[str, str]]] | None: ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/authorization_code.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/authorization_code.pyi index 1ee7e57abbb9..02985f4be73f 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/authorization_code.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/authorization_code.pyi @@ -1,23 +1,23 @@ from collections.abc import Collection from logging import Logger -from typing import TypeAlias +from typing import ClassVar, Literal from authlib.oauth2 import OAuth2Request from authlib.oauth2.rfc6749 import AuthorizationEndpointMixin, BaseGrant, ClientMixin, TokenEndpointMixin - -_ServerResponse: TypeAlias = tuple[int, str, list[tuple[str, str]]] +from authlib.oauth2.rfc6750.token import _Token log: Logger class AuthorizationCodeGrant(BaseGrant, AuthorizationEndpointMixin, TokenEndpointMixin): - TOKEN_ENDPOINT_AUTH_METHODS: Collection[str] + TOKEN_ENDPOINT_AUTH_METHODS: ClassVar[list[str]] AUTHORIZATION_CODE_LENGTH: int RESPONSE_TYPES: Collection[str] - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] + def validate_authorization_request(self) -> str: ... - def create_authorization_response(self, redirect_uri: str, grant_user) -> _ServerResponse: ... + def create_authorization_response(self, redirect_uri: str, grant_user) -> tuple[Literal[302], str, list[tuple[str, str]]]: ... def validate_token_request(self) -> None: ... - def create_token_response(self) -> _ServerResponse: ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... def generate_authorization_code(self) -> str: ... def save_authorization_code(self, code: str, request: OAuth2Request): ... def query_authorization_code(self, code: str, client: ClientMixin): ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/base.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/base.pyi index 82cd47e1c2d3..c97f1b50b9ab 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/base.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/base.pyi @@ -1,23 +1,26 @@ from _typeshed import Incomplete from collections.abc import Collection -from typing import TypeAlias +from typing import ClassVar, TypeAlias from authlib.oauth2 import OAuth2Request -from authlib.oauth2.rfc6749 import ClientMixin - -from ..hooks import Hookable +from authlib.oauth2.rfc6749.authorization_server import AuthorizationServer +from authlib.oauth2.rfc6749.hooks import Hookable +from authlib.oauth2.rfc6749.models import ClientMixin +from authlib.oauth2.rfc6750.token import _Token _ServerResponse: TypeAlias = tuple[int, str, list[tuple[str, str]]] class BaseGrant(Hookable): - TOKEN_ENDPOINT_AUTH_METHODS: Collection[str] - GRANT_TYPE: str | None - TOKEN_RESPONSE_HEADER: Collection[tuple[str, str]] - prompt: Incomplete + TOKEN_ENDPOINT_AUTH_METHODS: ClassVar[list[str]] + GRANT_TYPE: ClassVar[str | None] + TOKEN_RESPONSE_HEADER: ClassVar[list[tuple[str, str]]] + + prompt: str redirect_uri: Incomplete request: OAuth2Request - server: Incomplete - def __init__(self, request: OAuth2Request, server) -> None: ... + server: AuthorizationServer + + def __init__(self, request: OAuth2Request, server: AuthorizationServer) -> None: ... @property def client(self): ... def generate_token( @@ -27,18 +30,19 @@ class BaseGrant(Hookable): grant_type: str | None = None, expires_in: int | None = None, include_refresh_token: bool = True, - ) -> dict[str, str | int]: ... + ) -> _Token: ... def authenticate_token_endpoint_client(self) -> ClientMixin: ... def save_token(self, token): ... def validate_requested_scope(self) -> None: ... class TokenEndpointMixin: - TOKEN_ENDPOINT_HTTP_METHODS: Incomplete - GRANT_TYPE: Incomplete + TOKEN_ENDPOINT_HTTP_METHODS: ClassVar[list[str]] + GRANT_TYPE: ClassVar[str | None] + @classmethod def check_token_endpoint(cls, request: OAuth2Request) -> bool: ... def validate_token_request(self) -> None: ... - def create_token_response(self) -> _ServerResponse: ... + def create_token_response(self) -> tuple[int, _Token, list[tuple[str, str]]]: ... class AuthorizationEndpointMixin: RESPONSE_TYPES: Collection[str] diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/client_credentials.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/client_credentials.pyi index 39a26a843f82..1ca004aa8c25 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/client_credentials.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/client_credentials.pyi @@ -1,10 +1,12 @@ from logging import Logger +from typing import ClassVar, Literal from authlib.oauth2.rfc6749 import BaseGrant, TokenEndpointMixin +from authlib.oauth2.rfc6750.token import _Token log: Logger class ClientCredentialsGrant(BaseGrant, TokenEndpointMixin): - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] def validate_token_request(self) -> None: ... - def create_token_response(self): ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/implicit.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/implicit.pyi index 69b1946356d2..9c0707d746ca 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/implicit.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/implicit.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete from logging import Logger +from typing import ClassVar from authlib.oauth2.rfc6749 import AuthorizationEndpointMixin, BaseGrant @@ -7,9 +8,9 @@ log: Logger class ImplicitGrant(BaseGrant, AuthorizationEndpointMixin): AUTHORIZATION_ENDPOINT: bool - TOKEN_ENDPOINT_AUTH_METHODS: Incomplete + TOKEN_ENDPOINT_AUTH_METHODS: ClassVar[list[str]] RESPONSE_TYPES: Incomplete - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] ERROR_RESPONSE_FRAGMENT: bool def validate_authorization_request(self): ... def create_authorization_response(self, redirect_uri, grant_user): ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/refresh_token.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/refresh_token.pyi index 670fc27460b8..64927ee80f11 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/refresh_token.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/refresh_token.pyi @@ -1,18 +1,18 @@ from logging import Logger -from typing import TypeAlias +from typing import ClassVar, Literal from authlib.oauth2.rfc6749 import BaseGrant, TokenEndpointMixin, TokenMixin - -_ServerResponse: TypeAlias = tuple[int, str, list[tuple[str, str]]] +from authlib.oauth2.rfc6750.token import _Token log: Logger class RefreshTokenGrant(BaseGrant, TokenEndpointMixin): - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] INCLUDE_NEW_REFRESH_TOKEN: bool + def validate_token_request(self) -> None: ... - def create_token_response(self) -> _ServerResponse: ... - def issue_token(self, user, refresh_token: TokenMixin) -> dict[str, str | int]: ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... + def issue_token(self, user, refresh_token: TokenMixin) -> _Token: ... def authenticate_refresh_token(self, refresh_token: str) -> TokenMixin: ... def authenticate_user(self, refresh_token): ... def revoke_old_credential(self, refresh_token: TokenMixin) -> None: ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6749/grants/resource_owner_password_credentials.pyi b/stubs/Authlib/authlib/oauth2/rfc6749/grants/resource_owner_password_credentials.pyi index 13037ed8d2f6..51486ad21ffd 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6749/grants/resource_owner_password_credentials.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6749/grants/resource_owner_password_credentials.pyi @@ -1,11 +1,13 @@ from logging import Logger +from typing import ClassVar, Literal from authlib.oauth2.rfc6749 import BaseGrant, TokenEndpointMixin +from authlib.oauth2.rfc6750.token import _Token log: Logger class ResourceOwnerPasswordCredentialsGrant(BaseGrant, TokenEndpointMixin): - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] def validate_token_request(self) -> None: ... - def create_token_response(self): ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... def authenticate_user(self, username, password): ... diff --git a/stubs/Authlib/authlib/oauth2/rfc6750/token.pyi b/stubs/Authlib/authlib/oauth2/rfc6750/token.pyi index bd521552611f..2131e8226cb4 100644 --- a/stubs/Authlib/authlib/oauth2/rfc6750/token.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc6750/token.pyi @@ -1,5 +1,6 @@ from collections.abc import Callable -from typing import Protocol, type_check_only +from typing import Final, Protocol, TypedDict, type_check_only +from typing_extensions import NotRequired from authlib.oauth2.rfc6749 import ClientMixin @@ -7,12 +8,22 @@ from authlib.oauth2.rfc6749 import ClientMixin class _TokenGenerator(Protocol): def __call__(self, *, client: ClientMixin, grant_type: str, user, scope: str) -> str: ... +@type_check_only +class _Token(TypedDict): + token_type: str + access_token: str + expires_in: NotRequired[int] + refresh_token: NotRequired[str] + scope: NotRequired[str] + class BearerTokenGenerator: - DEFAULT_EXPIRES_IN: int - GRANT_TYPES_EXPIRES_IN: dict[str, int] + DEFAULT_EXPIRES_IN: Final[int] + GRANT_TYPES_EXPIRES_IN: Final[dict[str, int]] + access_token_generator: _TokenGenerator refresh_token_generator: _TokenGenerator expires_generator: Callable[[ClientMixin, str], int] + def __init__( self, access_token_generator: _TokenGenerator, @@ -29,7 +40,7 @@ class BearerTokenGenerator: scope: str | None = None, expires_in: int | None = None, include_refresh_token: bool = True, - ) -> dict[str, str | int]: ... + ) -> _Token: ... def __call__( self, grant_type: str, @@ -38,4 +49,4 @@ class BearerTokenGenerator: scope: str | None = None, expires_in: int | None = None, include_refresh_token: bool = True, - ) -> dict[str, str | int]: ... + ) -> _Token: ... diff --git a/stubs/Authlib/authlib/oauth2/rfc7523/jwt_bearer.pyi b/stubs/Authlib/authlib/oauth2/rfc7523/jwt_bearer.pyi index aa16b6a26f90..600be379c3d6 100644 --- a/stubs/Authlib/authlib/oauth2/rfc7523/jwt_bearer.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc7523/jwt_bearer.pyi @@ -1,14 +1,15 @@ from _typeshed import Incomplete from logging import Logger -from typing import ClassVar, Final +from typing import ClassVar, Final, Literal from authlib.oauth2.rfc6749 import BaseGrant, TokenEndpointMixin +from authlib.oauth2.rfc6750.token import _Token log: Logger JWT_BEARER_GRANT_TYPE: Final[str] class JWTBearerGrant(BaseGrant, TokenEndpointMixin): - GRANT_TYPE = JWT_BEARER_GRANT_TYPE + GRANT_TYPE: ClassVar[str] CLAIMS_OPTIONS: ClassVar[dict[str, dict[str, bool]]] LEEWAY: ClassVar[int] @staticmethod @@ -17,7 +18,7 @@ class JWTBearerGrant(BaseGrant, TokenEndpointMixin): def process_assertion_claims(self, assertion) -> dict[str, Incomplete]: ... def extract_assertion(self, assertion: str) -> tuple[dict[str, Incomplete], dict[Incomplete, Incomplete]]: ... def validate_token_request(self) -> None: ... - def create_token_response(self): ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... def resolve_issuer_client(self, issuer): ... def resolve_client_public_key(self, client): ... def authenticate_user(self, subject): ... diff --git a/stubs/Authlib/authlib/oauth2/rfc8628/device_code.pyi b/stubs/Authlib/authlib/oauth2/rfc8628/device_code.pyi index da0bd0bd1bb4..cfd236a1bca3 100644 --- a/stubs/Authlib/authlib/oauth2/rfc8628/device_code.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc8628/device_code.pyi @@ -1,16 +1,19 @@ -from _typeshed import Incomplete from logging import Logger +from typing import ClassVar, Final, Literal from authlib.oauth2.rfc6749 import BaseGrant, TokenEndpointMixin +from authlib.oauth2.rfc6750.token import _Token log: Logger -DEVICE_CODE_GRANT_TYPE: str + +DEVICE_CODE_GRANT_TYPE: Final[str] class DeviceCodeGrant(BaseGrant, TokenEndpointMixin): - GRANT_TYPE = DEVICE_CODE_GRANT_TYPE - TOKEN_ENDPOINT_AUTH_METHODS: Incomplete + GRANT_TYPE: ClassVar[str] + TOKEN_ENDPOINT_AUTH_METHODS: ClassVar[list[str]] + def validate_token_request(self) -> None: ... - def create_token_response(self): ... + def create_token_response(self) -> tuple[Literal[200], _Token, list[tuple[str, str]]]: ... def validate_device_credential(self, credential): ... def query_device_credential(self, device_code): ... def query_user_grant(self, user_code): ... diff --git a/stubs/Authlib/authlib/oauth2/rfc9101/authorization_server.pyi b/stubs/Authlib/authlib/oauth2/rfc9101/authorization_server.pyi index 5461a00b654c..d4640c975dc5 100644 --- a/stubs/Authlib/authlib/oauth2/rfc9101/authorization_server.pyi +++ b/stubs/Authlib/authlib/oauth2/rfc9101/authorization_server.pyi @@ -11,6 +11,7 @@ class JWTAuthenticationRequest: def __call__(self, authorization_server: AuthorizationServer) -> None: ... def get_request_object_signing_algorithms(self, client) -> list[str]: ... def parse_authorization_request(self, authorization_server: AuthorizationServer, request: OAuth2Request) -> None: ... + def validate_request_uri(self, request_uri: str, client: ClientMixin) -> bool: ... def get_request_object(self, request_uri: str): ... def resolve_client_public_key(self, client: ClientMixin): ... def get_server_metadata(self) -> dict[str, Incomplete]: ... diff --git a/stubs/Authlib/authlib/oidc/core/__init__.pyi b/stubs/Authlib/authlib/oidc/core/__init__.pyi index 0763373dc8ff..d2aba84665a0 100644 --- a/stubs/Authlib/authlib/oidc/core/__init__.pyi +++ b/stubs/Authlib/authlib/oidc/core/__init__.pyi @@ -1,3 +1,4 @@ +from .authorization_request import OpenIDJWTAuthenticationRequest as OpenIDJWTAuthenticationRequest from .claims import ( CodeIDToken as CodeIDToken, HybridIDToken as HybridIDToken, @@ -16,6 +17,7 @@ from .models import AuthorizationCodeMixin as AuthorizationCodeMixin from .userinfo import UserInfoEndpoint as UserInfoEndpoint __all__ = [ + "OpenIDJWTAuthenticationRequest", "AuthorizationCodeMixin", "IDToken", "CodeIDToken", diff --git a/stubs/Authlib/authlib/oidc/core/authorization_request.pyi b/stubs/Authlib/authlib/oidc/core/authorization_request.pyi new file mode 100644 index 000000000000..0f1dd40b80df --- /dev/null +++ b/stubs/Authlib/authlib/oidc/core/authorization_request.pyi @@ -0,0 +1,5 @@ +from authlib.oauth2.rfc6749.models import ClientMixin +from authlib.oauth2.rfc9101 import JWTAuthenticationRequest + +class OpenIDJWTAuthenticationRequest(JWTAuthenticationRequest): + def get_client_request_uris(self, client: ClientMixin) -> list[str]: ... diff --git a/stubs/Authlib/authlib/oidc/core/grants/hybrid.pyi b/stubs/Authlib/authlib/oidc/core/grants/hybrid.pyi index f2652cc1b9cc..1818d0eb6c9d 100644 --- a/stubs/Authlib/authlib/oidc/core/grants/hybrid.pyi +++ b/stubs/Authlib/authlib/oidc/core/grants/hybrid.pyi @@ -1,5 +1,6 @@ from _typeshed import Incomplete from logging import Logger +from typing import ClassVar from authlib.oidc.core import OpenIDImplicitGrant @@ -8,8 +9,9 @@ log: Logger class OpenIDHybridGrant(OpenIDImplicitGrant): AUTHORIZATION_CODE_LENGTH: int RESPONSE_TYPES: Incomplete - GRANT_TYPE: str + GRANT_TYPE: ClassVar[str] DEFAULT_RESPONSE_MODE: str + def generate_authorization_code(self) -> str: ... def save_authorization_code(self, code, request): ... def validate_authorization_request(self) -> str: ... diff --git a/stubs/Authlib/authlib/oidc/core/grants/util.pyi b/stubs/Authlib/authlib/oidc/core/grants/util.pyi index fe07d01da6f3..04b835d135a3 100644 --- a/stubs/Authlib/authlib/oidc/core/grants/util.pyi +++ b/stubs/Authlib/authlib/oidc/core/grants/util.pyi @@ -1,11 +1,16 @@ from _typeshed import ReadableBuffer from collections.abc import Collection, Iterable -from typing import Literal, SupportsBytes, SupportsIndex, overload +from typing import Literal, SupportsBytes, SupportsIndex, TypeVar, overload +from authlib.oauth2.rfc6749.grants.base import BaseGrant from authlib.oidc.core import UserInfo +from authlib.oidc.core.grants.implicit import OpenIDImplicitGrant + +_G = TypeVar("_G", bound=BaseGrant) def is_openid_scope(scope: Collection[str] | str | None) -> bool: ... -def validate_request_prompt(grant, redirect_uri: str, redirect_fragment: bool = False): ... +def validate_request_prompt(grant: _G, redirect_uri: str, redirect_fragment: bool = False) -> _G: ... +def validate_form_post_redirect_uri(grant: OpenIDImplicitGrant, redirect_uri: str) -> None: ... def validate_nonce(request, exists_nonce, required: bool = False): ... def generate_id_token( token: dict[str, str | int], diff --git a/stubs/Authlib/authlib/oidc/rpinitiated/end_session.pyi b/stubs/Authlib/authlib/oidc/rpinitiated/end_session.pyi index 85e56a5465e3..6c7c1f51e697 100644 --- a/stubs/Authlib/authlib/oidc/rpinitiated/end_session.pyi +++ b/stubs/Authlib/authlib/oidc/rpinitiated/end_session.pyi @@ -16,7 +16,7 @@ class EndSessionRequest(EndpointRequest): class EndSessionEndpoint(Endpoint): ENDPOINT_NAME: str def validate_request(self, request: OAuth2Request) -> EndSessionRequest: ... - def create_response(self, validated_request: EndSessionRequest) -> tuple[int, Incomplete, list[tuple[str, str]]] | None: ... # type: ignore[override] + def create_response(self, validated_request: EndSessionRequest) -> tuple[int, str, list[tuple[str, str]]] | None: ... # type: ignore[override] def resolve_client_from_id_token_claims(self, id_token_claims: dict[Incomplete, Incomplete]) -> Incomplete | None: ... def is_post_logout_redirect_uri_legitimate( self, request: OAuth2Request, post_logout_redirect_uri: str, client, logout_hint: str | None