52
52
import hashlib
53
53
import json
54
54
import logging
55
- import warnings
56
55
57
56
try :
58
57
from secrets import SystemRandom
70
69
71
70
72
71
_LOGGER = logging .getLogger (__name__ )
73
- _OOB_REDIRECT_URIS = [
74
- "urn:ietf:wg:oauth:2.0:oob" ,
75
- "urn:ietf:wg:oauth:2.0:oob:auto" ,
76
- "oob" ,
77
- ]
78
72
79
73
80
74
class Flow (object ):
@@ -214,17 +208,8 @@ def redirect_uri(self):
214
208
215
209
@redirect_uri .setter
216
210
def redirect_uri (self , value ):
217
- if value in _OOB_REDIRECT_URIS :
218
- warnings .warn (
219
- "'{}' is an OOB redirect URI. The OAuth out-of-band (OOB) flow is deprecated. "
220
- "New clients will be unable to use this flow starting on Feb 28, 2022. "
221
- "This flow will be deprecated for all clients on Oct 3, 2022. "
222
- "Migrate to an alternative flow. "
223
- "See https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html?m=1#disallowed-oob" .format (
224
- value
225
- ),
226
- DeprecationWarning ,
227
- )
211
+ """The OAuth 2.0 redirect URI. Pass-through to
212
+ ``self.oauth2session.redirect_uri``."""
228
213
self .oauth2session .redirect_uri = value
229
214
230
215
def authorization_url (self , ** kwargs ):
@@ -370,8 +355,6 @@ class InstalledAppFlow(Flow):
370
355
https://github.com/googleapis/google-api-python-client/blob/main/docs/oauth-installed.md
371
356
"""
372
357
373
- _OOB_REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
374
-
375
358
_DEFAULT_AUTH_PROMPT_MESSAGE = (
376
359
"Please visit this URL to authorize this application: {url}"
377
360
)
@@ -385,63 +368,6 @@ class InstalledAppFlow(Flow):
385
368
"The authentication flow has completed. You may close this window."
386
369
)
387
370
388
- def run_console (
389
- self ,
390
- authorization_prompt_message = _DEFAULT_AUTH_PROMPT_MESSAGE ,
391
- authorization_code_message = _DEFAULT_AUTH_CODE_MESSAGE ,
392
- ** kwargs
393
- ):
394
- """Run the flow using the console strategy.
395
-
396
- .. deprecated:: 0.5.0
397
- Use :meth:`run_local_server` instead.
398
-
399
- The OAuth out-of-band (OOB) flow is deprecated. New clients will be unable to
400
- use this flow starting on Feb 28, 2022. This flow will be deprecated
401
- for all clients on Oct 3, 2022. Migrate to an alternative flow.
402
-
403
- See https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html?m=1#disallowed-oob"
404
-
405
- The console strategy instructs the user to open the authorization URL
406
- in their browser. Once the authorization is complete the authorization
407
- server will give the user a code. The user then must copy & paste this
408
- code into the application. The code is then exchanged for a token.
409
-
410
- Args:
411
- authorization_prompt_message (str | None): The message to display to tell
412
- the user to navigate to the authorization URL. If None or empty,
413
- don't display anything.
414
- authorization_code_message (str): The message to display when
415
- prompting the user for the authorization code.
416
- kwargs: Additional keyword arguments passed through to
417
- :meth:`authorization_url`.
418
-
419
- Returns:
420
- google.oauth2.credentials.Credentials: The OAuth 2.0 credentials
421
- for the user.
422
- """
423
- kwargs .setdefault ("prompt" , "consent" )
424
- warnings .warn (
425
- "New clients will be unable to use `InstalledAppFlow.run_console` "
426
- "starting on Feb 28, 2022. All clients will be unable to use this method starting on Oct 3, 2022. "
427
- "Use `InstalledAppFlow.run_local_server` instead. For details on the OOB flow deprecation, "
428
- "see https://developers.googleblog.com/2022/02/making-oauth-flows-safer.html?m=1#disallowed-oob" ,
429
- DeprecationWarning ,
430
- )
431
-
432
- self .redirect_uri = self ._OOB_REDIRECT_URI
433
-
434
- auth_url , _ = self .authorization_url (** kwargs )
435
-
436
- if authorization_prompt_message :
437
- print (authorization_prompt_message .format (url = auth_url ))
438
-
439
- code = input (authorization_code_message )
440
-
441
- self .fetch_token (code = code )
442
-
443
- return self .credentials
444
-
445
371
def run_local_server (
446
372
self ,
447
373
host = "localhost" ,
0 commit comments