From c1e9f7bff3903a591519a5eeaca068c89c15c11a Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Mon, 7 Apr 2025 19:51:48 +0300 Subject: [PATCH 1/6] chore: remove env options from publish --- src/uipath_sdk/_cli/cli_publish.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/uipath_sdk/_cli/cli_publish.py b/src/uipath_sdk/_cli/cli_publish.py index f5c511bf..b11f480d 100644 --- a/src/uipath_sdk/_cli/cli_publish.py +++ b/src/uipath_sdk/_cli/cli_publish.py @@ -5,8 +5,6 @@ import requests from dotenv import load_dotenv -from uipath_sdk._cli._utils._common import environment_options - load_dotenv() @@ -57,8 +55,7 @@ def get_env_vars(): flag_value="personal", help="Whether to publish to the personal workspace", ) -@environment_options -def publish(feed, domain="alpha"): +def publish(feed): if feed is None: click.echo("Select feed type:") click.echo(" 0: Tenant package feed") From b4513262011356f626bb47dedbc3fbe042f2c267 Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Mon, 7 Apr 2025 19:52:05 +0300 Subject: [PATCH 2/6] feat: add 3 port options for auth server --- src/uipath_sdk/_cli/cli_auth.py | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/uipath_sdk/_cli/cli_auth.py b/src/uipath_sdk/_cli/cli_auth.py index bb373a64..28866071 100644 --- a/src/uipath_sdk/_cli/cli_auth.py +++ b/src/uipath_sdk/_cli/cli_auth.py @@ -1,5 +1,7 @@ # type: ignore +import json import os +import socket import webbrowser import click @@ -14,6 +16,42 @@ load_dotenv() +def is_port_in_use(port: int) -> bool: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + try: + s.bind(("localhost", port)) + s.close() + return False + except socket.error: + return True + + +def set_port(): + auth_config = get_auth_config() + port = auth_config.get("port", 8104) + port_option_one = auth_config.get("portOptionOne", 8104) + port_option_two = auth_config.get("portOptionTwo", 8055) + port_option_three = auth_config.get("portOptionThree", 42042) + if is_port_in_use(port): + if is_port_in_use(port_option_one): + if is_port_in_use(port_option_two): + if is_port_in_use(port_option_three): + raise RuntimeError( + "All configured ports are in use. Please close applications using ports or configure different ports." + ) + else: + port = port_option_three + else: + port = port_option_two + else: + port = port_option_one + auth_config["port"] = port + with open( + os.path.join(os.path.dirname(__file__), "..", "auth_config.json"), "w" + ) as f: + json.dump(auth_config, f) + + @click.command() @environment_options def auth(domain="alpha"): @@ -43,7 +81,7 @@ def auth(domain="alpha"): ) print(auth_url) server = HTTPSServer(port=auth_config["port"]) - token_data = server.start(state, code_verifier) + token_data = server.start(state, code_verifier, domain) try: if token_data: portal_service.update_token_data(token_data) From 9b40b7bb401454d391f6178cf6a9a15ee4308622 Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Mon, 7 Apr 2025 19:52:26 +0300 Subject: [PATCH 3/6] chore: change default auth env to cloud --- src/uipath_sdk/_cli/_utils/_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uipath_sdk/_cli/_utils/_common.py b/src/uipath_sdk/_cli/_utils/_common.py index ff994695..0e24f3b9 100644 --- a/src/uipath_sdk/_cli/_utils/_common.py +++ b/src/uipath_sdk/_cli/_utils/_common.py @@ -6,7 +6,6 @@ def environment_options(function): "--alpha", "domain", flag_value="alpha", - default=True, help="Use alpha environment", )(function) function = click.option( @@ -19,6 +18,7 @@ def environment_options(function): "--cloud", "domain", flag_value="cloud", + default=True, help="Use production environment", )(function) return function From ae88de8eafdb0bc2a22341e4f402fa3063fe6efa Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Tue, 8 Apr 2025 11:50:50 +0300 Subject: [PATCH 4/6] chore: add new clientid config --- src/uipath_sdk/_cli/_auth/auth_config.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uipath_sdk/_cli/_auth/auth_config.json b/src/uipath_sdk/_cli/_auth/auth_config.json index 17e5e8dd..e2a2a58b 100644 --- a/src/uipath_sdk/_cli/_auth/auth_config.json +++ b/src/uipath_sdk/_cli/_auth/auth_config.json @@ -1,6 +1,6 @@ { - "client_id": "1119a927-10ab-4543-bd1a-ad6bfbbc27f4", - "redirect_uri": "https://localhost:6234/oidc/login", - "scope": "offline_access openid profile", - "port": 6234 + "client_id": "36dea5b8-e8bb-423d-8e7b-c808df8f1c00", + "redirect_uri": "https://localhost:__PY_REPLACE_PORT__/oidc/login", + "scope": "offline_access OrchestratorApiUserAccess ConnectionService DataService DocumentUnderstanding EnterpriseContextService Directory JamJamApi LLMGateway LLMOps OMS", + "port": 8104 } \ No newline at end of file From a89f047da85fb912668279a6f40d3b9a92be8522 Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Tue, 8 Apr 2025 11:51:53 +0300 Subject: [PATCH 5/6] feat: allow auth everywhere --- src/uipath_sdk/_cli/_auth/_auth_server.py | 14 +++++++++----- src/uipath_sdk/_cli/_auth/_oidc_utils.py | 8 ++++++-- src/uipath_sdk/_cli/_auth/index.html | 6 +++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/uipath_sdk/_cli/_auth/_auth_server.py b/src/uipath_sdk/_cli/_auth/_auth_server.py index 4a8325ef..cfba7345 100644 --- a/src/uipath_sdk/_cli/_auth/_auth_server.py +++ b/src/uipath_sdk/_cli/_auth/_auth_server.py @@ -24,7 +24,7 @@ def __init__(self, token_data): super().__init__("Token received successfully") -def make_request_handler_class(state, code_verifier, token_callback): +def make_request_handler_class(state, code_verifier, token_callback, domain): class SimpleHTTPSRequestHandler(http.server.SimpleHTTPRequestHandler): """Simple HTTPS request handler that serves static files.""" @@ -85,6 +85,10 @@ def do_GET(self): content = content.replace("__PY_REPLACE_EXPECTED_STATE__", state) content = content.replace("__PY_REPLACE_CODE_VERIFIER__", code_verifier) content = content.replace("__PY_REPLACE_REDIRECT_URI__", redirect_uri) + content = content.replace( + "__PY_REPLACE_CLIENT_ID__", auth_config["client_id"] + ) + content = content.replace("__PY_REPLACE_DOMAIN__", domain) self.send_response(200) self.send_header("Content-Type", "text/html") @@ -123,7 +127,7 @@ def token_received_callback(self, token_data): self.token_data = token_data self.should_shutdown = True - def create_server(self, state, code_verifier): + def create_server(self, state, code_verifier, domain): """Create and configure the HTTPS server.""" # Create SSL context context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) @@ -131,17 +135,17 @@ def create_server(self, state, code_verifier): # Create server handler = make_request_handler_class( - state, code_verifier, self.token_received_callback + state, code_verifier, self.token_received_callback, domain ) self.httpd = socketserver.TCPServer(("", self.port), handler) self.httpd.socket = context.wrap_socket(self.httpd.socket, server_side=True) return self.httpd - def start(self, state, code_verifier): + def start(self, state, code_verifier, domain): """Start the server.""" if not self.httpd: - self.create_server(state, code_verifier) + self.create_server(state, code_verifier, domain) try: if self.httpd: diff --git a/src/uipath_sdk/_cli/_auth/_oidc_utils.py b/src/uipath_sdk/_cli/_auth/_oidc_utils.py index 0d6934a4..9bc047d8 100644 --- a/src/uipath_sdk/_cli/_auth/_oidc_utils.py +++ b/src/uipath_sdk/_cli/_auth/_oidc_utils.py @@ -28,11 +28,15 @@ def get_auth_config() -> AuthConfig: with open(os.path.join(os.path.dirname(__file__), "auth_config.json"), "r") as f: auth_config = json.load(f) + port = auth_config.get("port", 8104) + + redirect_uri = auth_config["redirect_uri"].replace("__PY_REPLACE_PORT__", str(port)) + return AuthConfig( client_id=auth_config["client_id"], - redirect_uri=auth_config["redirect_uri"], + redirect_uri=redirect_uri, scope=auth_config["scope"], - port=auth_config.get("port", 6234), + port=port, ) diff --git a/src/uipath_sdk/_cli/_auth/index.html b/src/uipath_sdk/_cli/_auth/index.html index cc9a9e95..5f773154 100644 --- a/src/uipath_sdk/_cli/_auth/index.html +++ b/src/uipath_sdk/_cli/_auth/index.html @@ -39,11 +39,11 @@

UiPath CLI Authentication

formData.append('grant_type', 'authorization_code'); formData.append('code', code); formData.append('redirect_uri', '__PY_REPLACE_REDIRECT_URI__'); - formData.append('client_id', '1119a927-10ab-4543-bd1a-ad6bfbbc27f4'); + formData.append('client_id', '__PY_REPLACE_CLIENT_ID__'); formData.append('code_verifier', codeVerifier); // Make token request - const response = await fetch('https://alpha.uipath.com/identity_/connect/token', { + const response = await fetch('https://__PY_REPLACE_DOMAIN__.uipath.com/identity_/connect/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' @@ -164,4 +164,4 @@

UiPath CLI Authentication

- \ No newline at end of file + From a6a71ff4b169c97453f7751cbaa6f9c1ce960666 Mon Sep 17 00:00:00 2001 From: Robert Andrei Moldoveanu Date: Tue, 8 Apr 2025 11:52:41 +0300 Subject: [PATCH 6/6] chore: increase sdk version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fefb5a89..8eafd222 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath-sdk" -version = "0.0.114" +version = "0.0.115" description = "UiPath SDK" readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.9"