Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions gather_keys_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import traceback
import webbrowser

from urllib.parse import urlparse
from base64 import b64encode
from fitbit.api import Fitbit
from oauthlib.oauth2.rfc6749.errors import MismatchingStateError, MissingTokenError
Expand All @@ -28,6 +29,8 @@ def __init__(self, client_id, client_secret,
timeout=10,
)

self.redirect_uri = redirect_uri

def browser_authorize(self):
"""
Open a browser to the authorization url and spool up a CherryPy
Expand All @@ -36,6 +39,12 @@ def browser_authorize(self):
url, _ = self.fitbit.client.authorize_token_url()
# Open the web browser in a new thread for command-line browser support
threading.Timer(1, webbrowser.open, args=(url,)).start()

# Same with redirect_uri hostname and port.
urlparams = urlparse(self.redirect_uri)
cherrypy.config.update({'server.socket_host': urlparams.hostname,
'server.socket_port': urlparams.port})

cherrypy.quickstart(self)

@cherrypy.expose
Expand Down