Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/api key auth version #1463

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion gspread/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down