Skip to content

Commit 4025dbf

Browse files
committed
Refactor to remove old auth.console_flow references
1 parent 9374013 commit 4025dbf

File tree

1 file changed

+3
-36
lines changed

1 file changed

+3
-36
lines changed

gspread/auth.py

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import json
1010
import os
1111
from pathlib import Path
12-
from typing import Any, Dict, Iterable, Mapping, Optional, Protocol, Tuple, Union
12+
from typing import Any, Dict, Iterable, Mapping, Optional, Tuple, Union
1313

1414
from google.auth.credentials import Credentials
1515

@@ -87,14 +87,6 @@ def authorize(
8787
return Client(auth=credentials, session=session, http_client=http_client)
8888

8989

90-
class FlowCallable(Protocol):
91-
"""Protocol for OAuth flow callables."""
92-
93-
def __call__(
94-
self, client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
95-
) -> OAuthCredentials: ...
96-
97-
9890
def local_server_flow(
9991
client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
10092
) -> OAuthCredentials:
@@ -103,9 +95,6 @@ def local_server_flow(
10395
Creates an OAuth flow and runs `google_auth_oauthlib.flow.InstalledAppFlow.run_local_server <https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_local_server>`_.
10496
This will start a local web server and open the authorization URL in
10597
the user's browser.
106-
107-
Pass this function to ``flow`` parameter of :meth:`~gspread.oauth` to run
108-
a local server flow.
10998
"""
11099
flow = InstalledAppFlow.from_client_config(client_config, scopes)
111100
return flow.run_local_server(port=port)
@@ -132,7 +121,6 @@ def store_credentials(
132121

133122
def oauth(
134123
scopes: Iterable[str] = DEFAULT_SCOPES,
135-
flow: FlowCallable = local_server_flow,
136124
credentials_filename: Union[str, Path] = DEFAULT_CREDENTIALS_FILENAME,
137125
authorized_user_filename: Union[str, Path] = DEFAULT_AUTHORIZED_USER_FILENAME,
138126
http_client: HTTPClientType = HTTPClient,
@@ -144,14 +132,6 @@ def oauth(
144132
145133
gc = gspread.oauth()
146134
147-
Another option is to run a console strategy. This way, the user is
148-
instructed to open the authorization URL in their browser. Once the
149-
authorization is complete, the user must then copy & paste the
150-
authorization code into the application::
151-
152-
gc = gspread.oauth(flow=gspread.auth.console_flow)
153-
154-
155135
``scopes`` parameter defaults to read/write scope available in
156136
``gspread.auth.DEFAULT_SCOPES``. It's read/write for Sheets
157137
and Drive API::
@@ -179,8 +159,6 @@ def oauth(
179159
)
180160
181161
:param list scopes: The scopes used to obtain authorization.
182-
:param function flow: OAuth flow to use for authentication.
183-
Defaults to :meth:`~gspread.auth.local_server_flow`
184162
:param str credentials_filename: Filepath (including name) pointing to a
185163
credentials `.json` file.
186164
Defaults to DEFAULT_CREDENTIALS_FILENAME:
@@ -207,7 +185,7 @@ def oauth(
207185
if not isinstance(creds, Credentials):
208186
with open(credentials_filename) as json_file:
209187
client_config = json.load(json_file)
210-
creds = flow(client_config=client_config, scopes=scopes)
188+
creds = local_server_flow(client_config=client_config, scopes=scopes)
211189
store_credentials(creds, filename=authorized_user_filename)
212190

213191
return Client(auth=creds, http_client=http_client)
@@ -217,7 +195,6 @@ def oauth_from_dict(
217195
credentials: Optional[Mapping[str, Any]] = None,
218196
authorized_user_info: Optional[Mapping[str, Any]] = None,
219197
scopes: Iterable[str] = DEFAULT_SCOPES,
220-
flow: FlowCallable = local_server_flow,
221198
http_client: HTTPClientType = HTTPClient,
222199
) -> Tuple[Client, Dict[str, Any]]:
223200
r"""Authenticate with OAuth Client ID.
@@ -227,14 +204,6 @@ def oauth_from_dict(
227204
228205
gc = gspread.oauth_from_dict()
229206
230-
Another option is to run a console strategy. This way, the user is
231-
instructed to open the authorization URL in their browser. Once the
232-
authorization is complete, the user must then copy & paste the
233-
authorization code into the application::
234-
235-
gc = gspread.oauth_from_dict(flow=gspread.auth.console_flow)
236-
237-
238207
``scopes`` parameter defaults to read/write scope available in
239208
``gspread.auth.DEFAULT_SCOPES``. It's read/write for Sheets
240209
and Drive API::
@@ -272,8 +241,6 @@ def oauth_from_dict(
272241
:param dict authorized_user_info: The authenticated user
273242
if already authenticated.
274243
:param list scopes: The scopes used to obtain authorization.
275-
:param function flow: OAuth flow to use for authentication.
276-
Defaults to :meth:`~gspread.auth.local_server_flow`
277244
:type http_client: :class:`gspread.http_client.HTTPClient`
278245
:param http_client: A factory function that returns a client class.
279246
Defaults to :class:`gspread.http_client.HTTPClient` (but could also use
@@ -286,7 +253,7 @@ def oauth_from_dict(
286253
creds = OAuthCredentials.from_authorized_user_info(authorized_user_info, scopes)
287254

288255
if not creds and credentials is not None:
289-
creds = flow(client_config=credentials, scopes=scopes)
256+
creds = local_server_flow(client_config=credentials, scopes=scopes)
290257

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

0 commit comments

Comments
 (0)