-
Notifications
You must be signed in to change notification settings - Fork 309
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
Add InstalledAppFlow #128
Add InstalledAppFlow #128
Conversation
This is DO NOT MERGE because I want a sanity check before I go any further.
Specifically for (2), I had some thoughts that it might make more sense to separate the strategies into separate classes: flow = google.oauth2.flow.InstalledAppFlow.from_client_secrets_file(...)
strategy = flow.ServerStrategy(port=9000)
# or
strategy = flow.ConsoleStrategy()
flow.run(strategy)
# or
flow.strategy = strategy
flow.run() But I'm unsure if that's over-engineering, even if it feels cleaner. |
/cc @proppy |
Can you provide some sample code for what it looks like with a single, combined flow? It would make it easier to reason about without doing a deep dive. |
@lukesneeringer not sure what you're asking for. |
I was referring to (2) specifically. Right now it seems to be: flow = InstalledAppFlow(...)
flow.run(strategy=SERVER, port=9000) I think that is fine. I do not think strategy objects are necessary. And it does seem reasonable that some arguments (like |
@lukesneeringer that's nearly correct, it would be: flow = InstalledAppFlow(...)
flow.web_port = 9000
flow.run(strategy=SERVER) I can keep that same interface but separate the internals into two separate strategy classes. Curious as to what @dhermes thinks as well. |
That makes a little less sense to me, but it certainly seems good enough. And it is probably better than making the user create a strategy object. |
It makes more sense to pass into Another option is to have two |
Oooh, I think |
Cool, that's what I'll go with. I'll remove |
@dhermes @lukesneeringer this is ready for review. :) |
@proppy it would be super cool if you took a look as well. |
google/oauth2/flow.py
Outdated
@@ -15,7 +15,7 @@ | |||
"""OAuth 2.0 Authorization Flow | |||
|
|||
.. warning:: | |||
This module is experimental and is subject to change signficantly | |||
This module is experimental and is subject to change significantly |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
@@ -54,12 +54,22 @@ | |||
""" | |||
|
|||
import json | |||
import logging | |||
import webbrowser |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
|
||
import google.auth.transport.requests | ||
import google.oauth2.credentials | ||
import google.oauth2.oauthlib | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
|
||
import google.oauth2.flow | ||
|
||
flow = google.oauth2.flow.InstalledAppFlow.from_client_secrets_file( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
""" | ||
kwargs.setdefault('prompt', 'consent') | ||
|
||
self.redirect_uri = self._OOB_REDIRECT_URI |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
|
||
auth_url, _ = self.authorization_url(**kwargs) | ||
|
||
print(authorization_prompt_message.format(url=auth_url)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
code is then exchanged for a token. | ||
|
||
Args: | ||
host (str): The web host for the local redirect server. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
|
||
return self.credentials | ||
|
||
class _LocalRedirectServer(BaseHTTPServer.HTTPServer): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
setup.py
Outdated
@@ -39,7 +39,7 @@ | |||
description='Google Authentication Library', | |||
long_description=long_description, | |||
url='https://github.com/GoogleCloudPlatform/google-auth-library-python', | |||
packages=find_packages(exclude=('tests', 'system_tests')), | |||
packages=find_packages(exclude=('tests*', 'system_tests*')), |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
local_server = self._LocalRedirectServer( | ||
success_message, (host, port), self._LocalRedirectRequestHandler) | ||
|
||
webbrowser.open(auth_url, new=1, autoraise=True) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
self.success_message = success_message | ||
self.last_request_path = None | ||
|
||
class _LocalRedirectRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
do we want a "smart" |
68ef67c
to
af9677a
Compare
Webbrowser doesn't give us any indication if the |
@dhermes @lukesneeringer should be good to review again. |
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.
LGTM I think?
google/oauth2/flow.py
Outdated
@@ -54,12 +54,22 @@ | |||
""" | |||
|
|||
import json | |||
import logging | |||
import webbrowser |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
google/oauth2/flow.py
Outdated
|
||
import google.auth.transport.requests | ||
import google.oauth2.credentials | ||
import google.oauth2.oauthlib | ||
|
||
|
||
_LOGGER = logging.getLogger(__name__) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
bebf653
to
d464f86
Compare
The good news is that it's in a separate package now, woohoo. :) |
|
||
auth_url, _ = self.authorization_url(**kwargs) | ||
|
||
print(authorization_prompt_message.format(url=auth_url)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Resolves #122