Skip to content

chore/change auth clientid #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 9 additions & 5 deletions src/uipath_sdk/_cli/_auth/_auth_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -123,25 +127,25 @@ 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)
context.load_cert_chain(self.cert_file, self.key_file)

# 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:
Expand Down
8 changes: 6 additions & 2 deletions src/uipath_sdk/_cli/_auth/_oidc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down
8 changes: 4 additions & 4 deletions src/uipath_sdk/_cli/_auth/auth_config.json
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions src/uipath_sdk/_cli/_auth/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ <h1>UiPath CLI Authentication</h1>
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'
Expand Down Expand Up @@ -164,4 +164,4 @@ <h1>UiPath CLI Authentication</h1>
</script>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion src/uipath_sdk/_cli/_utils/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def environment_options(function):
"--alpha",
"domain",
flag_value="alpha",
default=True,
help="Use alpha environment",
)(function)
function = click.option(
Expand All @@ -19,6 +18,7 @@ def environment_options(function):
"--cloud",
"domain",
flag_value="cloud",
default=True,
help="Use production environment",
)(function)
return function
40 changes: 39 additions & 1 deletion src/uipath_sdk/_cli/cli_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# type: ignore
import json
import os
import socket
import webbrowser

import click
Expand All @@ -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."
Comment on lines +35 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

)
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"):
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions src/uipath_sdk/_cli/cli_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import requests
from dotenv import load_dotenv

from uipath_sdk._cli._utils._common import environment_options

load_dotenv()


Expand Down Expand Up @@ -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")
Expand Down
Loading