-
Notifications
You must be signed in to change notification settings - Fork 83
Allow access_type parameter to be overriden #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,9 @@ class Flow(object): | |
https://console.developers.google.com/apis/credentials | ||
""" | ||
|
||
def __init__(self, oauth2session, client_type, client_config): | ||
def __init__( | ||
self, oauth2session, client_type, client_config, | ||
redirect_uri=None): | ||
""" | ||
Args: | ||
oauth2session (requests_oauthlib.OAuth2Session): | ||
|
@@ -96,6 +98,9 @@ def __init__(self, oauth2session, client_type, client_config): | |
``installed``. | ||
client_config (Mapping[str, Any]): The client | ||
configuration in the Google `client secrets`_ format. | ||
redirect_uri (str): The OAuth 2.0 redirect URI if known at flow | ||
creation time. Otherwise, it will need to be set using | ||
:attr:`redirect_uri`. | ||
|
||
.. _client secrets: | ||
https://developers.google.com/api-client-library/python/guide | ||
|
@@ -107,6 +112,7 @@ def __init__(self, oauth2session, client_type, client_config): | |
"""Mapping[str, Any]: The OAuth 2.0 client configuration.""" | ||
self.oauth2session = oauth2session | ||
"""requests_oauthlib.OAuth2Session: The OAuth 2.0 session.""" | ||
self.redirect_uri = redirect_uri | ||
|
||
@classmethod | ||
def from_client_config(cls, client_config, scopes, **kwargs): | ||
|
@@ -200,9 +206,9 @@ def authorization_url(self, **kwargs): | |
:class:`Flow` instance to obtain the token, you will need to | ||
specify the ``state`` when constructing the :class:`Flow`. | ||
""" | ||
kwargs.setdefault('access_type', 'offline') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth updating the docstring to explain that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh |
||
url, state = self.oauth2session.authorization_url( | ||
self.client_config['auth_uri'], | ||
access_type='offline', **kwargs) | ||
self.client_config['auth_uri'], **kwargs) | ||
|
||
return url, state | ||
|
||
|
@@ -229,10 +235,9 @@ def fetch_token(self, **kwargs): | |
:meth:`credentials` to obtain a | ||
:class:`~google.auth.credentials.Credentials` instance. | ||
""" | ||
kwargs.setdefault('client_secret', self.client_config['client_secret']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's okay if that happens (for now at least) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
return self.oauth2session.fetch_token( | ||
self.client_config['token_uri'], | ||
client_secret=self.client_config['client_secret'], | ||
**kwargs) | ||
self.client_config['token_uri'], **kwargs) | ||
|
||
@property | ||
def credentials(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want a docstring for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already one for it below (it's a property)