tools/lib/auth.py update oauth redirect url
parent
2a05701f47
commit
0252072729
|
@ -7,12 +7,14 @@ from tools.lib.api import CommaApi, APIError
|
|||
from tools.lib.auth_config import set_token
|
||||
from typing import Dict, Any
|
||||
|
||||
PORT = 3000
|
||||
|
||||
class ClientRedirectServer(HTTPServer):
|
||||
query_params: Dict[str, Any] = {}
|
||||
|
||||
class ClientRedirectHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if not self.path.startswith('/auth_redirect'):
|
||||
if not self.path.startswith('/auth/g/redirect'):
|
||||
self.send_response(204)
|
||||
return
|
||||
|
||||
|
@ -28,8 +30,8 @@ class ClientRedirectHandler(BaseHTTPRequestHandler):
|
|||
def log_message(self, format, *args): # pylint: disable=redefined-builtin
|
||||
pass # this prevent http server from dumping messages to stdout
|
||||
|
||||
def auth_redirect_link(port):
|
||||
redirect_uri = f'http://localhost:{port}/auth_redirect'
|
||||
def auth_redirect_link():
|
||||
redirect_uri = f'http://localhost:{PORT}/auth/g/redirect'
|
||||
params = {
|
||||
'type': 'web_server',
|
||||
'client_id': '45471411055-ornt4svd2miog6dnopve7qtmh5mnu6id.apps.googleusercontent.com',
|
||||
|
@ -42,10 +44,9 @@ def auth_redirect_link(port):
|
|||
return (redirect_uri, 'https://accounts.google.com/o/oauth2/auth?' + urlencode(params))
|
||||
|
||||
def login():
|
||||
port = 9090
|
||||
redirect_uri, oauth_uri = auth_redirect_link(port)
|
||||
redirect_uri, oauth_uri = auth_redirect_link()
|
||||
|
||||
web_server = ClientRedirectServer(('localhost', port), ClientRedirectHandler)
|
||||
web_server = ClientRedirectServer(('localhost', PORT), ClientRedirectHandler)
|
||||
print(f'To sign in, use your browser and navigate to {oauth_uri}')
|
||||
webbrowser.open(oauth_uri, new=2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue