Repository: burnash/gspread (language: python)

Issue:
gspread depends on google-auth>2.4.0 but only specifies google-auth>=1.12.0
**Describe the bug**
I have gspread installed against version 1.35.0 of google-auth which is within the constraints currently specified by `pyproject.toml`  (`google-auth>=1.12.0`) and get the following error upon `import gspread`:

`ModuleNotFoundError: No module named 'google.auth.api_key'`.

Looks like this module [only came into existence in google-auth v2.4.0](https://github.com/googleapis/google-auth-library-python/commit/3b15092b3461278400e4683060f64a96d50587c4#diff-4abb41958447ee7c433a05ab8f3d736e63dd5b38d7c64ddd7142c7c69cf194db) so that's the constraint that should be actually specified


**To Reproduce**
Steps to reproduce the behavior:
1. Install gspread alongside any version of google-auth less than 2.4.0
2. Import gspread
3. Observe `ModuleNotFoundError: No module named 'google.auth.api_key'`.




Discussion / hints:
Hi, I'm sorry about this issue ! I did not notice that the `api_key` does not exists in newer version :disappointed: 

I will have a look and see how we can solve this.
I check the dependencies, this going to be annoying to solve :disappointed: 

- We introduced a breaking-change when adding the API Key authentication

In order to solve it properly, I suggest, @alifeee  let me know if you think of something better

1. add a new warning on the auth method `api_key()` that it's going to move to version 7.0.0
2. release version 6.1.1 to let everyone get the warning
3. wait for _some time_ (I believe a couple of weeks at least ? ) for everyone to adapt
4. remove the auth method `api_key()` :cry: 
5. release version 6.2.0 -> auth method `api_key()` does not exists anymore
6. add it back
7. bump dependency to at least version 2.4.0 for `google_auth`
8. release version v7.0.0

this way anyone with a dependency on `google_auth` < 2.4.0 can use gspread-6.2.2
Anyone else not blocked by this version can benefit of the new auth method.

Sounds like a good plan to me. My personal solution was to upgrade dependencies but it was a complex web requiring a lot of updates and it would have been nice to have an option to still use gspread

Fix patch:
diff --git a/gspread/auth.py b/gspread/auth.py
index c46a86671..8e3b63b09 100644
--- a/gspread/auth.py
+++ b/gspread/auth.py
@@ -11,8 +11,14 @@
 from pathlib import Path
 from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Tuple, Union
 
-from google.auth.api_key import Credentials as APIKeyCredentials
 from google.auth.credentials import Credentials
+
+try:
+    from google.auth.api_key import Credentials as APIKeyCredentials
+
+    GOOGLE_AUTH_API_KEY_AVAILABLE = True
+except ImportError:
+    GOOGLE_AUTH_API_KEY_AVAILABLE = False
 from google.oauth2.credentials import Credentials as OAuthCredentials
 from google.oauth2.service_account import Credentials as SACredentials
 from google_auth_oauthlib.flow import InstalledAppFlow
@@ -379,5 +385,10 @@ def api_key(token: str, http_client: HTTPClientType = HTTPClient) -> Client:
     :rtype: :class:`gspread.client.Client`
 
     """
+    if GOOGLE_AUTH_API_KEY_AVAILABLE is False:
+        raise NotImplementedError(
+            "api_key is only available with package google.auth>=2.4.0."
+            'Install it with "pip install google-auth>=2.4.0".'
+        )
     creds = APIKeyCredentials(token)
     return Client(auth=creds, http_client=http_client)


Test patch:
diff --git a/test-requirements.txt b/test-requirements.txt
index f9ccfd0d5..ec7d225ce 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,5 +1,5 @@
-google-auth==2.15.0
-google-auth-oauthlib>=0.8.0
+google-auth==1.12.0
+google-auth-oauthlib==0.4.1
 vcrpy
 pytest
 pytest-vcr