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
4 changes: 2 additions & 2 deletions stubs/Authlib/METADATA.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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: ...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down
3 changes: 3 additions & 0 deletions stubs/Authlib/authlib/oauth2/drafts/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .id_jag import IDJAGGrant as IDJAGGrant

__all__ = ["IDJAGGrant"]
29 changes: 29 additions & 0 deletions stubs/Authlib/authlib/oauth2/drafts/id_jag.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
10 changes: 5 additions & 5 deletions stubs/Authlib/authlib/oauth2/rfc6749/authorization_server.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions stubs/Authlib/authlib/oauth2/rfc6749/endpoint.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Original file line number Diff line number Diff line change
@@ -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): ...
Expand Down
32 changes: 18 additions & 14 deletions stubs/Authlib/authlib/oauth2/rfc6749/grants/base.pyi
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]]]: ...
5 changes: 3 additions & 2 deletions stubs/Authlib/authlib/oauth2/rfc6749/grants/implicit.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from _typeshed import Incomplete
from logging import Logger
from typing import ClassVar

from authlib.oauth2.rfc6749 import AuthorizationEndpointMixin, BaseGrant

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): ...
12 changes: 6 additions & 6 deletions stubs/Authlib/authlib/oauth2/rfc6749/grants/refresh_token.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Original file line number Diff line number Diff line change
@@ -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): ...
21 changes: 16 additions & 5 deletions stubs/Authlib/authlib/oauth2/rfc6750/token.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
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

@type_check_only
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,
Expand All @@ -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,
Expand All @@ -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: ...
Loading
Loading