|
2 | 2 | import functools |
3 | 3 | import logging |
4 | 4 | import time |
5 | | -from typing import List # Needed in Python 3.7 & 3.8 |
| 5 | +from typing import List, Optional # Needed in Python 3.7 & 3.8 |
6 | 6 |
|
7 | 7 | import requests |
8 | 8 | import msal |
@@ -97,9 +97,14 @@ def _save_user_into_session(self, id_token_claims): |
97 | 97 | self._session[self._USER] = id_token_claims |
98 | 98 |
|
99 | 99 | def log_in( |
100 | | - self, scopes=None, redirect_uri=None, state=None, prompt=None, |
101 | | - next_link=None, |
102 | | - ): |
| 100 | + self, |
| 101 | + *, |
| 102 | + scopes: Optional[List[str]] = None, |
| 103 | + redirect_uri: Optional[str] = None, |
| 104 | + state: Optional[str] = None, |
| 105 | + prompt: Optional[str] = None, |
| 106 | + next_link: Optional[str] = None, |
| 107 | + ) -> dict: |
103 | 108 | """This is the first leg of the authentication/authorization. |
104 | 109 |
|
105 | 110 | :param list scopes: |
@@ -162,7 +167,7 @@ def log_in( |
162 | 167 | "user_code": flow["user_code"], |
163 | 168 | } |
164 | 169 |
|
165 | | - def complete_log_in(self, auth_response=None): |
| 170 | + def complete_log_in(self, auth_response: Optional[dict] = None) -> dict: |
166 | 171 | """This is the second leg of the authentication/authorization. |
167 | 172 |
|
168 | 173 | It is used inside your redirect_uri controller. |
@@ -356,15 +361,15 @@ def __init__( |
356 | 361 | client_id: str, |
357 | 362 | *, |
358 | 363 | client_credential=None, |
359 | | - oidc_authority: str=None, |
360 | | - authority: str=None, |
361 | | - redirect_uri: str=None, |
| 364 | + oidc_authority: Optional[str] = None, |
| 365 | + authority: Optional[str] = None, |
| 366 | + redirect_uri: Optional[str] = None, |
362 | 367 | # We end up accepting Microsoft Entra ID B2C parameters rather than generic urls |
363 | 368 | # because it is troublesome to build those urls in settings.py or templates |
364 | | - b2c_tenant_name: str=None, |
365 | | - b2c_signup_signin_user_flow: str=None, |
366 | | - b2c_edit_profile_user_flow: str=None, |
367 | | - b2c_reset_password_user_flow: str=None, |
| 369 | + b2c_tenant_name: Optional[str] = None, |
| 370 | + b2c_signup_signin_user_flow: Optional[str] = None, |
| 371 | + b2c_edit_profile_user_flow: Optional[str] = None, |
| 372 | + b2c_reset_password_user_flow: Optional[str] = None, |
368 | 373 | ): |
369 | 374 | """Create an identity helper for a web application. |
370 | 375 |
|
@@ -419,8 +424,9 @@ def __init__( |
419 | 424 | self._client_id = client_id |
420 | 425 | self._client_credential = client_credential |
421 | 426 | self._redirect_uri = redirect_uri |
422 | | - self._http_cache = {} # All subsequent Auth instances will share this |
| 427 | + self._http_cache: dict = {} # All subsequent Auth instances will share this |
423 | 428 |
|
| 429 | + self._authority: Optional[str] = None # It makes mypy happy |
424 | 430 | # Note: We do not use overload, because we want to allow the caller to |
425 | 431 | # have only one code path that relay in all the optional parameters. |
426 | 432 | if b2c_tenant_name and b2c_signup_signin_user_flow: |
@@ -467,7 +473,7 @@ def _get_configuration_error(self): |
467 | 473 | (2.3) the B2C_TENANT_NAME and SIGNUPSIGNIN_USER_FLOW pair? |
468 | 474 | """ |
469 | 475 |
|
470 | | - def _build_auth(self, session): |
| 476 | + def _build_auth(self, session) -> Auth: |
471 | 477 | return Auth( |
472 | 478 | session=session, |
473 | 479 | oidc_authority=self._oidc_authority, |
@@ -523,7 +529,9 @@ def _get_reset_password_url(self): |
523 | 529 | )["auth_uri"] if self._reset_password_auth and self._redirect_uri else None |
524 | 530 |
|
525 | 531 | @abstractmethod |
526 | | - def _render_auth_error(error, *, error_description=None): |
| 532 | + def _render_auth_error( |
| 533 | + error, *, error_description=None, |
| 534 | + ): # Return value could be a str, or a framework-specific Response object |
527 | 535 | # The default auth_error.html template may or may not escape. |
528 | 536 | # If a web framework does not escape it by default, a subclass shall escape it. |
529 | 537 | pass |
0 commit comments