Skip to content

Commit ae401c5

Browse files
Merge pull request #242 from UiPath/chore/change-auth-clientid
chore/change auth clientid
2 parents b86caed + a6a71ff commit ae401c5

File tree

8 files changed

+64
-21
lines changed

8 files changed

+64
-21
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath-sdk"
3-
version = "0.0.114"
3+
version = "0.0.115"
44
description = "UiPath SDK"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.9"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"client_id": "1119a927-10ab-4543-bd1a-ad6bfbbc27f4",
3-
"redirect_uri": "https://localhost:6234/oidc/login",
4-
"scope": "offline_access openid profile",
5-
"port": 6234
2+
"client_id": "36dea5b8-e8bb-423d-8e7b-c808df8f1c00",
3+
"redirect_uri": "https://localhost:__PY_REPLACE_PORT__/oidc/login",
4+
"scope": "offline_access OrchestratorApiUserAccess ConnectionService DataService DocumentUnderstanding EnterpriseContextService Directory JamJamApi LLMGateway LLMOps OMS",
5+
"port": 8104
66
}

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>

src/uipath_sdk/_cli/_utils/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ def environment_options(function):
66
"--alpha",
77
"domain",
88
flag_value="alpha",
9-
default=True,
109
help="Use alpha environment",
1110
)(function)
1211
function = click.option(
@@ -19,6 +18,7 @@ def environment_options(function):
1918
"--cloud",
2019
"domain",
2120
flag_value="cloud",
21+
default=True,
2222
help="Use production environment",
2323
)(function)
2424
return function

src/uipath_sdk/_cli/cli_auth.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# type: ignore
2+
import json
23
import os
4+
import socket
35
import webbrowser
46

57
import click
@@ -14,6 +16,42 @@
1416
load_dotenv()
1517

1618

19+
def is_port_in_use(port: int) -> bool:
20+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
21+
try:
22+
s.bind(("localhost", port))
23+
s.close()
24+
return False
25+
except socket.error:
26+
return True
27+
28+
29+
def set_port():
30+
auth_config = get_auth_config()
31+
port = auth_config.get("port", 8104)
32+
port_option_one = auth_config.get("portOptionOne", 8104)
33+
port_option_two = auth_config.get("portOptionTwo", 8055)
34+
port_option_three = auth_config.get("portOptionThree", 42042)
35+
if is_port_in_use(port):
36+
if is_port_in_use(port_option_one):
37+
if is_port_in_use(port_option_two):
38+
if is_port_in_use(port_option_three):
39+
raise RuntimeError(
40+
"All configured ports are in use. Please close applications using ports or configure different ports."
41+
)
42+
else:
43+
port = port_option_three
44+
else:
45+
port = port_option_two
46+
else:
47+
port = port_option_one
48+
auth_config["port"] = port
49+
with open(
50+
os.path.join(os.path.dirname(__file__), "..", "auth_config.json"), "w"
51+
) as f:
52+
json.dump(auth_config, f)
53+
54+
1755
@click.command()
1856
@environment_options
1957
def auth(domain="alpha"):
@@ -43,7 +81,7 @@ def auth(domain="alpha"):
4381
)
4482
print(auth_url)
4583
server = HTTPSServer(port=auth_config["port"])
46-
token_data = server.start(state, code_verifier)
84+
token_data = server.start(state, code_verifier, domain)
4785
try:
4886
if token_data:
4987
portal_service.update_token_data(token_data)

src/uipath_sdk/_cli/cli_publish.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import requests
66
from dotenv import load_dotenv
77

8-
from uipath_sdk._cli._utils._common import environment_options
9-
108
load_dotenv()
119

1210

@@ -57,8 +55,7 @@ def get_env_vars():
5755
flag_value="personal",
5856
help="Whether to publish to the personal workspace",
5957
)
60-
@environment_options
61-
def publish(feed, domain="alpha"):
58+
def publish(feed):
6259
if feed is None:
6360
click.echo("Select feed type:")
6461
click.echo(" 0: Tenant package feed")

0 commit comments

Comments
 (0)