3
3
import webbrowser
4
4
import threading
5
5
import uuid
6
+ import socket
6
7
import logging
7
8
from urllib .parse import urlparse
8
9
import requests
15
16
log = logging .getLogger ('werkzeug' )
16
17
log .setLevel (logging .ERROR ) # Hides most warnings
17
18
19
+ client_id = os .getenv ('SLP_CLIENT_ID' , f"smartloop-on-{ socket .gethostname ()} " )
20
+
18
21
class BrowserLogin :
19
22
'''Class to handle browser-based login for SmartLoop CLI.'''
20
23
def __init__ (self , port = 5000 ):
@@ -113,7 +116,7 @@ def _exchange_code_for_token(self, code):
113
116
'grant_type' : 'authorization_code' ,
114
117
'code' : code ,
115
118
'redirect_uri' : self .redirect_uri ,
116
- 'client_id' : os . getenv ( 'SLP_CLIENT_ID' , 'smartloop-cli' )
119
+ 'client_id' : client_id
117
120
}
118
121
)
119
122
@@ -149,7 +152,6 @@ def open_login_page(self):
149
152
"""Open the browser for the user to authenticate."""
150
153
# Construct the authorization URL pointing to /login
151
154
auth_url = f"{ auth_server } /login"
152
- client_id = os .getenv ('SLP_CLIENT_ID' , 'smartloop-cli' )
153
155
full_auth_url = f"{ auth_url } ?response_type=code&redirect_uri={ self .redirect_uri } &state={ self .state } &client_id={ client_id } "
154
156
# Open the authorization URL in the user's default browser
155
157
webbrowser .open (full_auth_url )
@@ -165,7 +167,6 @@ def perform_browser_login(callback_port=5000, timeout=120):
165
167
login_handler .start_server ()
166
168
login_handler .open_login_page ()
167
169
168
- client_id = os .getenv ('SLP_CLIENT_ID' , 'smartloop-cli' )
169
170
print ("A browser window has been opened for you to complete the login process." )
170
171
print ("If it doesn't open automatically, please go to the following URL:" )
171
172
print (f"{ auth_server } /login?response_type=code&redirect_uri=http://localhost:{ login_handler .port } /callback&state={ login_handler .state } &client_id={ client_id } " )
0 commit comments