From 0252072729b188d5a725e8a2b979ca4d44f92773 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 17 May 2021 14:51:29 +0200 Subject: [PATCH] tools/lib/auth.py update oauth redirect url --- tools/lib/auth.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/lib/auth.py b/tools/lib/auth.py index b91eb3f7..ce15be98 100755 --- a/tools/lib/auth.py +++ b/tools/lib/auth.py @@ -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)