def authenticate_user(clear_output: bool = False) -> None:
    """Authenticates on Google Cloud.

    Args:
        clear_output: Optional bool for whether to clear output before
            authenticating. Defaults to false.

    Returns:
        None.

    Raises:
        Exception: if authentication fails.
    """

    # Check for Google Application Default Credentials and run
    # interactive login if the notebook is executed in Colab. In
    # case the notebook is executed in Jupyter notebook or other
    # IPython runtimes, no interactive login is provided, it is
    # assumed that the `GOOGLE_APPLICATION_CREDENTIALS` env var is
    # set or `gcloud auth application-default login` was executed
    # already. For more information on using Application Default Credentials
    # see https://cloud.google.com/docs/authentication/production
    # Attempt to connect to the Quantum Engine API, and use a simulator if unable to connect.
    try:
        from google.colab import auth
    except ImportError:
        print("Not running in a colab kernel. Will use Application Default Credentials.")
        return

    try:
        print("Getting OAuth2 credentials.")
        print("Press enter after entering the verification code.")
        a = auth.authenticate_user(clear_output=clear_output)
        print(a)
        print("Authentication complete.")
    except Exception as exc:
        print(
            "Authentication failed, you may not have permission to access a"
            + " hardware Engine. Use a virtual Engine instead."
        )
        raise exc
Authenticates on Google Cloud.

    Args:
        clear_output: Optional bool for whether to clear output before
            authenticating. Defaults to false.

    Returns:
        None.

    Raises:
        Exception: if authentication fails.
    
cirq-google/cirq_google/engine/qcs_notebook.py