1414from centml .sdk import auth
1515from centml .sdk .config import settings
1616
17-
1817CLIENT_ID = settings .CENTML_WORKOS_CLIENT_ID
1918SERVER_HOST = "127.0.0.1"
2019SERVER_PORT = 57983
2625
2726def generate_pkce_pair ():
2827 verifier = secrets .token_urlsafe (64 )
29- challenge = (
30- base64 .urlsafe_b64encode (hashlib .sha256 (verifier .encode ()).digest ())
31- .decode ()
32- .rstrip ("=" )
33- )
28+ challenge = base64 .urlsafe_b64encode (hashlib .sha256 (verifier .encode ()).digest ()).decode ().rstrip ("=" )
3429 return verifier , challenge
3530
3631
@@ -55,16 +50,14 @@ def do_GET(self):
5550 self .send_response (200 )
5651 self .send_header ("Content-type" , "text/html" )
5752 self .end_headers ()
58- self .wfile .write (
59- """
53+ self .wfile .write ("""
6054 <html>
6155 <body>
6256 <h1>Succesfully logged into CentML CLI</h1>
6357 <p>You can now close this tab and continue in the CLI.</p>
6458 </body>
6559 </html>
66- """ .encode ("utf-8" )
67- )
60+ """ .encode ("utf-8" ))
6861
6962 def log_message (self , format , * args ):
7063 # Override this to suppress logging
@@ -104,18 +97,14 @@ def login(token_file):
10497 else :
10598 click .echo ("Logging into CentML..." )
10699
107- choice = click .confirm (
108- "Do you want to log in with your browser now?" , default = True
109- )
100+ choice = click .confirm ("Do you want to log in with your browser now?" , default = True )
110101 if choice :
111102 try :
112103 # PKCE Flow
113104 code_verifier , code_challenge = generate_pkce_pair ()
114105 auth_url = build_auth_url (CLIENT_ID , REDIRECT_URI , code_challenge )
115106 click .echo ("A browser window will open for you to authenticate." )
116- click .echo (
117- "If it doesn't open automatically, you can copy and paste this URL:"
118- )
107+ click .echo ("If it doesn't open automatically, you can copy and paste this URL:" )
119108 click .echo (f" { auth_url } \n " )
120109 webbrowser .open (auth_url )
121110 click .echo ("Waiting for authentication..." )
@@ -127,13 +116,9 @@ def login(token_file):
127116 click .echo ("Login failed. Please try again." )
128117 else :
129118 cred = {
130- key : response_dict [key ]
131- for key in ("access_token" , "refresh_token" )
132- if key in response_dict
119+ key : response_dict [key ] for key in ("access_token" , "refresh_token" ) if key in response_dict
133120 }
134- os .makedirs (
135- os .path .dirname (settings .CENTML_CRED_FILE_PATH ), exist_ok = True
136- )
121+ os .makedirs (os .path .dirname (settings .CENTML_CRED_FILE_PATH ), exist_ok = True )
137122 with open (settings .CENTML_CRED_FILE_PATH , "w" ) as f :
138123 json .dump (cred , f )
139124 click .echo ("✅ Login successful" )
0 commit comments