From 4fe70b4c27d6b4a26e4648d47edf80e666b8872f Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Thu, 5 Oct 2017 12:09:15 -0300 Subject: [PATCH 1/3] Accept redirect_uri as arg to flow creating classmethods. --- google_auth_oauthlib/flow.py | 9 +++++---- tests/test_flow.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/google_auth_oauthlib/flow.py b/google_auth_oauthlib/flow.py index 6123e59..3da7f4f 100644 --- a/google_auth_oauthlib/flow.py +++ b/google_auth_oauthlib/flow.py @@ -115,7 +115,7 @@ def __init__( self.redirect_uri = redirect_uri @classmethod - def from_client_config(cls, client_config, scopes, **kwargs): + def from_client_config(cls, client_config, scopes, redirect_uri=None, **kwargs): """Creates a :class:`requests_oauthlib.OAuth2Session` from client configuration loaded from a Google-format client secrets file. @@ -150,10 +150,10 @@ def from_client_config(cls, client_config, scopes, **kwargs): google_auth_oauthlib.helpers.session_from_client_config( client_config, scopes, **kwargs)) - return cls(session, client_type, client_config) + return cls(session, client_type, client_config, redirect_uri) @classmethod - def from_client_secrets_file(cls, client_secrets_file, scopes, **kwargs): + def from_client_secrets_file(cls, client_secrets_file, scopes, redirect_uri=None, **kwargs): """Creates a :class:`Flow` instance from a Google client secrets file. Args: @@ -170,7 +170,8 @@ def from_client_secrets_file(cls, client_secrets_file, scopes, **kwargs): with open(client_secrets_file, 'r') as json_file: client_config = json.load(json_file) - return cls.from_client_config(client_config, scopes=scopes, **kwargs) + return cls.from_client_config( + client_config, scopes=scopes, redirect_uri=redirect_uri, **kwargs) @property def redirect_uri(self): diff --git a/tests/test_flow.py b/tests/test_flow.py index 1404636..d68932c 100644 --- a/tests/test_flow.py +++ b/tests/test_flow.py @@ -40,6 +40,15 @@ def test_from_client_secrets_file(self): CLIENT_SECRETS_INFO['web']['client_id']) assert instance.oauth2session.scope == mock.sentinel.scopes + def test_from_client_secrets_file_with_redirect_uri(self): + instance = flow.Flow.from_client_secrets_file( + CLIENT_SECRETS_FILE, scopes=mock.sentinel.scopes, + redirect_uri=mock.sentinel.redirect_uri + ) + assert (instance.redirect_uri == + instance.oauth2session.redirect_uri == + mock.sentinel.redirect_uri) + def test_from_client_config_installed(self): client_config = {'installed': CLIENT_SECRETS_INFO['web']} instance = flow.Flow.from_client_config( @@ -49,6 +58,16 @@ def test_from_client_config_installed(self): client_config['installed']['client_id']) assert instance.oauth2session.scope == mock.sentinel.scopes + def test_from_client_config_with_redirect_uri(self): + client_config = {'installed': CLIENT_SECRETS_INFO['web']} + instance = flow.Flow.from_client_config( + client_config, scopes=mock.sentinel.scopes, + redirect_uri=mock.sentinel.redirect_uri + ) + assert (instance.redirect_uri == + instance.oauth2session.redirect_uri == + mock.sentinel.redirect_uri) + def test_from_client_config_bad_format(self): with pytest.raises(ValueError): flow.Flow.from_client_config({}, scopes=mock.sentinel.scopes) From 6addf731835e53c0a1f932f53169967504cdd9e7 Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Thu, 5 Oct 2017 12:22:16 -0300 Subject: [PATCH 2/3] Attend to lint complaints. --- google_auth_oauthlib/flow.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/google_auth_oauthlib/flow.py b/google_auth_oauthlib/flow.py index 3da7f4f..68c0af6 100644 --- a/google_auth_oauthlib/flow.py +++ b/google_auth_oauthlib/flow.py @@ -115,7 +115,8 @@ def __init__( self.redirect_uri = redirect_uri @classmethod - def from_client_config(cls, client_config, scopes, redirect_uri=None, **kwargs): + def from_client_config( + cls, client_config, scopes, redirect_uri=None, **kwargs): """Creates a :class:`requests_oauthlib.OAuth2Session` from client configuration loaded from a Google-format client secrets file. @@ -153,7 +154,8 @@ def from_client_config(cls, client_config, scopes, redirect_uri=None, **kwargs): return cls(session, client_type, client_config, redirect_uri) @classmethod - def from_client_secrets_file(cls, client_secrets_file, scopes, redirect_uri=None, **kwargs): + def from_client_secrets_file( + cls, client_secrets_file, scopes, redirect_uri=None, **kwargs): """Creates a :class:`Flow` instance from a Google client secrets file. Args: From e29e7a80066a1a370b07664d62f82eb9352ec10a Mon Sep 17 00:00:00 2001 From: Michel Sabchuk Date: Fri, 6 Oct 2017 16:53:15 -0300 Subject: [PATCH 3/3] Get the redirect_uri from kwargs. --- google_auth_oauthlib/flow.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/google_auth_oauthlib/flow.py b/google_auth_oauthlib/flow.py index 68c0af6..b5026e3 100644 --- a/google_auth_oauthlib/flow.py +++ b/google_auth_oauthlib/flow.py @@ -115,8 +115,7 @@ def __init__( self.redirect_uri = redirect_uri @classmethod - def from_client_config( - cls, client_config, scopes, redirect_uri=None, **kwargs): + def from_client_config(cls, client_config, scopes, **kwargs): """Creates a :class:`requests_oauthlib.OAuth2Session` from client configuration loaded from a Google-format client secrets file. @@ -151,11 +150,11 @@ def from_client_config( google_auth_oauthlib.helpers.session_from_client_config( client_config, scopes, **kwargs)) + redirect_uri = kwargs.get('redirect_uri', None) return cls(session, client_type, client_config, redirect_uri) @classmethod - def from_client_secrets_file( - cls, client_secrets_file, scopes, redirect_uri=None, **kwargs): + def from_client_secrets_file(cls, client_secrets_file, scopes, **kwargs): """Creates a :class:`Flow` instance from a Google client secrets file. Args: @@ -172,8 +171,7 @@ def from_client_secrets_file( with open(client_secrets_file, 'r') as json_file: client_config = json.load(json_file) - return cls.from_client_config( - client_config, scopes=scopes, redirect_uri=redirect_uri, **kwargs) + return cls.from_client_config(client_config, scopes=scopes, **kwargs) @property def redirect_uri(self):