Skip to content

Commit 8591aa4

Browse files
authored
Add stubs for msal (#16781)
1 parent 5aafe0b commit 8591aa4

26 files changed

Lines changed: 823 additions & 0 deletions

‎pyrightconfig.stricter.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"stubs/m3u8/m3u8/model.pyi",
6060
"stubs/Markdown",
6161
"stubs/mock/mock/mock.pyi",
62+
"stubs/msal",
6263
"stubs/mysqlclient",
6364
"stubs/netaddr/netaddr/core.pyi",
6465
"stubs/netaddr/netaddr/ip/__init__.pyi",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Interactive command-line tester ("python -m msal"), not a library API.
2+
msal.__main__
3+
4+
# Requires the optional dependency pymsalruntime (installed with "msal[broker]");
5+
# importing this module without it raises ImportError.
6+
msal.broker

‎stubs/msal/METADATA.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "1.39.*"
2+
upstream-repository = "https://github.com/AzureAD/microsoft-authentication-library-for-python"

‎stubs/msal/msal/__init__.pyi‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .application import (
2+
ClientApplication as ClientApplication,
3+
ConfidentialClientApplication as ConfidentialClientApplication,
4+
PublicClientApplication as PublicClientApplication,
5+
)
6+
from .auth_scheme import PopAuthScheme as PopAuthScheme
7+
from .managed_identity import (
8+
ArcPlatformNotSupportedError as ArcPlatformNotSupportedError,
9+
ManagedIdentityClient as ManagedIdentityClient,
10+
ManagedIdentityError as ManagedIdentityError,
11+
SystemAssignedManagedIdentity as SystemAssignedManagedIdentity,
12+
UserAssignedManagedIdentity as UserAssignedManagedIdentity,
13+
)
14+
from .oauth2cli.assertion import AutoRefresher as AutoRefresher
15+
from .oauth2cli.oauth2 import BrowserInteractionTimeoutError as BrowserInteractionTimeoutError
16+
from .oauth2cli.oidc import IdTokenError as IdTokenError, Prompt as Prompt
17+
from .sku import __version__ as __version__
18+
from .token_cache import SerializableTokenCache as SerializableTokenCache, TokenCache as TokenCache

‎stubs/msal/msal/application.pyi‎

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
from collections.abc import Mapping, MutableMapping
2+
from logging import Logger
3+
from typing import Any, Final, Protocol, type_check_only
4+
from typing_extensions import deprecated
5+
6+
from .auth_scheme import PopAuthScheme
7+
from .authority import Authority, AuthorityBuilder
8+
from .oauth2cli import Client
9+
from .oauth2cli.http import _HttpClientLike
10+
from .throttled_http_client import ThrottledHttpClient
11+
from .token_cache import TokenCache
12+
from .wstrust_response import *
13+
14+
logger: Logger
15+
16+
@type_check_only
17+
class _OnBeforeLaunchingUI(Protocol):
18+
# Called as on_before_launching_ui(ui="browser") or on_before_launching_ui(ui="broker").
19+
def __call__(self, *, ui: str) -> object: ...
20+
21+
def extract_certs(public_cert_content: str) -> list[str]: ...
22+
23+
class ClientApplication:
24+
ACQUIRE_TOKEN_SILENT_ID: str
25+
ACQUIRE_TOKEN_BY_REFRESH_TOKEN: str
26+
ACQUIRE_TOKEN_BY_USERNAME_PASSWORD_ID: str
27+
ACQUIRE_TOKEN_ON_BEHALF_OF_ID: str
28+
ACQUIRE_TOKEN_BY_DEVICE_FLOW_ID: str
29+
ACQUIRE_TOKEN_FOR_CLIENT_ID: str
30+
ACQUIRE_TOKEN_BY_AUTHORIZATION_CODE_ID: str
31+
ACQUIRE_TOKEN_INTERACTIVE: str
32+
ACQUIRE_TOKEN_BY_USER_FIC_ID: str
33+
GET_ACCOUNTS_ID: str
34+
REMOVE_ACCOUNT_ID: str
35+
ATTEMPT_REGION_DISCOVERY: bool
36+
DISABLE_MSAL_FORCE_REGION: bool
37+
client_id: str
38+
client_credential: str | dict[str, Any] | None
39+
client_claims: Mapping[str, Any] | None
40+
http_client: ThrottledHttpClient
41+
app_name: str | None
42+
app_version: str | None
43+
authority: Authority
44+
token_cache: TokenCache
45+
client: Client
46+
authority_groups: dict[str, list[set[str]]]
47+
def __init__(
48+
self,
49+
client_id: str,
50+
client_credential: str | dict[str, Any] | None = None,
51+
authority: str | AuthorityBuilder | None = None,
52+
validate_authority: bool = True,
53+
token_cache: TokenCache | None = None,
54+
http_client: _HttpClientLike | None = None,
55+
verify: bool | str = True,
56+
proxies: Mapping[str, str] | None = None,
57+
timeout: float | tuple[float, float] | tuple[float, None] | None = None,
58+
client_claims: Mapping[str, Any] | None = None,
59+
app_name: str | None = None,
60+
app_version: str | None = None,
61+
client_capabilities: list[str] | None = None,
62+
azure_region: str | bool | None = None,
63+
exclude_scopes: list[str] | None = None,
64+
http_cache: MutableMapping[str, Any] | None = None,
65+
instance_discovery: bool | None = None,
66+
allow_broker: bool | None = None,
67+
enable_pii_log: bool | None = None,
68+
oidc_authority: str | None = None,
69+
) -> None: ...
70+
def is_pop_supported(self) -> bool: ...
71+
def initiate_auth_code_flow(
72+
self,
73+
scopes: list[str],
74+
redirect_uri: str | None = None,
75+
state: str | None = None,
76+
prompt: str | None = None,
77+
login_hint: str | None = None,
78+
domain_hint: str | None = None,
79+
claims_challenge: str | None = None,
80+
max_age: int | None = None,
81+
response_mode: str | None = None,
82+
) -> dict[str, Any]: ...
83+
@deprecated("Change your get_authorization_request_url() to initiate_auth_code_flow()")
84+
def get_authorization_request_url(
85+
self,
86+
scopes: list[str],
87+
login_hint: str | None = None,
88+
state: str | None = None,
89+
redirect_uri: str | None = None,
90+
response_type: str = "code",
91+
prompt: str | None = None,
92+
nonce: str | None = None,
93+
domain_hint: str | None = None,
94+
claims_challenge: str | None = None,
95+
**kwargs: Any,
96+
) -> str: ...
97+
def acquire_token_by_auth_code_flow(
98+
self, auth_code_flow: dict[str, Any], auth_response: dict[str, Any], scopes: list[str] | None = None, **kwargs: Any
99+
) -> dict[str, Any]: ...
100+
@deprecated("Change your acquire_token_by_authorization_code() to acquire_token_by_auth_code_flow()")
101+
def acquire_token_by_authorization_code(
102+
self,
103+
code: str,
104+
scopes: list[str],
105+
redirect_uri: str | None = None,
106+
nonce: str | None = None,
107+
claims_challenge: str | None = None,
108+
forwarded_client_claims: str | None = None,
109+
**kwargs: Any,
110+
) -> dict[str, Any]: ...
111+
def get_accounts(self, username: str | None = None) -> list[dict[str, Any]]: ...
112+
def remove_account(self, account: Mapping[str, Any]) -> None: ...
113+
def acquire_token_silent(
114+
self,
115+
scopes: list[str],
116+
account: Mapping[str, Any] | None,
117+
authority: str | None = None,
118+
force_refresh: bool | None = False,
119+
claims_challenge: str | None = None,
120+
forwarded_client_claims: str | None = None,
121+
auth_scheme: PopAuthScheme | None = None,
122+
**kwargs: Any,
123+
) -> dict[str, Any] | None: ...
124+
def acquire_token_silent_with_error(
125+
self,
126+
scopes: list[str],
127+
account: Mapping[str, Any] | None,
128+
authority: str | None = None,
129+
force_refresh: bool | None = False,
130+
claims_challenge: str | None = None,
131+
forwarded_client_claims: str | None = None,
132+
auth_scheme: PopAuthScheme | None = None,
133+
**kwargs: Any,
134+
) -> dict[str, Any] | None: ...
135+
def acquire_token_by_refresh_token(self, refresh_token: str, scopes: list[str], **kwargs: Any) -> dict[str, Any]: ...
136+
def acquire_token_by_username_password(
137+
self,
138+
username: str,
139+
password: str,
140+
scopes: list[str],
141+
claims_challenge: str | None = None,
142+
auth_scheme: PopAuthScheme | None = None,
143+
**kwargs: Any,
144+
) -> dict[str, Any]: ...
145+
146+
class PublicClientApplication(ClientApplication):
147+
DEVICE_FLOW_CORRELATION_ID: Final = "_correlation_id"
148+
CONSOLE_WINDOW_HANDLE: Final[object]
149+
def __init__(
150+
self,
151+
client_id: str,
152+
client_credential: None = None,
153+
*,
154+
enable_broker_on_windows: bool | None = None,
155+
enable_broker_on_mac: bool | None = None,
156+
enable_broker_on_linux: bool | None = None,
157+
enable_broker_on_wsl: bool | None = None,
158+
authority: str | AuthorityBuilder | None = None,
159+
validate_authority: bool = True,
160+
token_cache: TokenCache | None = None,
161+
http_client: _HttpClientLike | None = None,
162+
verify: bool | str = True,
163+
proxies: Mapping[str, str] | None = None,
164+
timeout: float | tuple[float, float] | tuple[float, None] | None = None,
165+
client_claims: Mapping[str, Any] | None = None,
166+
app_name: str | None = None,
167+
app_version: str | None = None,
168+
client_capabilities: list[str] | None = None,
169+
azure_region: str | bool | None = None,
170+
exclude_scopes: list[str] | None = None,
171+
http_cache: MutableMapping[str, Any] | None = None,
172+
instance_discovery: bool | None = None,
173+
allow_broker: bool | None = None,
174+
enable_pii_log: bool | None = None,
175+
oidc_authority: str | None = None,
176+
) -> None: ...
177+
def acquire_token_interactive(
178+
self,
179+
scopes: list[str],
180+
prompt: str | None = None,
181+
login_hint: str | None = None,
182+
domain_hint: str | None = None,
183+
claims_challenge: str | None = None,
184+
timeout: float | None = None,
185+
port: int | None = None,
186+
extra_scopes_to_consent: list[str] | None = None,
187+
max_age: int | None = None,
188+
parent_window_handle: object | None = None,
189+
on_before_launching_ui: _OnBeforeLaunchingUI | None = None,
190+
auth_scheme: PopAuthScheme | None = None,
191+
**kwargs: Any,
192+
) -> dict[str, Any]: ...
193+
def initiate_device_flow(
194+
self, scopes: list[str] | None = None, *, claims_challenge: str | None = None, **kwargs: Any
195+
) -> dict[str, Any]: ...
196+
def acquire_token_by_device_flow(
197+
self, flow: dict[str, Any], claims_challenge: str | None = None, **kwargs: Any
198+
) -> dict[str, Any]: ...
199+
@deprecated(
200+
"This API has been deprecated for public client flows, please use a more secure flow. "
201+
"See https://aka.ms/msal-ropc-migration for migration guidance"
202+
)
203+
def acquire_token_by_username_password(
204+
self,
205+
username: str,
206+
password: str,
207+
scopes: list[str],
208+
claims_challenge: str | None = None,
209+
auth_scheme: PopAuthScheme | None = None,
210+
**kwargs: Any,
211+
) -> dict[str, Any]: ...
212+
213+
class ConfidentialClientApplication(ClientApplication):
214+
def acquire_token_for_client(
215+
self,
216+
scopes: list[str],
217+
claims_challenge: str | None = None,
218+
fmi_path: str | None = None,
219+
forwarded_client_claims: str | None = None,
220+
**kwargs: Any,
221+
) -> dict[str, Any]: ...
222+
def remove_tokens_for_client(self) -> None: ...
223+
def acquire_token_on_behalf_of(
224+
self,
225+
user_assertion: str,
226+
scopes: list[str],
227+
claims_challenge: str | None = None,
228+
forwarded_client_claims: str | None = None,
229+
**kwargs: Any,
230+
) -> dict[str, Any]: ...
231+
def acquire_token_by_user_federated_identity_credential(
232+
self,
233+
scopes: list[str],
234+
assertion: str,
235+
username: str | None = None,
236+
user_object_id: str | None = None,
237+
claims_challenge: str | None = None,
238+
forwarded_client_claims: str | None = None,
239+
**kwargs: Any,
240+
) -> dict[str, Any]: ...

‎stubs/msal/msal/auth_scheme.pyi‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Final
2+
3+
class PopAuthScheme:
4+
HTTP_GET: Final = "GET"
5+
HTTP_POST: Final = "POST"
6+
HTTP_PUT: Final = "PUT"
7+
HTTP_DELETE: Final = "DELETE"
8+
HTTP_PATCH: Final = "PATCH"
9+
def __init__(self, http_method: str | None = None, url: str | None = None, nonce: str | None = None) -> None: ...

‎stubs/msal/msal/authority.pyi‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from logging import Logger
2+
from typing import Any
3+
from urllib.parse import ParseResult
4+
5+
from .oauth2cli.http import _HttpClientLike
6+
7+
logger: Logger
8+
AZURE_US_GOVERNMENT: str
9+
DEPRECATED_AZURE_CHINA: str
10+
AZURE_PUBLIC: str
11+
AZURE_GOV_FR: str
12+
AZURE_GOV_DE: str
13+
AZURE_GOV_SG: str
14+
WORLD_WIDE: str
15+
WELL_KNOWN_AUTHORITY_HOSTS: frozenset[str]
16+
WELL_KNOWN_B2C_HOSTS: list[str]
17+
18+
class AuthorityBuilder:
19+
def __init__(self, instance: str, tenant: str) -> None: ...
20+
21+
class Authority:
22+
instance: str
23+
tenant: str
24+
is_adfs: bool
25+
authorization_endpoint: str
26+
token_endpoint: str
27+
device_authorization_endpoint: str | None
28+
def __init__(
29+
self,
30+
authority_url: str | AuthorityBuilder | None,
31+
http_client: _HttpClientLike,
32+
validate_authority: bool = True,
33+
instance_discovery: bool | str | None = None,
34+
oidc_authority_url: str | None = None,
35+
) -> None: ...
36+
def user_realm_discovery(self, username: str, correlation_id: str | None = None, response=None) -> dict[str, Any]: ...
37+
def has_valid_issuer(self) -> bool: ...
38+
39+
def canonicalize(authority_or_auth_endpoint: str) -> tuple[ParseResult, str, str]: ...
40+
def tenant_discovery(tenant_discovery_endpoint: str, http_client: _HttpClientLike, **kwargs) -> dict[str, Any]: ...

‎stubs/msal/msal/broker.pyi‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from logging import Logger
2+
3+
logger: Logger
4+
5+
class RedirectUriError(ValueError): ...
6+
class TokenTypeError(ValueError): ...

‎stubs/msal/msal/cloudshell.pyi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from logging import Logger
2+
3+
logger: Logger

‎stubs/msal/msal/exceptions.pyi‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class MsalError(Exception):
2+
msg: str
3+
4+
class MsalServiceError(MsalError):
5+
msg: str
6+
def __init__(self, *args: object, error: str | None, error_description: str | None) -> None: ...

0 commit comments

Comments
 (0)