Skip to content

Commit

Permalink
automatically listen on the ip of the callback uri
Browse files Browse the repository at this point in the history
  • Loading branch information
brad committed Aug 22, 2018
1 parent dafc4fb commit 781545a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/nokia
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from optparse import OptionParser
import sys
import os
import socket
import threading
import webbrowser

Expand All @@ -10,8 +11,10 @@ import nokia

try:
import configparser
from urllib.parse import urlparse
except ImportError: # Python 2.x fallback
import ConfigParser as configparser
from urlparse import urlparse


class NokiaOAuth2Server:
Expand All @@ -29,6 +32,10 @@ class NokiaOAuth2Server:
callback_uri=callback_uri,
scope='user.info,user.metrics,user.activity'
)
parsed_url = urlparse(callback_uri)
self.cherrypy_config = {
'server.socket_host': socket.gethostbyname(parsed_url.hostname),
}

def browser_authorize(self):
"""
Expand All @@ -43,6 +50,7 @@ class NokiaOAuth2Server:
print(url)
# Open the web browser in a new thread for command-line browser support
threading.Timer(1, webbrowser.open, args=(url,)).start()
cherrypy.config.update(self.cherrypy_config)
cherrypy.quickstart(self)

@cherrypy.expose
Expand Down

0 comments on commit 781545a

Please sign in to comment.