Skip to content

Commit a89f047

Browse files
feat: allow auth everywhere
1 parent ae88de8 commit a89f047

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/uipath_sdk/_cli/_auth/_auth_server.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, token_data):
2424
super().__init__("Token received successfully")
2525

2626

27-
def make_request_handler_class(state, code_verifier, token_callback):
27+
def make_request_handler_class(state, code_verifier, token_callback, domain):
2828
class SimpleHTTPSRequestHandler(http.server.SimpleHTTPRequestHandler):
2929
"""Simple HTTPS request handler that serves static files."""
3030

@@ -85,6 +85,10 @@ def do_GET(self):
8585
content = content.replace("__PY_REPLACE_EXPECTED_STATE__", state)
8686
content = content.replace("__PY_REPLACE_CODE_VERIFIER__", code_verifier)
8787
content = content.replace("__PY_REPLACE_REDIRECT_URI__", redirect_uri)
88+
content = content.replace(
89+
"__PY_REPLACE_CLIENT_ID__", auth_config["client_id"]
90+
)
91+
content = content.replace("__PY_REPLACE_DOMAIN__", domain)
8892

8993
self.send_response(200)
9094
self.send_header("Content-Type", "text/html")
@@ -123,25 +127,25 @@ def token_received_callback(self, token_data):
123127
self.token_data = token_data
124128
self.should_shutdown = True
125129

126-
def create_server(self, state, code_verifier):
130+
def create_server(self, state, code_verifier, domain):
127131
"""Create and configure the HTTPS server."""
128132
# Create SSL context
129133
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
130134
context.load_cert_chain(self.cert_file, self.key_file)
131135

132136
# Create server
133137
handler = make_request_handler_class(
134-
state, code_verifier, self.token_received_callback
138+
state, code_verifier, self.token_received_callback, domain
135139
)
136140
self.httpd = socketserver.TCPServer(("", self.port), handler)
137141
self.httpd.socket = context.wrap_socket(self.httpd.socket, server_side=True)
138142

139143
return self.httpd
140144

141-
def start(self, state, code_verifier):
145+
def start(self, state, code_verifier, domain):
142146
"""Start the server."""
143147
if not self.httpd:
144-
self.create_server(state, code_verifier)
148+
self.create_server(state, code_verifier, domain)
145149

146150
try:
147151
if self.httpd:

src/uipath_sdk/_cli/_auth/_oidc_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ def get_auth_config() -> AuthConfig:
2828
with open(os.path.join(os.path.dirname(__file__), "auth_config.json"), "r") as f:
2929
auth_config = json.load(f)
3030

31+
port = auth_config.get("port", 8104)
32+
33+
redirect_uri = auth_config["redirect_uri"].replace("__PY_REPLACE_PORT__", str(port))
34+
3135
return AuthConfig(
3236
client_id=auth_config["client_id"],
33-
redirect_uri=auth_config["redirect_uri"],
37+
redirect_uri=redirect_uri,
3438
scope=auth_config["scope"],
35-
port=auth_config.get("port", 6234),
39+
port=port,
3640
)
3741

3842

src/uipath_sdk/_cli/_auth/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ <h1>UiPath CLI Authentication</h1>
3939
formData.append('grant_type', 'authorization_code');
4040
formData.append('code', code);
4141
formData.append('redirect_uri', '__PY_REPLACE_REDIRECT_URI__');
42-
formData.append('client_id', '1119a927-10ab-4543-bd1a-ad6bfbbc27f4');
42+
formData.append('client_id', '__PY_REPLACE_CLIENT_ID__');
4343
formData.append('code_verifier', codeVerifier);
4444

4545
// Make token request
46-
const response = await fetch('https://alpha.uipath.com/identity_/connect/token', {
46+
const response = await fetch('https://__PY_REPLACE_DOMAIN__.uipath.com/identity_/connect/token', {
4747
method: 'POST',
4848
headers: {
4949
'Content-Type': 'application/x-www-form-urlencoded'
@@ -164,4 +164,4 @@ <h1>UiPath CLI Authentication</h1>
164164
</script>
165165
</body>
166166

167-
</html>
167+
</html>

0 commit comments

Comments
 (0)