Skip to content
Open
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
12 changes: 12 additions & 0 deletions stubs/Authlib/@tests/django_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SECRET_KEY = "1"

INSTALLED_APPS = (
"django.contrib.contenttypes",
"django.contrib.sites",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.admin.apps.SimpleAdminConfig",
"django.contrib.staticfiles",
"django.contrib.auth",
"authlib",
)
3 changes: 0 additions & 3 deletions stubs/Authlib/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,5 @@ authlib.oidc.core.grants.implicit.OpenIDImplicitGrant.validate_consent_request

# Exclude integrations dirs
# Failed to import, getting ModuleNotFoundError for third-party libs:
authlib.integrations.django_client.*
authlib.integrations.django_oauth1.*
authlib.integrations.django_oauth2.*
authlib.integrations.sqla_oauth2.*
authlib.integrations.starlette_client.*
6 changes: 5 additions & 1 deletion stubs/Authlib/METADATA.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ version = "1.8.0"
upstream-repository = "https://github.com/authlib/authlib"
dependencies = ["cryptography"]
# Requires a version of flask with a `py.typed` file
optional-dependencies = ["requests", "httpx2", "Flask>=2.0.0"]
optional-dependencies = ["requests", "httpx2", "Flask>=2.0.0", "django-stubs"]

[tool.stubtest]
mypy-plugins = ["mypy_django_plugin.main"]
mypy-plugins-config = {"django-stubs" = {"django_settings_module" = "@tests.django_settings"}}
19 changes: 9 additions & 10 deletions stubs/Authlib/authlib/integrations/django_client/apps.pyi
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
from _typeshed import Incomplete
from typing import TypeAlias

from django.http import HttpRequest, HttpResponseRedirect

from ..base_client import BaseApp, OAuth1Mixin, OAuth2Mixin, OpenIDMixin
from ..requests_client import OAuth1Session, OAuth2Session

_HttpResponseRedirect: TypeAlias = Incomplete # actual type is django.http.response.HttpResponseRedirect

class DjangoAppMixin:
def save_authorize_data(self, request, **kwargs) -> None: ...
def authorize_redirect(self, request, redirect_uri=None, **kwargs): ...
def save_authorize_data(self, request: HttpRequest, **kwargs) -> None: ...
def authorize_redirect(self, request: HttpRequest, redirect_uri=None, **kwargs) -> HttpResponseRedirect: ...

class DjangoOAuth1App(DjangoAppMixin, OAuth1Mixin, BaseApp):
client_cls = OAuth1Session
def authorize_access_token(self, request, **kwargs): ...
def authorize_access_token(self, request: HttpRequest, **kwargs): ...

class DjangoOAuth2App(DjangoAppMixin, OAuth2Mixin, OpenIDMixin, BaseApp):
client_cls = OAuth2Session
def logout_redirect(
self,
request,
request: HttpRequest,
post_logout_redirect_uri=None,
id_token_hint=None,
*,
state=None,
client_id=None,
logout_hint=None,
ui_locales=None,
) -> _HttpResponseRedirect: ...
def validate_logout_response(self, request): ...
def authorize_access_token(self, request, **kwargs): ...
) -> HttpResponseRedirect: ...
def validate_logout_response(self, request: HttpRequest): ...
def authorize_access_token(self, request: HttpRequest, **kwargs) -> dict[Incomplete, Incomplete]: ...
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from _typeshed import Incomplete
from django.dispatch import Signal

from ..base_client import FrameworkIntegration

# actual type is django.dispatch.Signal
token_update: Incomplete
token_update: Signal

class DjangoIntegration(FrameworkIntegration):
def update_token(self, token, refresh_token=None, access_token=None) -> None: ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import logging
from _typeshed import Incomplete

from authlib.oauth1 import AuthorizationServer as _AuthorizationServer, OAuth1Request, TemporaryCredential
from django.http import HttpResponse

log: logging.Logger

Expand All @@ -16,7 +17,7 @@ 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): ...
def handle_response(self, status_code, payload, headers) -> HttpResponse: ...

class CacheAuthorizationServer(BaseServer):
def __init__(self, client_model, token_model, token_generator=None) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/Authlib/authlib/integrations/django_oauth1/nonce.pyi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
def exists_nonce_in_cache(nonce, request, timeout) -> bool: ...
def exists_nonce_in_cache(nonce, request, timeout: int | float | None) -> bool: ...
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from _typeshed import Incomplete
from _typeshed import Incomplete, SupportsKeysAndGetItem, Unused
from collections.abc import Callable
from typing import Literal, ParamSpec, TypeVar, overload

from authlib.oauth2 import AuthorizationServer as _AuthorizationServer
from authlib.oauth2.rfc6750 import BearerTokenGenerator
from django.http import HttpResponse

from .requests import DjangoJsonRequest, DjangoOAuth2Request

Expand All @@ -16,9 +19,20 @@ 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): ...
def handle_response(self, status_code, payload, headers) -> HttpResponse: ...
def send_signal(self, name, *args, **kwargs) -> None: ...
def create_bearer_token_generator(self) -> BearerTokenGenerator: ...

def create_token_generator(token_generator_conf, length: int = 42): ...
def create_token_expires_in_generator(expires_in_conf=None): ...
_P = ParamSpec("_P")
_R = TypeVar("_R")

@overload
def create_token_generator(token_generator_conf: Callable[_P, _R], length: Unused = 42) -> Callable[_P, _R]: ...
@overload
def create_token_generator(token_generator_conf: str, length: Unused = 42): ...
@overload
def create_token_generator(token_generator_conf: Literal[True], length: int = 42) -> Callable[..., str]: ...

def create_token_expires_in_generator(
expires_in_conf: SupportsKeysAndGetItem[str, int] | None = None,
) -> Callable[[Incomplete, str], int]: ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Literal

from authlib.oauth2.rfc7009 import RevocationEndpoint as _RevocationEndpoint

class RevocationEndpoint(_RevocationEndpoint):
def query_token(self, token, token_type_hint): ...
def query_token(self, token, token_type_hint: Literal["access_token", "refresh_token"] | None): ...
def revoke_token(self, token, request) -> None: ...
21 changes: 15 additions & 6 deletions stubs/Authlib/authlib/integrations/django_oauth2/requests.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
from collections import defaultdict

from authlib.oauth2.rfc6749 import JsonPayload, JsonRequest, OAuth2Payload, OAuth2Request
from django.http import HttpRequest
from django.http.request import _ImmutableQueryDict

class DjangoOAuth2Payload(OAuth2Payload):
def __init__(self, request) -> None: ...
def __init__(self, request: HttpRequest) -> None: ...
@property
def data(self) -> dict[str, str]: ...
@property
def datalist(self) -> defaultdict[str, list[str]]: ...

class DjangoOAuth2Request(OAuth2Request):
payload: DjangoOAuth2Payload
def __init__(self, request) -> None: ...
def __init__(self, request: HttpRequest) -> None: ...
@property
def args(self): ...
def args(self) -> _ImmutableQueryDict: ...
@property
def form(self): ...
def form(self) -> _ImmutableQueryDict: ...

class DjangoJsonPayload(JsonPayload):
def __init__(self, request) -> None: ...
def __init__(self, request: HttpRequest) -> None: ...
@property
def data(self): ...

class DjangoJsonRequest(JsonRequest):
payload: DjangoJsonPayload
def __init__(self, request) -> None: ...
def __init__(self, request: HttpRequest) -> None: ...
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ from _typeshed import Incomplete

from authlib.oauth2 import ResourceProtector as _ResourceProtector
from authlib.oauth2.rfc6750 import BearerTokenValidator as _BearerTokenValidator
from django.http import HttpRequest, JsonResponse

class ResourceProtector(_ResourceProtector):
def acquire_token(self, request, scopes=None, **kwargs): ...
def __call__(self, scopes=None, optional=False, **kwargs): ...
def acquire_token(self, request: HttpRequest, scopes=None, **kwargs): ...
def __call__(self, scopes=None, optional: bool = False, **kwargs): ...

class BearerTokenValidator(_BearerTokenValidator):
token_model: Incomplete
def __init__(self, token_model, realm=None, **extra_attributes): ...
def authenticate_token(self, token_string): ...

def return_error_response(error): ...
def return_error_response(error) -> JsonResponse: ...
9 changes: 4 additions & 5 deletions stubs/Authlib/authlib/integrations/django_oauth2/signals.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from _typeshed import Incomplete
from django.dispatch import Signal

# actual types is django.dispatch.Signal
client_authenticated: Incomplete
token_revoked: Incomplete
token_authenticated: Incomplete
client_authenticated: Signal
token_revoked: Signal
token_authenticated: Signal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FlaskOAuth2Request(OAuth2Request):
payload: FlaskOAuth2Payload
def __init__(self, request: Request) -> None: ...
@property
def args(self) -> MultiDict[str, str]: ... # type: ignore[override]
def args(self) -> MultiDict[str, str]: ...
@property
def form(self) -> ImmutableMultiDict[str, str]: ...

Expand Down
2 changes: 1 addition & 1 deletion stubs/Authlib/authlib/oauth2/rfc6749/requests.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OAuth2Request(OAuth2Payload):
def __init__(self, method: str, uri: str, body, headers: Mapping[str, str] | None = None) -> None: ...

@property
def args(self) -> dict[str, str | None]: ...
def args(self) -> dict[str, str]: ...
@property
def form(self) -> dict[str, str]: ...
@property
Expand Down