@@ -11,27 +11,73 @@ namespace UiPath.PowerShell.Cmdlets
1111 /// <summary>
1212 /// <para type="synopsis">Obtains an UiPath authentication token</para>
1313 /// <para type="description">The authentication token is needed for other UiPath Powershell cmdlets.</para>
14+ /// <example>
15+ /// <code>Get-UiPathAuthToken -URL https://platform.uipath.com -Username <myuser> -Password <mypassword></code>
16+ /// <para>Connect to UiPath public platform Orchestrator, using user name and password.</para>
17+ /// </example>
18+ /// <example>
19+ /// <code>Get-UiPathAuthToken -URL https://platform.uipath.com -Username <myuser> -Password <mypassword> -Session</code>
20+ /// <para>Connect to UiPath public platform Orchestrator, using user name and password and save the token for the current session.</para>
21+ /// </example>
22+ /// <example>
23+ /// <code>Get-UiPathAuthToken -URL https://uipath.corpnet -WindowsCredentials -Session</code>
24+ /// <para>Connect to a private Orchestrator with Windows enabled, using current Windows credentials and save the token for current session.</para>
25+ /// </example>
1426 /// </summary>
1527 [ Cmdlet ( VerbsCommon . Get , Nouns . AuthToken ) ]
1628 public class GetAuthToken : UiPathCmdlet
1729 {
30+ private const string UserPasswordSet = "UserPassword" ;
31+ private const string WindowsCredentialsSet = "WindowsCredentials" ;
32+
1833 [ Parameter ( Mandatory = true , Position = 0 ) ]
1934 public string URL { get ; set ; }
2035
2136 [ Parameter ( Mandatory = false ) ]
2237 public string TenantName { get ; set ; }
2338
24- [ Parameter ( Mandatory = true ) ]
39+ [ Parameter ( Mandatory = true , ParameterSetName = UserPasswordSet ) ]
2540 public string Username { get ; set ; }
2641
27- [ Parameter ( Mandatory = true ) ]
42+ [ Parameter ( Mandatory = true , ParameterSetName = UserPasswordSet ) ]
2843 public string Password { get ; set ; }
2944
45+ [ Parameter ( Mandatory = true , ParameterSetName = WindowsCredentialsSet ) ]
46+ public SwitchParameter WindowsCredentials { get ; set ; }
47+
3048 [ Parameter ]
3149 public SwitchParameter Session { get ; set ; }
3250
3351 protected override void ProcessRecord ( )
3452 {
53+ AuthToken authToken = null ;
54+ if ( ParameterSetName == UserPasswordSet )
55+ {
56+ authToken = GetUserToken ( ) ;
57+ }
58+ else if ( ParameterSetName == WindowsCredentialsSet )
59+ {
60+ authToken = GetWindowsToken ( ) ;
61+ }
62+ if ( Session . IsPresent )
63+ {
64+ AuthenticatedCmdlet . SetAuthToken ( authToken ) ;
65+ }
66+
67+ WriteObject ( authToken ) ;
68+ }
69+
70+ private AuthToken GetWindowsToken ( )
71+ {
72+ return new AuthToken
73+ {
74+ URL = URL ,
75+ WindowsCredentials = true
76+ } ;
77+ }
78+
79+ private AuthToken GetUserToken ( )
80+ {
3581 var creds = new BasicAuthenticationCredentials ( ) ;
3682 using ( var client = new UiPathWebApi ( creds )
3783 {
@@ -47,18 +93,13 @@ protected override void ProcessRecord()
4793 var response = HandleHttpOperationException ( ( ) => client . Account . Authenticate ( loginModel ) ) ;
4894 var token = ( string ) response . Result ;
4995
50- var authToken = new AuthToken
96+ return new AuthToken
5197 {
5298 Token = token ,
53- URL = URL
99+ URL = URL ,
100+ WindowsCredentials = false
54101 } ;
55102
56- if ( Session . IsPresent )
57- {
58- AuthenticatedCmdlet . SetAuthToken ( authToken ) ;
59- }
60-
61- WriteObject ( authToken ) ;
62103 }
63104 }
64105 }
0 commit comments