diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 2b724712154b..a789fa447e83 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -59,6 +59,7 @@ "stubs/m3u8/m3u8/model.pyi", "stubs/Markdown", "stubs/mock/mock/mock.pyi", + "stubs/msal", "stubs/mysqlclient", "stubs/netaddr/netaddr/core.pyi", "stubs/netaddr/netaddr/ip/__init__.pyi", diff --git a/stubs/msal/@tests/stubtest_allowlist.txt b/stubs/msal/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..a4f6e7331ca8 --- /dev/null +++ b/stubs/msal/@tests/stubtest_allowlist.txt @@ -0,0 +1,6 @@ +# Interactive command-line tester ("python -m msal"), not a library API. +msal.__main__ + +# Requires the optional dependency pymsalruntime (installed with "msal[broker]"); +# importing this module without it raises ImportError. +msal.broker diff --git a/stubs/msal/METADATA.toml b/stubs/msal/METADATA.toml new file mode 100644 index 000000000000..40c334304b03 --- /dev/null +++ b/stubs/msal/METADATA.toml @@ -0,0 +1,2 @@ +version = "1.39.*" +upstream-repository = "https://github.com/AzureAD/microsoft-authentication-library-for-python" diff --git a/stubs/msal/msal/__init__.pyi b/stubs/msal/msal/__init__.pyi new file mode 100644 index 000000000000..f1bf6d7d80f1 --- /dev/null +++ b/stubs/msal/msal/__init__.pyi @@ -0,0 +1,18 @@ +from .application import ( + ClientApplication as ClientApplication, + ConfidentialClientApplication as ConfidentialClientApplication, + PublicClientApplication as PublicClientApplication, +) +from .auth_scheme import PopAuthScheme as PopAuthScheme +from .managed_identity import ( + ArcPlatformNotSupportedError as ArcPlatformNotSupportedError, + ManagedIdentityClient as ManagedIdentityClient, + ManagedIdentityError as ManagedIdentityError, + SystemAssignedManagedIdentity as SystemAssignedManagedIdentity, + UserAssignedManagedIdentity as UserAssignedManagedIdentity, +) +from .oauth2cli.assertion import AutoRefresher as AutoRefresher +from .oauth2cli.oauth2 import BrowserInteractionTimeoutError as BrowserInteractionTimeoutError +from .oauth2cli.oidc import IdTokenError as IdTokenError, Prompt as Prompt +from .sku import __version__ as __version__ +from .token_cache import SerializableTokenCache as SerializableTokenCache, TokenCache as TokenCache diff --git a/stubs/msal/msal/application.pyi b/stubs/msal/msal/application.pyi new file mode 100644 index 000000000000..fb490794adef --- /dev/null +++ b/stubs/msal/msal/application.pyi @@ -0,0 +1,240 @@ +from collections.abc import Mapping, MutableMapping +from logging import Logger +from typing import Any, Final, Protocol, type_check_only +from typing_extensions import deprecated + +from .auth_scheme import PopAuthScheme +from .authority import Authority, AuthorityBuilder +from .oauth2cli import Client +from .oauth2cli.http import _HttpClientLike +from .throttled_http_client import ThrottledHttpClient +from .token_cache import TokenCache +from .wstrust_response import * + +logger: Logger + +@type_check_only +class _OnBeforeLaunchingUI(Protocol): + # Called as on_before_launching_ui(ui="browser") or on_before_launching_ui(ui="broker"). + def __call__(self, *, ui: str) -> object: ... + +def extract_certs(public_cert_content: str) -> list[str]: ... + +class ClientApplication: + ACQUIRE_TOKEN_SILENT_ID: str + ACQUIRE_TOKEN_BY_REFRESH_TOKEN: str + ACQUIRE_TOKEN_BY_USERNAME_PASSWORD_ID: str + ACQUIRE_TOKEN_ON_BEHALF_OF_ID: str + ACQUIRE_TOKEN_BY_DEVICE_FLOW_ID: str + ACQUIRE_TOKEN_FOR_CLIENT_ID: str + ACQUIRE_TOKEN_BY_AUTHORIZATION_CODE_ID: str + ACQUIRE_TOKEN_INTERACTIVE: str + ACQUIRE_TOKEN_BY_USER_FIC_ID: str + GET_ACCOUNTS_ID: str + REMOVE_ACCOUNT_ID: str + ATTEMPT_REGION_DISCOVERY: bool + DISABLE_MSAL_FORCE_REGION: bool + client_id: str + client_credential: str | dict[str, Any] | None + client_claims: Mapping[str, Any] | None + http_client: ThrottledHttpClient + app_name: str | None + app_version: str | None + authority: Authority + token_cache: TokenCache + client: Client + authority_groups: dict[str, list[set[str]]] + def __init__( + self, + client_id: str, + client_credential: str | dict[str, Any] | None = None, + authority: str | AuthorityBuilder | None = None, + validate_authority: bool = True, + token_cache: TokenCache | None = None, + http_client: _HttpClientLike | None = None, + verify: bool | str = True, + proxies: Mapping[str, str] | None = None, + timeout: float | tuple[float, float] | tuple[float, None] | None = None, + client_claims: Mapping[str, Any] | None = None, + app_name: str | None = None, + app_version: str | None = None, + client_capabilities: list[str] | None = None, + azure_region: str | bool | None = None, + exclude_scopes: list[str] | None = None, + http_cache: MutableMapping[str, Any] | None = None, + instance_discovery: bool | None = None, + allow_broker: bool | None = None, + enable_pii_log: bool | None = None, + oidc_authority: str | None = None, + ) -> None: ... + def is_pop_supported(self) -> bool: ... + def initiate_auth_code_flow( + self, + scopes: list[str], + redirect_uri: str | None = None, + state: str | None = None, + prompt: str | None = None, + login_hint: str | None = None, + domain_hint: str | None = None, + claims_challenge: str | None = None, + max_age: int | None = None, + response_mode: str | None = None, + ) -> dict[str, Any]: ... + @deprecated("Change your get_authorization_request_url() to initiate_auth_code_flow()") + def get_authorization_request_url( + self, + scopes: list[str], + login_hint: str | None = None, + state: str | None = None, + redirect_uri: str | None = None, + response_type: str = "code", + prompt: str | None = None, + nonce: str | None = None, + domain_hint: str | None = None, + claims_challenge: str | None = None, + **kwargs: Any, + ) -> str: ... + def acquire_token_by_auth_code_flow( + self, auth_code_flow: dict[str, Any], auth_response: dict[str, Any], scopes: list[str] | None = None, **kwargs: Any + ) -> dict[str, Any]: ... + @deprecated("Change your acquire_token_by_authorization_code() to acquire_token_by_auth_code_flow()") + def acquire_token_by_authorization_code( + self, + code: str, + scopes: list[str], + redirect_uri: str | None = None, + nonce: str | None = None, + claims_challenge: str | None = None, + forwarded_client_claims: str | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + def get_accounts(self, username: str | None = None) -> list[dict[str, Any]]: ... + def remove_account(self, account: Mapping[str, Any]) -> None: ... + def acquire_token_silent( + self, + scopes: list[str], + account: Mapping[str, Any] | None, + authority: str | None = None, + force_refresh: bool | None = False, + claims_challenge: str | None = None, + forwarded_client_claims: str | None = None, + auth_scheme: PopAuthScheme | None = None, + **kwargs: Any, + ) -> dict[str, Any] | None: ... + def acquire_token_silent_with_error( + self, + scopes: list[str], + account: Mapping[str, Any] | None, + authority: str | None = None, + force_refresh: bool | None = False, + claims_challenge: str | None = None, + forwarded_client_claims: str | None = None, + auth_scheme: PopAuthScheme | None = None, + **kwargs: Any, + ) -> dict[str, Any] | None: ... + def acquire_token_by_refresh_token(self, refresh_token: str, scopes: list[str], **kwargs: Any) -> dict[str, Any]: ... + def acquire_token_by_username_password( + self, + username: str, + password: str, + scopes: list[str], + claims_challenge: str | None = None, + auth_scheme: PopAuthScheme | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + +class PublicClientApplication(ClientApplication): + DEVICE_FLOW_CORRELATION_ID: Final = "_correlation_id" + CONSOLE_WINDOW_HANDLE: Final[object] + def __init__( + self, + client_id: str, + client_credential: None = None, + *, + enable_broker_on_windows: bool | None = None, + enable_broker_on_mac: bool | None = None, + enable_broker_on_linux: bool | None = None, + enable_broker_on_wsl: bool | None = None, + authority: str | AuthorityBuilder | None = None, + validate_authority: bool = True, + token_cache: TokenCache | None = None, + http_client: _HttpClientLike | None = None, + verify: bool | str = True, + proxies: Mapping[str, str] | None = None, + timeout: float | tuple[float, float] | tuple[float, None] | None = None, + client_claims: Mapping[str, Any] | None = None, + app_name: str | None = None, + app_version: str | None = None, + client_capabilities: list[str] | None = None, + azure_region: str | bool | None = None, + exclude_scopes: list[str] | None = None, + http_cache: MutableMapping[str, Any] | None = None, + instance_discovery: bool | None = None, + allow_broker: bool | None = None, + enable_pii_log: bool | None = None, + oidc_authority: str | None = None, + ) -> None: ... + def acquire_token_interactive( + self, + scopes: list[str], + prompt: str | None = None, + login_hint: str | None = None, + domain_hint: str | None = None, + claims_challenge: str | None = None, + timeout: float | None = None, + port: int | None = None, + extra_scopes_to_consent: list[str] | None = None, + max_age: int | None = None, + parent_window_handle: object | None = None, + on_before_launching_ui: _OnBeforeLaunchingUI | None = None, + auth_scheme: PopAuthScheme | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + def initiate_device_flow( + self, scopes: list[str] | None = None, *, claims_challenge: str | None = None, **kwargs: Any + ) -> dict[str, Any]: ... + def acquire_token_by_device_flow( + self, flow: dict[str, Any], claims_challenge: str | None = None, **kwargs: Any + ) -> dict[str, Any]: ... + @deprecated( + "This API has been deprecated for public client flows, please use a more secure flow. " + "See https://aka.ms/msal-ropc-migration for migration guidance" + ) + def acquire_token_by_username_password( + self, + username: str, + password: str, + scopes: list[str], + claims_challenge: str | None = None, + auth_scheme: PopAuthScheme | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + +class ConfidentialClientApplication(ClientApplication): + def acquire_token_for_client( + self, + scopes: list[str], + claims_challenge: str | None = None, + fmi_path: str | None = None, + forwarded_client_claims: str | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + def remove_tokens_for_client(self) -> None: ... + def acquire_token_on_behalf_of( + self, + user_assertion: str, + scopes: list[str], + claims_challenge: str | None = None, + forwarded_client_claims: str | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... + def acquire_token_by_user_federated_identity_credential( + self, + scopes: list[str], + assertion: str, + username: str | None = None, + user_object_id: str | None = None, + claims_challenge: str | None = None, + forwarded_client_claims: str | None = None, + **kwargs: Any, + ) -> dict[str, Any]: ... diff --git a/stubs/msal/msal/auth_scheme.pyi b/stubs/msal/msal/auth_scheme.pyi new file mode 100644 index 000000000000..73d062c3e3b0 --- /dev/null +++ b/stubs/msal/msal/auth_scheme.pyi @@ -0,0 +1,9 @@ +from typing import Final + +class PopAuthScheme: + HTTP_GET: Final = "GET" + HTTP_POST: Final = "POST" + HTTP_PUT: Final = "PUT" + HTTP_DELETE: Final = "DELETE" + HTTP_PATCH: Final = "PATCH" + def __init__(self, http_method: str | None = None, url: str | None = None, nonce: str | None = None) -> None: ... diff --git a/stubs/msal/msal/authority.pyi b/stubs/msal/msal/authority.pyi new file mode 100644 index 000000000000..b63c419bfd7e --- /dev/null +++ b/stubs/msal/msal/authority.pyi @@ -0,0 +1,40 @@ +from logging import Logger +from typing import Any +from urllib.parse import ParseResult + +from .oauth2cli.http import _HttpClientLike + +logger: Logger +AZURE_US_GOVERNMENT: str +DEPRECATED_AZURE_CHINA: str +AZURE_PUBLIC: str +AZURE_GOV_FR: str +AZURE_GOV_DE: str +AZURE_GOV_SG: str +WORLD_WIDE: str +WELL_KNOWN_AUTHORITY_HOSTS: frozenset[str] +WELL_KNOWN_B2C_HOSTS: list[str] + +class AuthorityBuilder: + def __init__(self, instance: str, tenant: str) -> None: ... + +class Authority: + instance: str + tenant: str + is_adfs: bool + authorization_endpoint: str + token_endpoint: str + device_authorization_endpoint: str | None + def __init__( + self, + authority_url: str | AuthorityBuilder | None, + http_client: _HttpClientLike, + validate_authority: bool = True, + instance_discovery: bool | str | None = None, + oidc_authority_url: str | None = None, + ) -> None: ... + def user_realm_discovery(self, username: str, correlation_id: str | None = None, response=None) -> dict[str, Any]: ... + def has_valid_issuer(self) -> bool: ... + +def canonicalize(authority_or_auth_endpoint: str) -> tuple[ParseResult, str, str]: ... +def tenant_discovery(tenant_discovery_endpoint: str, http_client: _HttpClientLike, **kwargs) -> dict[str, Any]: ... diff --git a/stubs/msal/msal/broker.pyi b/stubs/msal/msal/broker.pyi new file mode 100644 index 000000000000..ee85a3cec1a8 --- /dev/null +++ b/stubs/msal/msal/broker.pyi @@ -0,0 +1,6 @@ +from logging import Logger + +logger: Logger + +class RedirectUriError(ValueError): ... +class TokenTypeError(ValueError): ... diff --git a/stubs/msal/msal/cloudshell.pyi b/stubs/msal/msal/cloudshell.pyi new file mode 100644 index 000000000000..384fca5366a7 --- /dev/null +++ b/stubs/msal/msal/cloudshell.pyi @@ -0,0 +1,3 @@ +from logging import Logger + +logger: Logger diff --git a/stubs/msal/msal/exceptions.pyi b/stubs/msal/msal/exceptions.pyi new file mode 100644 index 000000000000..4252833f0ee5 --- /dev/null +++ b/stubs/msal/msal/exceptions.pyi @@ -0,0 +1,6 @@ +class MsalError(Exception): + msg: str + +class MsalServiceError(MsalError): + msg: str + def __init__(self, *args: object, error: str | None, error_description: str | None) -> None: ... diff --git a/stubs/msal/msal/individual_cache.pyi b/stubs/msal/msal/individual_cache.pyi new file mode 100644 index 000000000000..3aff0967a324 --- /dev/null +++ b/stubs/msal/msal/individual_cache.pyi @@ -0,0 +1,15 @@ +from _typeshed import Incomplete +from collections.abc import Iterator, MutableMapping + +class _ExpiringMapping(MutableMapping[Incomplete, Incomplete]): + def __init__(self, mapping=None, capacity=None, expires_in=None, lock=None, *args, **kwargs) -> None: ... + def set(self, key, value, expires_in) -> None: ... + def __setitem__(self, key, value) -> None: ... + def __getitem__(self, key): ... + def __delitem__(self, key) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[Incomplete]: ... + +class _IndividualCache: + def __init__(self, mapping=None, key_maker=None, expires_in=None) -> None: ... + def __call__(self, function): ... diff --git a/stubs/msal/msal/managed_identity.pyi b/stubs/msal/msal/managed_identity.pyi new file mode 100644 index 000000000000..d77a9e5aacf7 --- /dev/null +++ b/stubs/msal/msal/managed_identity.pyi @@ -0,0 +1,64 @@ +from collections import UserDict +from collections.abc import MutableMapping +from logging import Logger +from typing import Any, Final, overload + +from .oauth2cli.http import _HttpClientLike +from .throttled_http_client import ThrottledHttpClientBase +from .token_cache import TokenCache + +logger: Logger + +class ManagedIdentityError(ValueError): ... + +class ManagedIdentity(UserDict[str, str | None]): + ID_TYPE: Final = "ManagedIdentityIdType" + ID: Final = "Id" + CLIENT_ID: Final = "ClientId" + RESOURCE_ID: Final = "ResourceId" + OBJECT_ID: Final = "ObjectId" + SYSTEM_ASSIGNED: Final = "SystemAssigned" + @classmethod + def is_managed_identity(cls, unknown: object): ... + @classmethod + def is_system_assigned(cls, unknown: object) -> bool: ... + @classmethod + def is_user_assigned(cls, unknown: object): ... + def __init__(self, identifier: str | None = None, id_type: str | None = None) -> None: ... + +class SystemAssignedManagedIdentity(ManagedIdentity): + def __init__(self) -> None: ... + +class UserAssignedManagedIdentity(ManagedIdentity): + @overload + def __init__(self, *, client_id: str, resource_id: None = None, object_id: None = None) -> None: ... + @overload + def __init__(self, *, client_id: None = None, resource_id: str, object_id: None = None) -> None: ... + @overload + def __init__(self, *, client_id: None = None, resource_id: None = None, object_id: str) -> None: ... + +class _ThrottledHttpClient(ThrottledHttpClientBase): + def __init__(self, *args, **kwargs) -> None: ... + +class ManagedIdentityClient: + def __init__( + self, + managed_identity: dict[str, Any] | ManagedIdentity, + *, + http_client: _HttpClientLike, + token_cache: TokenCache | None = None, + http_cache: MutableMapping[str, Any] | None = None, + client_capabilities: list[str] | None = None, + ) -> None: ... + def acquire_token_for_client(self, *, resource: str, claims_challenge: str | None = None) -> dict[str, Any]: ... + +APP_SERVICE: Final[object] +AZURE_ARC: Final[object] +CLOUD_SHELL: Final[object] +MACHINE_LEARNING: Final[object] +SERVICE_FABRIC: Final[object] +DEFAULT_TO_VM: Final[object] + +def get_managed_identity_source() -> object: ... + +class ArcPlatformNotSupportedError(ManagedIdentityError): ... diff --git a/stubs/msal/msal/mex.pyi b/stubs/msal/msal/mex.pyi new file mode 100644 index 000000000000..e7b14e967020 --- /dev/null +++ b/stubs/msal/msal/mex.pyi @@ -0,0 +1,15 @@ +from _typeshed import Incomplete +from logging import Logger +from xml.etree.ElementTree import Element + +logger: Logger + +def send_request(mex_endpoint: str, http_client, **kwargs) -> dict[str, Incomplete] | None: ... + +class Mex: + NS: dict[str, str] + ACTION_13: str + ACTION_2005: str + dom: Element + def __init__(self, mex_document: str) -> None: ... + def get_wstrust_username_password_endpoint(self) -> dict[str, Incomplete] | None: ... diff --git a/stubs/msal/msal/oauth2cli/__init__.pyi b/stubs/msal/msal/oauth2cli/__init__.pyi new file mode 100644 index 000000000000..2cb3ba1efae8 --- /dev/null +++ b/stubs/msal/msal/oauth2cli/__init__.pyi @@ -0,0 +1,5 @@ +from .assertion import JwtAssertionCreator as JwtAssertionCreator, JwtSigner as JwtSigner +from .authcode import AuthCodeReceiver as AuthCodeReceiver +from .oidc import Client as Client, IdTokenError as IdTokenError + +__version__: str diff --git a/stubs/msal/msal/oauth2cli/assertion.pyi b/stubs/msal/msal/oauth2cli/assertion.pyi new file mode 100644 index 000000000000..0071d8b4ac8a --- /dev/null +++ b/stubs/msal/msal/oauth2cli/assertion.pyi @@ -0,0 +1,51 @@ +from _typeshed import Incomplete +from collections.abc import Callable +from logging import Logger +from typing import Any, Generic, TypeVar + +_T = TypeVar("_T") + +logger: Logger + +class AssertionCreator: + def create_normal_assertion( + self, audience, issuer, subject, expires_at=None, expires_in: int = 600, issued_at=None, assertion_id=None, **kwargs + ) -> bytes: ... + def create_regenerative_assertion( + self, audience, issuer, subject=None, expires_in: int = 600, **kwargs + ) -> AutoRefresher[bytes]: ... + +class AutoRefresher(Generic[_T]): + def __init__(self, factory: Callable[[], _T], expires_in: float = 540) -> None: ... + def __call__(self) -> _T: ... + +class JwtAssertionCreator(AssertionCreator): + key: Incomplete + algorithm: str + headers: dict[str, Any] + def __init__( + self, + key, + algorithm: str, + sha1_thumbprint: str | None = None, + headers: dict[str, Any] | None = None, + *, + sha256_thumbprint: str | None = None, + ) -> None: ... + def create_normal_assertion( + self, + audience, + issuer, + subject=None, + expires_at=None, + expires_in: int = 600, + issued_at=None, + assertion_id=None, + not_before=None, + additional_claims=None, + **kwargs, + ) -> bytes: ... + sign_assertion = create_normal_assertion + +Signer = AssertionCreator +JwtSigner = JwtAssertionCreator diff --git a/stubs/msal/msal/oauth2cli/authcode.pyi b/stubs/msal/msal/oauth2cli/authcode.pyi new file mode 100644 index 000000000000..d3d0eed9f98d --- /dev/null +++ b/stubs/msal/msal/oauth2cli/authcode.pyi @@ -0,0 +1,34 @@ +from collections.abc import Callable +from http.server import BaseHTTPRequestHandler, HTTPServer +from logging import Logger +from types import TracebackType +from typing import Any +from typing_extensions import Self + +logger: Logger + +def obtain_auth_code(listen_port: int, auth_uri: str | None = None): ... +def is_wsl() -> bool: ... + +class _AuthCodeHandler(BaseHTTPRequestHandler): + def do_GET(self) -> None: ... + def do_POST(self) -> None: ... + def log_message(self, format: str, *args: Any) -> None: ... + +class _AuthCodeHttpServer(HTTPServer): + def __init__(self, server_address: tuple[str, int], *args, **kwargs) -> None: ... + def handle_timeout(self) -> None: ... + +class _AuthCodeHttpServer6(_AuthCodeHttpServer): ... + +class AuthCodeReceiver: + def __init__( + self, port: int | None = None, scheduled_actions: list[tuple[float, Callable[[], object]]] | None = None + ) -> None: ... + def get_port(self) -> int: ... + def get_auth_response(self, timeout: float | None = None, **kwargs) -> dict[str, Any] | None: ... + def close(self) -> None: ... + def __enter__(self) -> Self: ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None + ) -> None: ... diff --git a/stubs/msal/msal/oauth2cli/http.pyi b/stubs/msal/msal/oauth2cli/http.pyi new file mode 100644 index 000000000000..0e846c0be44b --- /dev/null +++ b/stubs/msal/msal/oauth2cli/http.pyi @@ -0,0 +1,18 @@ +from typing import Protocol, type_check_only + +# The HTTP client object accepted by MSAL is duck-typed: it can be a requests.Session, +# an instance of a subclass of HttpClient, or any object with compatible post() and get() methods. +@type_check_only +class _HttpClientLike(Protocol): # noqa: Y046 + def post(self, url: str, /, *, params=..., data=..., headers=...): ... + def get(self, url: str, /, *, params=..., headers=...): ... + +class HttpClient: + def post(self, url: str, params=None, data=None, headers=None, **kwargs) -> Response: ... + def get(self, url: str, params=None, headers=None, **kwargs) -> Response: ... + +class Response: + status_code: int + text: str + headers: dict[str, str] + def raise_for_status(self) -> None: ... diff --git a/stubs/msal/msal/oauth2cli/oauth2.pyi b/stubs/msal/msal/oauth2cli/oauth2.pyi new file mode 100644 index 000000000000..2f9997088cdb --- /dev/null +++ b/stubs/msal/msal/oauth2cli/oauth2.pyi @@ -0,0 +1,95 @@ +from _typeshed import Incomplete +from collections.abc import Callable, Mapping +from logging import Logger +from typing import Any +from typing_extensions import deprecated + +from .authcode import AuthCodeReceiver +from .http import _HttpClientLike + +string_types: tuple[type[str]] + +class BrowserInteractionTimeoutError(RuntimeError): ... + +class BaseClient: + @staticmethod + def encode_saml_assertion(assertion: bytes) -> bytes: ... + CLIENT_ASSERTION_TYPE_JWT: str + CLIENT_ASSERTION_TYPE_SAML2: str + client_assertion_encoders: dict[str, Callable[[bytes], bytes]] + + @property + @deprecated("Will be gone in next major release") + def session(self): ... + @session.setter + @deprecated("Will be gone in next major release") + def session(self, value) -> None: ... + + configuration: dict[str, Incomplete] + client_id: str + client_secret: str | None + client_assertion: str | bytes | Callable[..., str | bytes] | None + default_headers: dict[str, str] + default_body: dict[str, Incomplete] + logger: Logger + def __init__( + self, + server_configuration: dict[str, Incomplete], + client_id: str, + http_client: _HttpClientLike | None = None, + client_secret: str | None = None, + client_assertion: str | bytes | Callable[..., str | bytes] | None = None, + client_assertion_type: str | None = None, + default_headers: dict[str, str] | None = None, + default_body: dict[str, Incomplete] | None = None, + verify: bool | str | None = None, + proxies: Mapping[str, str] | None = None, + timeout: float | tuple[float, float] | tuple[float, None] | None = None, + ) -> None: ... + def obtain_token_by_refresh_token(self, refresh_token: str, scope=None, **kwargs) -> dict[str, Any]: ... + +class Client(BaseClient): + DEVICE_FLOW: dict[str, str] + DEVICE_FLOW_RETRIABLE_ERRORS: tuple[str, ...] + GRANT_TYPE_SAML2: str + GRANT_TYPE_JWT: str + grant_assertion_encoders: dict[str, Callable[[bytes], bytes]] + def initiate_device_flow(self, scope=None, *, data=None, **kwargs) -> dict[str, Any]: ... + def obtain_token_by_device_flow( + self, flow: dict[str, Any], exit_condition: Callable[[dict[str, Any]], bool] = ..., **kwargs + ) -> dict[str, Any]: ... + @deprecated("Use initiate_auth_code_flow() instead.") + def build_auth_request_uri(self, response_type: str, redirect_uri=None, scope=None, state=None, **kwargs) -> str: ... + def initiate_auth_code_flow(self, scope=None, redirect_uri=None, state=None, **kwargs) -> dict[str, Any]: ... + def obtain_token_by_auth_code_flow( + self, auth_code_flow: dict[str, Any], auth_response: dict[str, Any], scope=None, **kwargs + ) -> dict[str, Any]: ... + def obtain_token_by_browser( + self, redirect_uri: str | None = None, auth_code_receiver: AuthCodeReceiver | None = None, **kwargs + ) -> dict[str, Any]: ... + @staticmethod + @deprecated("Use obtain_token_by_auth_code_flow() instead") + def parse_auth_response(params, state=None): ... + @deprecated("Use obtain_token_by_auth_code_flow() instead") + def obtain_token_by_authorization_code(self, code: str, redirect_uri=None, scope=None, **kwargs) -> dict[str, Any]: ... + def obtain_token_by_username_password(self, username: str, password: str, scope=None, **kwargs) -> dict[str, Any]: ... + def obtain_token_for_client(self, scope=None, **kwargs) -> dict[str, Any]: ... + def obtain_token_by_user_fic( + self, scope, assertion: str, username: str | None = None, user_object_id: str | None = None, **kwargs + ) -> dict[str, Any]: ... + on_obtaining_tokens: Callable[[dict[str, Any]], object] + on_removing_rt: Callable[[dict[str, Any]], object] + on_updating_rt: Callable[[dict[str, Any], str], object] + def __init__( + self, + server_configuration: dict[str, Incomplete], + client_id: str, + on_obtaining_tokens: Callable[[dict[str, Any]], object] = ..., + on_removing_rt: Callable[[dict[str, Any]], object] = ..., + on_updating_rt: Callable[[dict[str, Any], str], object] = ..., + **kwargs, + ) -> None: ... + def obtain_token_by_refresh_token( # type: ignore[override] + self, token_item, scope=None, rt_getter=..., on_removing_rt=None, on_updating_rt=None, **kwargs + ) -> dict[str, Any]: ... + def obtain_token_by_assertion(self, assertion, grant_type: str, scope=None, **kwargs) -> dict[str, Any]: ... diff --git a/stubs/msal/msal/oauth2cli/oidc.pyi b/stubs/msal/msal/oauth2cli/oidc.pyi new file mode 100644 index 000000000000..744c7a4e8481 --- /dev/null +++ b/stubs/msal/msal/oauth2cli/oidc.pyi @@ -0,0 +1,67 @@ +from collections.abc import Mapping +from logging import Logger +from typing import Any, Final, overload +from typing_extensions import deprecated + +from . import oauth2 + +logger: Logger + +@overload +def decode_part(raw: str, encoding: str = "utf-8") -> str: ... +@overload +def decode_part(raw: str, encoding: None) -> bytes: ... + +base64decode = decode_part + +class IdTokenError(RuntimeError): + def __init__(self, reason: str, now: float, claims: Mapping[str, Any]) -> None: ... + +class _IdTokenTimeError(IdTokenError): + def __init__(self, reason: str, now: float, claims: Mapping[str, Any]) -> None: ... + def log(self) -> None: ... + +class IdTokenIssuerError(IdTokenError): ... +class IdTokenAudienceError(IdTokenError): ... +class IdTokenNonceError(IdTokenError): ... + +@deprecated( + "decode_id_token() is deprecated. MSAL's token acquisition no longer validates the ID token; " + "validation is the application's responsibility." +) +def decode_id_token( + id_token: str, client_id: str | None = None, issuer: str | None = None, nonce: str | None = None, now: float | None = None +) -> dict[str, Any]: ... + +class Prompt: + NONE: Final = "none" + LOGIN: Final = "login" + CONSENT: Final = "consent" + SELECT_ACCOUNT: Final = "select_account" + CREATE: Final = "create" + +class Client(oauth2.Client): + @deprecated( + "decode_id_token() is deprecated. MSAL's token acquisition no longer validates the ID token; " + "validation is the application's responsibility." + ) + def decode_id_token(self, id_token: str, nonce: str | None = None) -> dict[str, Any]: ... + @deprecated("Use initiate_auth_code_flow() instead") + def build_auth_request_uri(self, response_type: str, nonce: str | None = None, **kwargs) -> str: ... # type: ignore[override] + @deprecated("Use obtain_token_by_auth_code_flow() instead") + def obtain_token_by_authorization_code(self, code: str, nonce: str | None = None, **kwargs) -> dict[str, Any]: ... # type: ignore[override] + def initiate_auth_code_flow(self, scope=None, **kwargs) -> dict[str, Any]: ... # type: ignore[override] + def obtain_token_by_auth_code_flow( # type: ignore[override] + self, auth_code_flow: dict[str, Any], auth_response: dict[str, Any], **kwargs + ) -> dict[str, Any]: ... + def obtain_token_by_browser( # type: ignore[override] + self, + display=None, + prompt: str | list[str] | tuple[str, ...] | None = None, + max_age: int | None = None, + ui_locales=None, + id_token_hint: str | None = None, + login_hint: str | None = None, + acr_values=None, + **kwargs, + ) -> dict[str, Any]: ... diff --git a/stubs/msal/msal/region.pyi b/stubs/msal/msal/region.pyi new file mode 100644 index 000000000000..384fca5366a7 --- /dev/null +++ b/stubs/msal/msal/region.pyi @@ -0,0 +1,3 @@ +from logging import Logger + +logger: Logger diff --git a/stubs/msal/msal/sku.pyi b/stubs/msal/msal/sku.pyi new file mode 100644 index 000000000000..008c7a43fe67 --- /dev/null +++ b/stubs/msal/msal/sku.pyi @@ -0,0 +1,2 @@ +__version__: str +SKU: str diff --git a/stubs/msal/msal/telemetry.pyi b/stubs/msal/msal/telemetry.pyi new file mode 100644 index 000000000000..3798c8bffdd8 --- /dev/null +++ b/stubs/msal/msal/telemetry.pyi @@ -0,0 +1,19 @@ +from _typeshed import Incomplete +from logging import Logger + +logger: Logger +CLIENT_REQUEST_ID: str +CLIENT_CURRENT_TELEMETRY: str +CLIENT_LAST_TELEMETRY: str +NON_SILENT_CALL: int +FORCE_REFRESH: int +AT_ABSENT: int +AT_EXPIRED: int +AT_AGING: int +RESERVED: int + +class _TelemetryContext: + def __init__(self, buffer, lock, api_id, correlation_id=None, refresh_reason=None) -> None: ... + def generate_headers(self) -> dict[str, str]: ... + def hit_an_access_token(self) -> None: ... + def update_telemetry(self, auth_result: Incomplete | None) -> None: ... diff --git a/stubs/msal/msal/throttled_http_client.pyi b/stubs/msal/msal/throttled_http_client.pyi new file mode 100644 index 000000000000..923de70171e1 --- /dev/null +++ b/stubs/msal/msal/throttled_http_client.pyi @@ -0,0 +1,26 @@ +from _typeshed import Incomplete +from collections.abc import MutableMapping +from typing import Any + +from .oauth2cli.http import Response + +DEVICE_AUTH_GRANT: str + +class RetryAfterParser: + FIELD_NAME_LOWER: str + def __init__(self, default_value: int | None = None) -> None: ... + def parse(self, *, result, **ignored) -> int: ... + +class NormalizedResponse(Response): + def __init__(self, raw_response) -> None: ... + def raise_for_status(self) -> None: ... + +class ThrottledHttpClientBase: + http_client: Incomplete + def __init__(self, http_client, *, http_cache: MutableMapping[str, Any] | None = None) -> None: ... + def post(self, *args, **kwargs) -> NormalizedResponse: ... + def get(self, *args, **kwargs) -> NormalizedResponse: ... + def close(self): ... + +class ThrottledHttpClient(ThrottledHttpClientBase): + def __init__(self, *args, default_throttle_time: int | None = None, **kwargs) -> None: ... diff --git a/stubs/msal/msal/token_cache.pyi b/stubs/msal/msal/token_cache.pyi new file mode 100644 index 000000000000..af90cec0cca0 --- /dev/null +++ b/stubs/msal/msal/token_cache.pyi @@ -0,0 +1,56 @@ +from collections.abc import Callable, Generator, Mapping +from logging import Logger +from typing import Any, Final +from typing_extensions import deprecated + +logger: Logger + +def is_subdict_of(small: Mapping[str, Any], big: Mapping[str, Any]) -> bool: ... + +class TokenCache: + class CredentialType: + ACCESS_TOKEN: Final = "AccessToken" + ACCESS_TOKEN_EXTENDED: Final = "atext" + REFRESH_TOKEN: Final = "RefreshToken" + ACCOUNT: Final = "Account" + ID_TOKEN: Final = "IdToken" + APP_METADATA: Final = "AppMetadata" + + class AuthorityType: + ADFS: Final = "ADFS" + MSSTS: Final = "MSSTS" + + key_makers: dict[str, Callable[..., str]] + def __init__(self) -> None: ... + def search( + self, + credential_type: str, + target: list[str] | None = None, + query: Mapping[str, Any] | None = None, + *, + now: float | None = None, + ) -> Generator[dict[str, Any]]: ... + @deprecated("Use list(search(...)) instead to explicitly get a list.") + def find( + self, + credential_type: str, + target: list[str] | None = None, + query: Mapping[str, Any] | None = None, + *, + now: float | None = None, + ) -> list[dict[str, Any]]: ... + def add(self, event: Mapping[str, Any], now: float | None = None) -> None: ... + def modify( + self, credential_type: str, old_entry: Mapping[str, Any], new_key_value_pairs: Mapping[str, Any] | None = None + ) -> None: ... + def remove_rt(self, rt_item: Mapping[str, Any]) -> None: ... + def update_rt(self, rt_item: Mapping[str, Any], new_rt: str) -> None: ... + def remove_at(self, at_item: Mapping[str, Any]) -> None: ... + def remove_idt(self, idt_item: Mapping[str, Any]) -> None: ... + def remove_account(self, account_item: Mapping[str, Any]) -> None: ... + +class SerializableTokenCache(TokenCache): + has_state_changed: bool + def add(self, event: Mapping[str, Any], *, now: float | None = None) -> None: ... # type: ignore[override] + def deserialize(self, state: str | None) -> None: ... + def serialize(self) -> str: ... diff --git a/stubs/msal/msal/wstrust_request.pyi b/stubs/msal/msal/wstrust_request.pyi new file mode 100644 index 000000000000..6721adc31bcd --- /dev/null +++ b/stubs/msal/msal/wstrust_request.pyi @@ -0,0 +1,11 @@ +from _typeshed import Incomplete +from datetime import datetime +from logging import Logger + +logger: Logger + +def send_request( + username: str, password: str, cloud_audience_urn: str, endpoint_address: str, soap_action: str | None, http_client, **kwargs +) -> dict[str, Incomplete]: ... +def escape_xml(s: str) -> str: ... +def wsu_time_format(datetime_obj: datetime) -> str: ... diff --git a/stubs/msal/msal/wstrust_response.pyi b/stubs/msal/msal/wstrust_response.pyi new file mode 100644 index 000000000000..e70afbee2c87 --- /dev/null +++ b/stubs/msal/msal/wstrust_response.pyi @@ -0,0 +1,11 @@ +from _typeshed import Incomplete + +SAML_TOKEN_TYPE_V1: str +SAML_TOKEN_TYPE_V2: str +WSS_SAML_TOKEN_PROFILE_V1_1: str +WSS_SAML_TOKEN_PROFILE_V2: str + +def parse_response(body: str) -> dict[str, Incomplete]: ... +def parse_error(body: str) -> dict[str, str | None] | None: ... +def findall_content(xml_string: str, tag: str) -> list[Incomplete]: ... +def parse_token_by_re(raw_response: str) -> dict[str, Incomplete] | None: ...