|
28 | 28 | from planet_auth.oidc.api_clients.userinfo_api_client import UserinfoApiClient
|
29 | 29 | from planet_auth.oidc.api_clients.token_api_client import TokenApiClient
|
30 | 30 | from planet_auth.oidc.oidc_credential import FileBackedOidcCredential
|
| 31 | +import planet_auth.logging.auth_logger |
| 32 | + |
| 33 | + |
| 34 | +auth_logger = planet_auth.logging.auth_logger.getAuthLogger() |
31 | 35 |
|
32 | 36 |
|
33 | 37 | class OidcAuthClientConfig(AuthClientConfig, ABC):
|
@@ -426,6 +430,44 @@ def login(
|
426 | 430 | **kwargs,
|
427 | 431 | )
|
428 | 432 |
|
| 433 | + def _warn_password_kwarg(self, **kwargs): |
| 434 | + """ |
| 435 | + Helper function for _oidc_flow_login implementations to offer guidance to users |
| 436 | + and developers when options are unnecessary and will be ignored. |
| 437 | + """ |
| 438 | + if "password" in kwargs: |
| 439 | + if kwargs["password"]: |
| 440 | + # Safety check. "password" is a legitimate kwarg for some OAuth flows |
| 441 | + # like Resource Owner Flow. But, it should never be provided to the client |
| 442 | + # of other flows such as Auth Code or Device Code flows. |
| 443 | + # We could simply ignore it in the kwargs, but it's a good opportunity |
| 444 | + # to improve user or developer security practices. |
| 445 | + warning_msg = ( |
| 446 | + "Supplying your password is not a supported option for the current login process. " |
| 447 | + "Protect your password. Do not expose your password unnecessarily." |
| 448 | + ) |
| 449 | + # If we decide we want to not just warn, but halt user interactive |
| 450 | + # clients, uncomment this: |
| 451 | + # if allow_open_browser or allow_tty_prompt: |
| 452 | + # raise AuthCodeAuthClientException(message=warning_msg) |
| 453 | + auth_logger.warning(msg=warning_msg) |
| 454 | + |
| 455 | + def _warn_ignored_kwargs(self, ignore_kws: list, **kwargs): |
| 456 | + """ |
| 457 | + Helper function for _oidc_flow_login implementations to offer guidance to users |
| 458 | + and developers when options are unnecessary and will be ignored. This is mostly |
| 459 | + to steer users away from habitually passing unnecessary arguments. OAuth flows |
| 460 | + behave differently enough that extra data through the generic login() kwargs |
| 461 | + is a problem we can anticipate. |
| 462 | + """ |
| 463 | + for ignore_kw in ignore_kws: |
| 464 | + if ignore_kw in kwargs: |
| 465 | + if kwargs[ignore_kw]: |
| 466 | + auth_logger.debug( |
| 467 | + msg=f'Ignoring "{ignore_kw}" argument to login. ' |
| 468 | + "It is not used for the current login process." |
| 469 | + ) |
| 470 | + |
429 | 471 | @abstractmethod
|
430 | 472 | def _oidc_flow_login(
|
431 | 473 | self,
|
|
0 commit comments