def DoInstalledAppBrowserFlow(launch_browser, scopes, client_id_file=None, client_id=None, client_secret=None): """Launches a browser to get credentials. Args: launch_browser: bool, True to do a browser flow, false to allow the user to type in a token from a different browser. scopes: [str], The list of scopes to authorize. client_id_file: str, The path to a file containing the client id and secret to use for the flow. If None, the default client id for the Cloud SDK is used. client_id: str, An alternate client id to use. This is ignored if you give a client id file. If None, the default client id for the Cloud SDK is used. client_secret: str, The secret to go along with client_id if specified. Returns: The clients obtained from the web flow. """ try: if client_id_file: client_type = GetClientSecretsType(client_id_file) if client_type != clientsecrets.TYPE_INSTALLED: raise InvalidClientSecretsError( 'Only client IDs of type \'%s\' are allowed, but encountered ' 'type \'%s\'' % (clientsecrets.TYPE_INSTALLED, client_type)) webflow = client.flow_from_clientsecrets(filename=client_id_file, scope=scopes) return c_store.RunWebFlow(webflow, launch_browser=launch_browser) else: return c_store.AcquireFromWebFlow(launch_browser=launch_browser, scopes=scopes, client_id=client_id, client_secret=client_secret) except c_store.FlowError: msg = 'There was a problem with web authentication.' if launch_browser: msg += ' Try running again with --no-launch-browser.' log.error(msg) raise
def DoInstalledAppBrowserFlow(launch_browser, scopes, client_id_file=None, client_id=None, client_secret=None): """Launches a browser to get credentials. Args: launch_browser: bool, True to do a browser flow, false to allow the user to type in a token from a different browser. scopes: [str], The list of scopes to authorize. client_id_file: str, The path to a file containing the client id and secret to use for the flow. If None, the default client id for the Cloud SDK is used. client_id: str, An alternate client id to use. This is ignored if you give a client id file. If None, the default client id for the Cloud SDK is used. client_secret: str, The secret to go along with client_id if specified. Returns: The clients obtained from the web flow. """ try: if client_id_file: AssertClientSecretIsInstalledType(client_id_file) webflow = client.flow_from_clientsecrets(filename=client_id_file, scope=scopes) return c_store.RunWebFlow(webflow, launch_browser=launch_browser) else: return c_store.AcquireFromWebFlow(launch_browser=launch_browser, scopes=scopes, client_id=client_id, client_secret=client_secret) except c_store.FlowError as e: if c_store.IsContextAwareAccessDeniedError(e): msg = c_store.CONTEXT_AWARE_ACCESS_HELP_MSG else: msg = 'There was a problem with web authentication.' if launch_browser: msg += ' Try running again with --no-launch-browser.' log.error(msg) raise