@@ -68,7 +68,7 @@ public AzureRMProfile Login(
68
68
var token = AcquireAccessToken ( account , environment , tenantId , password , promptBehavior ) ;
69
69
if ( TryGetTenantSubscription ( token , account , environment , tenantId , subscriptionId , subscriptionName , out newSubscription , out newTenant ) )
70
70
{
71
- account . SetProperty ( AzureAccount . Property . Tenants , new [ ] { newTenant . Id . ToString ( ) } ) ;
71
+ account . SetOrAppendProperty ( AzureAccount . Property . Tenants , new [ ] { newTenant . Id . ToString ( ) } ) ;
72
72
}
73
73
}
74
74
// (tenant is not provided and subscription is present) OR
@@ -240,7 +240,7 @@ private void SwitchSubscription(AzureSubscription subscription)
240
240
241
241
public List < AzureTenant > ListTenants ( string tenant )
242
242
{
243
- return ListAccountTenants ( _profile . Context . Account , _profile . Context . Environment , null , ShowDialog . Auto )
243
+ return ListAccountTenants ( _profile . Context . Account , _profile . Context . Environment , null , ShowDialog . Never )
244
244
. Where ( t => tenant == null ||
245
245
tenant . Equals ( t . Id . ToString ( ) , StringComparison . OrdinalIgnoreCase ) ||
246
246
tenant . Equals ( t . Domain , StringComparison . OrdinalIgnoreCase ) )
@@ -380,7 +380,9 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
380
380
{
381
381
try
382
382
{
383
- subscriptions . AddRange ( ListSubscriptions ( tenant . Id . ToString ( ) ) ) ;
383
+ subscriptions . AddRange (
384
+ ListSubscriptions (
385
+ ( tenant . Id == Guid . Empty ) ? tenant . Domain : tenant . Id . ToString ( ) ) ) ;
384
386
}
385
387
catch ( AadAuthenticationException )
386
388
{
@@ -569,10 +571,21 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
569
571
{
570
572
result =
571
573
account . GetPropertyAsArray ( AzureAccount . Property . Tenants )
572
- . Select ( ti => new AzureTenant ( )
573
- {
574
- Id = new Guid ( ti ) ,
575
- Domain = AccessTokenExtensions . GetDomain ( account . Id )
574
+ . Select ( ti => {
575
+ var tenant = new AzureTenant ( ) ;
576
+
577
+ Guid guid ;
578
+ if ( Guid . TryParse ( ti , out guid ) )
579
+ {
580
+ tenant . Id = guid ;
581
+ tenant . Domain = AccessTokenExtensions . GetDomain ( account . Id ) ;
582
+ }
583
+ else
584
+ {
585
+ tenant . Domain = ti ;
586
+ }
587
+
588
+ return tenant ;
576
589
} ) . ToList ( ) ;
577
590
}
578
591
@@ -608,7 +621,7 @@ private IEnumerable<AzureSubscription> ListSubscriptionsForTenant(AzureAccount a
608
621
subscriptions . Subscriptions . Select (
609
622
( s ) =>
610
623
s . ToAzureSubscription ( new AzureContext ( _profile . Context . Subscription , account ,
611
- environment , CreateTenantFromString ( tenantId ) ) ) ) ;
624
+ environment , CreateTenantFromString ( tenantId , accessToken . TenantId ) ) ) ) ;
612
625
}
613
626
614
627
return new List < AzureSubscription > ( ) ;
@@ -623,7 +636,7 @@ private void WriteWarningMessage(string message)
623
636
}
624
637
}
625
638
626
- private static AzureTenant CreateTenantFromString ( string tenantOrDomain )
639
+ private static AzureTenant CreateTenantFromString ( string tenantOrDomain , string accessTokenTenantId )
627
640
{
628
641
AzureTenant result = new AzureTenant ( ) ;
629
642
Guid id ;
@@ -633,6 +646,7 @@ private static AzureTenant CreateTenantFromString(string tenantOrDomain)
633
646
}
634
647
else
635
648
{
649
+ result . Id = Guid . Parse ( accessTokenTenantId ) ;
636
650
result . Domain = tenantOrDomain ;
637
651
}
638
652
0 commit comments