Skip to content

Commit bff8dcc

Browse files
committed
feat(auth): add support for custom urls
1 parent 9f88719 commit bff8dcc

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/uipath/_cli/_auth/_oidc_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@ def get_auth_url(domain: str) -> tuple[str, str, str]:
6565
}
6666

6767
query_string = urlencode(query_params)
68-
url = f"https://{domain}.uipath.com/identity_/connect/authorize?{query_string}"
68+
if domain.startswith("http"):
69+
url = f"{domain}/identity_/connect/authorize?{query_string}"
70+
else:
71+
url = f"https://{domain}.uipath.com/identity_/connect/authorize?{query_string}"
6972
return url, code_verifier, state

src/uipath/_cli/_auth/_portal_service.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ def get_tenants_and_organizations(self) -> TenantsAndOrganizationInfoResponse:
6565
if self._client is None:
6666
raise RuntimeError("HTTP client is not initialized")
6767

68-
url = f"https://{self.domain}.uipath.com/{self.prt_id}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo"
68+
if self.domain.startswith("http"):
69+
url = f"{self.domain}/{self.prt_id}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo"
70+
else:
71+
url = f"https://{self.domain}.uipath.com/{self.prt_id}/portal_/api/filtering/leftnav/tenantsAndOrganizationInfo"
6972
response = self._client.get(
7073
url, headers={"Authorization": f"Bearer {self.access_token}"}
7174
)
@@ -213,12 +216,19 @@ def select_tenant(
213216
account_name = tenants_and_organizations["organization"]["name"]
214217
console.info(f"Selected tenant: {click.style(tenant_name, fg='cyan')}")
215218

219+
if domain.startswith("http"):
220+
base_url = domain
221+
else:
222+
base_url = f"https://{domain if domain else 'cloud'}.uipath.com"
223+
224+
uipath_url = f"{base_url}/{account_name}/{tenant_name}"
225+
216226
update_env_file(
217227
{
218-
"UIPATH_URL": f"https://{domain if domain else 'alpha'}.uipath.com/{account_name}/{tenant_name}",
228+
"UIPATH_URL": uipath_url,
219229
"UIPATH_TENANT_ID": tenants_and_organizations["tenants"][tenant_idx]["id"],
220230
"UIPATH_ORGANIZATION_ID": tenants_and_organizations["organization"]["id"],
221231
}
222232
)
223233

224-
return f"https://{domain if domain else 'alpha'}.uipath.com/{account_name}/{tenant_name}"
234+
return uipath_url

src/uipath/_cli/_auth/index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,12 @@ <h1 class="auth-title" id="main-title">Authenticate CLI</h1>
477477
formData.append('client_id', '__PY_REPLACE_CLIENT_ID__');
478478
formData.append('code_verifier', codeVerifier);
479479

480-
const response = await fetch('https://__PY_REPLACE_DOMAIN__.uipath.com/identity_/connect/token', {
480+
const domain = '__PY_REPLACE_DOMAIN__';
481+
const tokenUrl = domain.startsWith('http')
482+
? `${domain}/identity_/connect/token`
483+
: `https://${domain}.uipath.com/identity_/connect/token`;
484+
485+
const response = await fetch(tokenUrl, {
481486
method: 'POST',
482487
headers: {
483488
'Content-Type': 'application/x-www-form-urlencoded'

src/uipath/_cli/cli_auth.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import socket
66
import webbrowser
7+
from urllib.parse import urlparse
78

89
import click
910
from dotenv import load_dotenv
@@ -91,6 +92,9 @@ def auth(
9192
):
9293
"""Authenticate with UiPath Cloud Platform.
9394
95+
The domain for authentication is determined by the UIPATH_URL environment variable if set.
96+
Otherwise, it can be specified with --cloud (default), --staging, or --alpha flags.
97+
9498
Interactive mode (default): Opens browser for OAuth authentication.
9599
Unattended mode: Use --client-id, --client-secret and --base-url for client credentials flow.
96100
@@ -99,6 +103,11 @@ def auth(
99103
- Set REQUESTS_CA_BUNDLE to specify a custom CA bundle for SSL verification
100104
- Set UIPATH_DISABLE_SSL_VERIFY to disable SSL verification (not recommended)
101105
"""
106+
uipath_url = os.getenv("UIPATH_URL")
107+
if uipath_url and domain == "cloud": # "cloud" is the default
108+
parsed_url = urlparse(uipath_url)
109+
domain = f"{parsed_url.scheme}://{parsed_url.netloc}"
110+
102111
# Check if client credentials are provided for unattended authentication
103112
if client_id and client_secret:
104113
if not base_url:

0 commit comments

Comments
 (0)