12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
- using System ;
16
- using System . Collections . Concurrent ;
17
- using System . Linq ;
18
- using System . Management . Automation ;
19
- using System . Runtime . InteropServices ;
20
- using System . Security ;
21
- using System . Text ;
22
- using System . Threading ;
23
- using System . Threading . Tasks ;
24
-
25
15
using Azure . Identity ;
26
16
27
17
using Microsoft . Azure . Commands . Common . Authentication ;
30
20
using Microsoft . Azure . Commands . Common . Authentication . Factories ;
31
21
using Microsoft . Azure . Commands . Common . Authentication . Models ;
32
22
using Microsoft . Azure . Commands . Common . Authentication . ResourceManager . Common ;
23
+ using Microsoft . Azure . Commands . Common . Authentication . Sanitizer ;
33
24
using Microsoft . Azure . Commands . Profile . Common ;
34
25
using Microsoft . Azure . Commands . Profile . Models . Core ;
35
26
using Microsoft . Azure . Commands . Profile . Properties ;
27
+ using Microsoft . Azure . Commands . Profile . Utilities ;
36
28
using Microsoft . Azure . Commands . ResourceManager . Common ;
37
29
using Microsoft . Azure . Commands . ResourceManager . Common . ArgumentCompleters ;
38
30
using Microsoft . Azure . Commands . Shared . Config ;
39
31
using Microsoft . Azure . PowerShell . Authenticators ;
40
32
using Microsoft . Azure . PowerShell . Authenticators . Factories ;
41
33
using Microsoft . Azure . PowerShell . Common . Config ;
34
+ using Microsoft . Azure . PowerShell . Common . Share . Survey ;
42
35
using Microsoft . Identity . Client ;
43
36
using Microsoft . WindowsAzure . Commands . Common ;
37
+ using Microsoft . WindowsAzure . Commands . Common . Sanitizer ;
44
38
using Microsoft . WindowsAzure . Commands . Common . Utilities ;
45
39
using Microsoft . WindowsAzure . Commands . Utilities . Common ;
46
- using Microsoft . Azure . PowerShell . Common . Share . Survey ;
47
- using Microsoft . Azure . Commands . Profile . Utilities ;
48
- using System . Management . Automation . Runspaces ;
49
- using Microsoft . WindowsAzure . Commands . Common . Sanitizer ;
50
- using Microsoft . Azure . Commands . Common . Authentication . Sanitizer ;
40
+
41
+ using System ;
42
+ using System . Collections . Concurrent ;
43
+ using System . Linq ;
44
+ using System . Management . Automation ;
45
+ using System . Runtime . InteropServices ;
46
+ using System . Security ;
47
+ using System . Text ;
48
+ using System . Threading ;
49
+ using System . Threading . Tasks ;
51
50
52
51
namespace Microsoft . Azure . Commands . Profile
53
52
{
@@ -328,6 +327,7 @@ public override void ExecuteCmdlet()
328
327
Guid subscriptionIdGuid ;
329
328
string subscriptionName = null ;
330
329
string subscriptionId = null ;
330
+ bool isInteractiveAuthentication = IsInteractiveAuthentication ( ) ;
331
331
if ( MyInvocation . BoundParameters . ContainsKey ( nameof ( Subscription ) ) )
332
332
{
333
333
if ( Guid . TryParse ( Subscription , out subscriptionIdGuid ) )
@@ -506,7 +506,7 @@ public override void ExecuteCmdlet()
506
506
commonUtilities = new CommonUtilities ( ) ;
507
507
AzureSession . Instance . RegisterComponent ( nameof ( CommonUtilities ) , ( ) => commonUtilities ) ;
508
508
}
509
- if ( ! commonUtilities . IsDesktopSession ( ) && IsUsingInteractiveAuthentication ( ) )
509
+ if ( ! commonUtilities . IsDesktopSession ( ) && IsBrowserPopUpInteractiveAuthentication ( ) )
510
510
{
511
511
WriteWarning ( Resources . InteractiveAuthNotSupported ) ;
512
512
return ;
@@ -523,8 +523,10 @@ public override void ExecuteCmdlet()
523
523
shouldPopulateContextList = false ;
524
524
}
525
525
526
- profileClient . WarningLog = ( message ) => _tasks . Enqueue ( new Task ( ( ) => this . WriteWarning ( message ) ) ) ;
526
+ profileClient . WarningLog = ( message ) => _tasks . Enqueue ( new Task ( ( ) => this . WriteWarning ( message ) ) ) ;
527
+ profileClient . InformationLog = ( message ) => _tasks . Enqueue ( new Task ( ( ) => this . WriteInformation ( message , false ) ) ) ;
527
528
profileClient . DebugLog = ( message ) => _tasks . Enqueue ( new Task ( ( ) => this . WriteDebugWithTimestamp ( message ) ) ) ;
529
+
528
530
var task = new Task < AzureRmProfile > ( ( ) => profileClient . Login (
529
531
azureAccount ,
530
532
_environment ,
@@ -538,7 +540,9 @@ public override void ExecuteCmdlet()
538
540
name ,
539
541
shouldPopulateContextList ,
540
542
MaxContextPopulation ,
541
- resourceId ) ) ;
543
+ resourceId ,
544
+ Prompt ,
545
+ isInteractiveAuthentication ) ) ;
542
546
task . Start ( ) ;
543
547
while ( ! task . IsCompleted )
544
548
{
@@ -569,7 +573,7 @@ public override void ExecuteCmdlet()
569
573
}
570
574
else
571
575
{
572
- if ( IsUsingInteractiveAuthentication ( ) )
576
+ if ( IsBrowserPopUpInteractiveAuthentication ( ) )
573
577
{
574
578
//Display only if user is using Interactive auth
575
579
WriteWarning ( Resources . SuggestToUseDeviceCodeAuth ) ;
@@ -579,9 +583,17 @@ public override void ExecuteCmdlet()
579
583
}
580
584
}
581
585
} ) ;
586
+
587
+ WriteInformation ( $ "[Announcements]{ System . Environment . NewLine } Share your feedback regarding your experience with `Connect-AzAccount` at: https://aka.ms/azloginfeedback{ System . Environment . NewLine } ") ;
588
+ WriteInformation ( $ "If you encounter any problem, please open an issue at: https://aka.ms/azpsissue{ System . Environment . NewLine } ") ;
582
589
}
583
590
}
584
591
592
+ private bool IsInteractiveAuthentication ( )
593
+ {
594
+ return ParameterSetName . Equals ( UserParameterSet ) ;
595
+ }
596
+
585
597
private void ValidateActionRequiredMessageCanBePresented ( )
586
598
{
587
599
if ( UseDeviceAuthentication . IsPresent && IsWriteInformationIgnored ( ) )
@@ -608,9 +620,9 @@ private string PreProcessAuthScope()
608
620
return mappedScope ;
609
621
}
610
622
611
- private bool IsUsingInteractiveAuthentication ( )
623
+ private bool IsBrowserPopUpInteractiveAuthentication ( )
612
624
{
613
- return ParameterSetName == UserParameterSet && UseDeviceAuthentication == false ;
625
+ return ParameterSetName . Equals ( UserParameterSet ) && UseDeviceAuthentication . IsPresent == false ;
614
626
}
615
627
616
628
private bool IsUnableToOpenWebPageError ( AuthenticationFailedException exception )
@@ -654,6 +666,20 @@ private void WriteWarningEvent(string message)
654
666
}
655
667
}
656
668
669
+ private void WriteInformationEvent ( string message )
670
+ {
671
+ EventHandler < StreamEventArgs > writeInformationEvent ;
672
+ if ( AzureSession . Instance . TryGetComponent ( WriteInformationKey , out writeInformationEvent ) )
673
+ {
674
+ writeInformationEvent ( this , new StreamEventArgs ( ) { Message = message } ) ;
675
+ }
676
+ }
677
+ private string Prompt ( string message )
678
+ {
679
+ _tasks . Enqueue ( new Task ( ( ) => this . WriteInformation ( message , true ) ) ) ;
680
+ return this . Host . UI . ReadLine ( ) ;
681
+ }
682
+
657
683
private static bool CheckForExistingContext ( AzureRmProfile profile , string name )
658
684
{
659
685
return name != null && profile ? . Contexts != null && profile . Contexts . ContainsKey ( name ) ;
0 commit comments