Skip to content

Commit

Permalink
Merge pull request #1397 from burnash/fix/oauth-flow-type-hints
Browse files Browse the repository at this point in the history
Fix oauth flow typo
  • Loading branch information
alifeee committed Jan 31, 2024
2 parents 3c02a2c + 0fef655 commit bed3293
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions gspread/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import json
import os
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Mapping, Optional, Tuple, Union
from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Tuple, Union

from google.auth.credentials import Credentials
from google.oauth2.credentials import Credentials as OAuthCredentials
Expand Down Expand Up @@ -80,6 +80,15 @@ def authorize(
return Client(auth=credentials, http_client=http_client, session=session)


class FlowCallable(Protocol):
"""Protocol for OAuth flow callables."""

def __call__(
self, client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
) -> Credentials:
...


def local_server_flow(
client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
) -> Credentials:
Expand Down Expand Up @@ -117,7 +126,7 @@ def store_credentials(

def oauth(
scopes: Iterable[str] = DEFAULT_SCOPES,
flow: Callable[..., Credentials] = local_server_flow,
flow: FlowCallable = local_server_flow,
credentials_filename: Union[str, Path] = DEFAULT_CREDENTIALS_FILENAME,
authorized_user_filename: Union[str, Path] = DEFAULT_AUTHORIZED_USER_FILENAME,
http_client: HTTPClientType = HTTPClient,
Expand Down Expand Up @@ -202,7 +211,7 @@ def oauth_from_dict(
credentials: Optional[Mapping[str, Any]] = None,
authorized_user_info: Optional[Mapping[str, Any]] = None,
scopes: Iterable[str] = DEFAULT_SCOPES,
flow: Callable[..., Credentials] = local_server_flow,
flow: FlowCallable = local_server_flow,
http_client: HTTPClientType = HTTPClient,
) -> Tuple[Client, Dict[str, Any]]:
r"""Authenticate with OAuth Client ID.
Expand Down Expand Up @@ -272,7 +281,7 @@ def oauth_from_dict(
creds = OAuthCredentials.from_authorized_user_info(authorized_user_info, scopes)

if not creds and credentials is not None:
creds = flow(client_config=credentials, scopres=scopes)
creds = flow(client_config=credentials, scopes=scopes)

client = Client(auth=creds, http_client=http_client)

Expand Down

0 comments on commit bed3293

Please sign in to comment.