Repository: PrefectHQ/prefect

Issue:
`auth login` CLI check needs token required query
## Description
`prefect auth login` runs a graphql query to verify the token provided is valid. The current query is `query { hello }` and this query does not require authentication. This query needs to be updated to one which requires authentication (which is every other query, let's just find the smallest one)


## Expected Behavior
If the token is invalid it should elevate an error to the user


## Reproduction
Query the API with `query { hello }` without a token and it will still work.


## Environment
N/A



Discussion:

Resolving patch:
diff --git a/src/prefect/cli/auth.py b/src/prefect/cli/auth.py
--- a/src/prefect/cli/auth.py
+++ b/src/prefect/cli/auth.py
@@ -37,10 +37,11 @@ def login(token):
         --token, -t         TEXT    A Prefect Cloud api token  [required]
     """
 
-    if config.cloud.auth_token:
+    if config.cloud.get("auth_token"):
         click.confirm(
             "Prefect Cloud API token already set in config. Do you want to override?",
             default=True,
+            abort=True,
         )
 
     client = Client()
@@ -48,7 +49,7 @@ def login(token):
 
     # Verify login obtained a valid api token
     try:
-        client.graphql(query={"query": "hello"})
+        client.graphql(query={"query": {"tenant": "id"}})
     except AuthorizationError:
         click.secho(
             "Error attempting to use Prefect API token {}".format(token), fg="red"


Test patch:
diff --git a/tests/cli/test_auth.py b/tests/cli/test_auth.py
--- a/tests/cli/test_auth.py
+++ b/tests/cli/test_auth.py
@@ -31,7 +31,7 @@ def test_auth_login(monkeypatch):
         monkeypatch.setattr("prefect.client.Client.local_token_path", f.name)
         post = MagicMock(
             return_value=MagicMock(
-                json=MagicMock(return_value=dict(data=dict(hello="hi")))
+                json=MagicMock(return_value=dict(data=dict(tenant="id")))
             )
         )
         session = MagicMock()
@@ -67,3 +67,46 @@ def test_auth_login_client_error(monkeypatch):
             result = runner.invoke(auth, ["login", "--token", "test"])
             assert result.exit_code == 0
             assert "Error attempting to communicate with Prefect Cloud" in result.output
+
+
+def test_auth_login_confirm(monkeypatch):
+
+    with tempfile.NamedTemporaryFile() as f:
+        monkeypatch.setattr("prefect.client.Client.local_token_path", f.name)
+        post = MagicMock(
+            return_value=MagicMock(
+                json=MagicMock(return_value=dict(data=dict(hello="hi")))
+            )
+        )
+        session = MagicMock()
+        session.return_value.post = post
+        monkeypatch.setattr("requests.Session", session)
+
+        with set_temporary_config(
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        ):
+            runner = CliRunner()
+            result = runner.invoke(auth, ["login", "--token", "test"], input="Y")
+            assert result.exit_code == 0
+            assert "Login successful" in result.output
+
+
+def test_auth_login_not_confirm(monkeypatch):
+
+    with tempfile.NamedTemporaryFile() as f:
+        monkeypatch.setattr("prefect.client.Client.local_token_path", f.name)
+        post = MagicMock(
+            return_value=MagicMock(
+                json=MagicMock(return_value=dict(data=dict(hello="hi")))
+            )
+        )
+        session = MagicMock()
+        session.return_value.post = post
+        monkeypatch.setattr("requests.Session", session)
+
+        with set_temporary_config(
+            {"cloud.graphql": "http://my-cloud.foo", "cloud.auth_token": "secret_token"}
+        ):
+            runner = CliRunner()
+            result = runner.invoke(auth, ["login", "--token", "test"], input="N")
+            assert result.exit_code == 1