|
3 | 3 | import os
|
4 | 4 | import socket
|
5 | 5 | import webbrowser
|
| 6 | +from typing import Optional |
6 | 7 |
|
7 | 8 | import click
|
8 | 9 | from dotenv import load_dotenv
|
@@ -56,25 +57,34 @@ def set_port():
|
56 | 57 |
|
57 | 58 | @click.command()
|
58 | 59 | @environment_options
|
59 |
| -def auth(domain="alpha"): |
| 60 | +@click.option( |
| 61 | + "-f", |
| 62 | + "--force", |
| 63 | + is_flag=True, |
| 64 | + required=False, |
| 65 | + help="Force new token", |
| 66 | +) |
| 67 | +def auth(domain, force: Optional[bool] = False): |
60 | 68 | """Authenticate with UiPath Cloud Platform."""
|
61 | 69 | with console.spinner("Authenticating with UiPath ..."):
|
62 | 70 | portal_service = PortalService(domain)
|
63 |
| - if ( |
64 |
| - os.getenv("UIPATH_URL") |
65 |
| - and os.getenv("UIPATH_TENANT_ID") |
66 |
| - and os.getenv("UIPATH_ORGANIZATION_ID") |
67 |
| - ): |
68 |
| - try: |
69 |
| - portal_service.ensure_valid_token() |
70 |
| - console.success( |
71 |
| - "Authentication successful.", |
72 |
| - ) |
73 |
| - return |
74 |
| - except Exception: |
75 |
| - console.info( |
76 |
| - "Authentication token is invalid. Please reauthenticate.", |
77 |
| - ) |
| 71 | + |
| 72 | + if not force: |
| 73 | + if ( |
| 74 | + os.getenv("UIPATH_URL") |
| 75 | + and os.getenv("UIPATH_TENANT_ID") |
| 76 | + and os.getenv("UIPATH_ORGANIZATION_ID") |
| 77 | + ): |
| 78 | + try: |
| 79 | + portal_service.ensure_valid_token() |
| 80 | + console.success( |
| 81 | + "Authentication successful.", |
| 82 | + ) |
| 83 | + return |
| 84 | + except Exception: |
| 85 | + console.info( |
| 86 | + "Authentication token is invalid. Please reauthenticate.", |
| 87 | + ) |
78 | 88 |
|
79 | 89 | auth_url, code_verifier, state = get_auth_url(domain)
|
80 | 90 |
|
|
0 commit comments