|
23 | 23 | ) |
24 | 24 | from ..errorcode import ( |
25 | 25 | ER_IDP_CONNECTION_ERROR, |
| 26 | + ER_INVALID_VALUE, |
26 | 27 | ER_NO_HOSTNAME_FOUND, |
27 | 28 | ER_UNABLE_TO_OPEN_BROWSER, |
28 | 29 | ) |
|
32 | 33 | EXTERNAL_BROWSER_AUTHENTICATOR, |
33 | 34 | PYTHON_CONNECTOR_USER_AGENT, |
34 | 35 | ) |
| 36 | +from ..url_util import is_valid_url |
35 | 37 | from . import Auth |
36 | 38 | from .by_plugin import AuthByPlugin, AuthType |
37 | 39 |
|
@@ -131,18 +133,29 @@ def prepare( |
131 | 133 | socket_connection.listen(0) # no backlog |
132 | 134 | callback_port = socket_connection.getsockname()[1] |
133 | 135 |
|
| 136 | + logger.debug("step 1: query GS to obtain SSO url") |
| 137 | + sso_url = self._get_sso_url( |
| 138 | + conn, authenticator, service_name, account, callback_port, user |
| 139 | + ) |
| 140 | + |
| 141 | + logger.debug("Validate SSO URL") |
| 142 | + if not is_valid_url(sso_url): |
| 143 | + self._handle_failure( |
| 144 | + conn=conn, |
| 145 | + ret={ |
| 146 | + "code": ER_INVALID_VALUE, |
| 147 | + "message": (f"The SSO URL provided {sso_url} is invalid"), |
| 148 | + }, |
| 149 | + ) |
| 150 | + return |
| 151 | + |
134 | 152 | print( |
135 | 153 | "Initiating login request with your identity provider. A " |
136 | 154 | "browser window should have opened for you to complete the " |
137 | 155 | "login. If you can't see it, check existing browser windows, " |
138 | 156 | "or your OS settings. Press CTRL+C to abort and try again..." |
139 | 157 | ) |
140 | 158 |
|
141 | | - logger.debug("step 1: query GS to obtain SSO url") |
142 | | - sso_url = self._get_sso_url( |
143 | | - conn, authenticator, service_name, account, callback_port, user |
144 | | - ) |
145 | | - |
146 | 159 | logger.debug("step 2: open a browser") |
147 | 160 | print(f"Going to open: {sso_url} to authenticate...") |
148 | 161 | if not self._webbrowser.open_new(sso_url): |
|
0 commit comments