@@ -87,7 +87,9 @@ class Flow(object):
8787 https://console.developers.google.com/apis/credentials
8888 """
8989
90- def __init__ (self , oauth2session , client_type , client_config ):
90+ def __init__ (
91+ self , oauth2session , client_type , client_config ,
92+ redirect_uri = None ):
9193 """
9294 Args:
9395 oauth2session (requests_oauthlib.OAuth2Session):
@@ -96,6 +98,9 @@ def __init__(self, oauth2session, client_type, client_config):
9698 ``installed``.
9799 client_config (Mapping[str, Any]): The client
98100 configuration in the Google `client secrets`_ format.
101+ redirect_uri (str): The OAuth 2.0 redirect URI if known at flow
102+ creation time. Otherwise, it will need to be set using
103+ :attr:`redirect_uri`.
99104
100105 .. _client secrets:
101106 https://developers.google.com/api-client-library/python/guide
@@ -107,6 +112,7 @@ def __init__(self, oauth2session, client_type, client_config):
107112 """Mapping[str, Any]: The OAuth 2.0 client configuration."""
108113 self .oauth2session = oauth2session
109114 """requests_oauthlib.OAuth2Session: The OAuth 2.0 session."""
115+ self .redirect_uri = redirect_uri
110116
111117 @classmethod
112118 def from_client_config (cls , client_config , scopes , ** kwargs ):
@@ -200,9 +206,9 @@ def authorization_url(self, **kwargs):
200206 :class:`Flow` instance to obtain the token, you will need to
201207 specify the ``state`` when constructing the :class:`Flow`.
202208 """
209+ kwargs .setdefault ('access_type' , 'offline' )
203210 url , state = self .oauth2session .authorization_url (
204- self .client_config ['auth_uri' ],
205- access_type = 'offline' , ** kwargs )
211+ self .client_config ['auth_uri' ], ** kwargs )
206212
207213 return url , state
208214
@@ -229,10 +235,9 @@ def fetch_token(self, **kwargs):
229235 :meth:`credentials` to obtain a
230236 :class:`~google.auth.credentials.Credentials` instance.
231237 """
238+ kwargs .setdefault ('client_secret' , self .client_config ['client_secret' ])
232239 return self .oauth2session .fetch_token (
233- self .client_config ['token_uri' ],
234- client_secret = self .client_config ['client_secret' ],
235- ** kwargs )
240+ self .client_config ['token_uri' ], ** kwargs )
236241
237242 @property
238243 def credentials (self ):
0 commit comments