@@ -269,9 +269,6 @@ public AzureRmProfile Login(
269
269
subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
270
270
Prompt , WriteInformationMessage ,
271
271
ref defaultSubscription , ref defaultTenant ) ;
272
- var defaultContext = new AzureContext ( defaultSubscription , account , environment , defaultTenant ) ;
273
- _profile . TrySetDefaultContext ( defaultContext ) ;
274
- _profile . TryRemoveContext ( "Default" ) ;
275
272
}
276
273
}
277
274
}
@@ -325,12 +322,12 @@ public AzureRmProfile Login(
325
322
}
326
323
327
324
if ( token != null &&
328
- defaultTenant == null &&
325
+ ( defaultTenant == null || selectSubscriptionFromList ) &&
329
326
TryGetTenantSubscription ( token , account , environment , subscriptionId , subscriptionName , false , out tempSubscription , out tempTenant , out tempSubscriptions , isInteractiveAuthenticationFlow ) )
330
327
{
331
328
// If no subscription found for the given token/tenant,discard tempTenant value.
332
329
// Continue to look for matched subscripitons until one subscription retrived by its home tenant is found.
333
- if ( tempSubscription != null )
330
+ if ( defaultTenant == null && tempSubscription != null )
334
331
{
335
332
defaultSubscription = tempSubscription ;
336
333
if ( tempSubscription . GetTenant ( ) == tempSubscription . GetHomeTenant ( ) )
@@ -355,14 +352,12 @@ public AzureRmProfile Login(
355
352
subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
356
353
Prompt , WriteInformationMessage ,
357
354
ref defaultSubscription , ref defaultTenant ) ;
358
- var defaultContext = new AzureContext ( defaultSubscription , account , environment , defaultTenant ) ;
359
- _profile . TrySetDefaultContext ( defaultContext ) ;
360
- _profile . TryRemoveContext ( "Default" ) ;
361
355
}
362
356
}
363
357
}
364
358
365
359
shouldPopulateContextList &= _profile . DefaultContext ? . Account == null ;
360
+
366
361
if ( defaultSubscription == null )
367
362
{
368
363
if ( subscriptionId != null )
@@ -383,7 +378,7 @@ public AzureRmProfile Login(
383
378
}
384
379
else
385
380
{
386
- defaultTenant = InteractiveSubscriptionSelectionHelper . GetDetailedTenantFromQueryHistory ( _queriedTenants , defaultTenant ? . Id ) ?? defaultTenant ; ;
381
+ defaultTenant = InteractiveSubscriptionSelectionHelper . GetDetailedTenantFromQueryHistory ( _queriedTenants , defaultTenant ? . Id ) ?? defaultTenant ;
387
382
var defaultContext = new AzureContext ( defaultSubscription , account , environment , defaultTenant ) ;
388
383
if ( ! _profile . TrySetDefaultContext ( name , defaultContext ) )
389
384
{
0 commit comments