MCPcopy Create free account
hub / github.com/aws/aws-cli / OpenBrowserHandler

Class OpenBrowserHandler

awscli/customizations/sso/utils.py:179–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

177
178
179class OpenBrowserHandler(BaseAuthorizationhandler):
180 def __init__(self, outfile=None, open_browser=None):
181 self._outfile = outfile
182 if open_browser is None:
183 open_browser = webbrowser.open_new_tab
184 self._open_browser = open_browser
185
186 def __call__(
187 self,
188 userCode,
189 verificationUri,
190 verificationUriComplete,
191 cross_device_flag,
192 **kwargs,
193 ):
194 if userCode: # only the device code flow supports different devices
195 opening_msg = (
196 f'Attempting to open your default browser.\n'
197 f'If the browser does not open or '
198 f'you wish to use a different device to authorize this '
199 f'request, open the following URL:\n'
200 f'\n{verificationUri}\n'
201 )
202 else:
203 opening_msg = (
204 f'Attempting to open your default browser. '
205 f'If the browser does not open, open the following URL.\n'
206 f'If you are unable to open the URL on this device, '
207 f'run this command again with the \'{cross_device_flag}\' option.\n'
208 f'\n{verificationUri}\n\n'
209 )
210
211 user_code_msg = f'\nThen enter the code:\n\n{userCode}\n'
212 uni_print(opening_msg, self._outfile)
213 if userCode:
214 uni_print(user_code_msg, self._outfile)
215
216 if self._open_browser:
217 try:
218 return self._open_browser(verificationUriComplete)
219 except Exception:
220 LOG.debug('Failed to open browser:', exc_info=True)
221
222
223class AuthCodeFetcher:

Callers 4

setUpMethod · 0.90
test_call_no_browserMethod · 0.90
_run_mainMethod · 0.90
do_sso_loginFunction · 0.85

Calls

no outgoing calls

Tested by 2

setUpMethod · 0.72
test_call_no_browserMethod · 0.72