Skip to content

Commit 6a0a7cb

Browse files
authored
Merge pull request #152 from mtoshi/add_cherrypy_hostname_and_port_control
Add CherryPy server hostname and port control
2 parents 2f00d77 + 1692aca commit 6a0a7cb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

gather_keys_oauth2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import traceback
77
import webbrowser
88

9+
from urllib.parse import urlparse
910
from base64 import b64encode
1011
from fitbit.api import Fitbit
1112
from oauthlib.oauth2.rfc6749.errors import MismatchingStateError, MissingTokenError
@@ -28,6 +29,8 @@ def __init__(self, client_id, client_secret,
2829
timeout=10,
2930
)
3031

32+
self.redirect_uri = redirect_uri
33+
3134
def browser_authorize(self):
3235
"""
3336
Open a browser to the authorization url and spool up a CherryPy
@@ -36,6 +39,12 @@ def browser_authorize(self):
3639
url, _ = self.fitbit.client.authorize_token_url()
3740
# Open the web browser in a new thread for command-line browser support
3841
threading.Timer(1, webbrowser.open, args=(url,)).start()
42+
43+
# Same with redirect_uri hostname and port.
44+
urlparams = urlparse(self.redirect_uri)
45+
cherrypy.config.update({'server.socket_host': urlparams.hostname,
46+
'server.socket_port': urlparams.port})
47+
3948
cherrypy.quickstart(self)
4049

4150
@cherrypy.expose

0 commit comments

Comments
 (0)