1111// See the License for the specific language governing permissions and
1212// limitations under the License.
1313// ----------------------------------------------------------------------------------
14- using Microsoft . Azure . Commands . Common ;
1514using Microsoft . Azure . Commands . Common . Authentication ;
1615using Microsoft . Azure . Commands . Common . Authentication . Abstractions ;
1716using Microsoft . Azure . Commands . Common . Authentication . Models ;
1817using Microsoft . Azure . Commands . Common . Authentication . ResourceManager ;
19- using Microsoft . Azure . Commands . Common . Exceptions ;
2018using Microsoft . Azure . Commands . Profile . Models ;
2119using Microsoft . Azure . Commands . Profile . Properties ;
2220using Microsoft . Azure . Commands . Profile . Utilities ;
23- using Microsoft . Azure . Management . Profiles . Storage . Version2019_06_01 . Models ;
24- using Microsoft . Identity . Client . NativeInterop ;
2521using Microsoft . Rest . Azure ;
2622using Microsoft . WindowsAzure . Commands . Common ;
2723
2824using System ;
2925using System . Collections . Generic ;
3026using System . Linq ;
3127using System . Management . Automation ;
32- using System . Runtime . InteropServices ;
3328using System . Security ;
34- using System . Security . Authentication . ExtendedProtection ;
35- using System . Text ;
3629
3730using AuthenticationMessages = Microsoft . Azure . Commands . Common . Authentication . Properties . Resources ;
3831using ProfileMessages = Microsoft . Azure . Commands . Profile . Properties . Resources ;
@@ -46,7 +39,7 @@ public class RMProfileClient
4639 private IAzureTokenCache _cache ;
4740 public Action < string > WarningLog ;
4841 public Action < string > DebugLog ;
49- public Action < string > InformationLog ;
42+ public Action < string > InteractiveInformationLog ;
5043 internal Func < string , string > PromptAndReadLine ;
5144
5245 private List < AzureTenant > _queriedTenants = new List < AzureTenant > ( ) ;
@@ -137,18 +130,21 @@ public AzureRmProfile Login(
137130 bool shouldPopulateContextList = true ,
138131 int maxContextPopulation = Profile . ConnectAzureRmAccountCommand . DefaultMaxContextPopulation ,
139132 string authScope = null ,
140- bool isInteractiveAuthenticationFlow = false ,
141133 bool IsInteractiveContextSelectionEnabled = true )
142134 {
143- if ( isInteractiveAuthenticationFlow ) WriteInformationMessage ( $ "{ PSStyle . ForegroundColor . BrightYellow } { Resources . PleaseSelectAccount } { PSStyle . Reset } { System . Environment . NewLine } ") ;
135+
136+ WriteInteractiveInformationMessage ( $ "{ PSStyle . ForegroundColor . BrightYellow } { Resources . PleaseSelectAccount } { PSStyle . Reset } { System . Environment . NewLine } ") ;
144137
145138 IAzureSubscription defaultSubscription = null ;
146139 IAzureTenant defaultTenant = null ;
147140 List < AzureSubscription > subscriptions = new List < AzureSubscription > ( ) ;
148141 List < AzureSubscription > tempSubscriptions = null ;
149142 string tenantName = null ;
150143
151- bool selectSubscriptionFromList = isInteractiveAuthenticationFlow && IsInteractiveContextSelectionEnabled && string . IsNullOrEmpty ( subscriptionId ) && string . IsNullOrEmpty ( subscriptionName ) ;
144+ bool selectSubscriptionFromList = AzureAccount . AccountType . User . Equals ( account . Type ) &&
145+ IsInteractiveContextSelectionEnabled &&
146+ string . IsNullOrEmpty ( subscriptionId ) &&
147+ string . IsNullOrEmpty ( subscriptionName ) ;
152148 var lastUsedSubscription = selectSubscriptionFromList ? _profile ? . DefaultContext ? . Subscription : null ;
153149
154150 string promptBehavior =
@@ -242,7 +238,7 @@ public AzureRmProfile Login(
242238 throw new ArgumentNullException ( string . Format ( $ "{ e . Message } { Environment . NewLine } { baseMessage } { typeMessage } ") , e ) ;
243239 }
244240
245- WriteInformationMessage ( Resources . RetrievingSubscription ) ;
241+ WriteInteractiveInformationMessage ( Resources . RetrievingSubscription ) ;
246242 tempSubscriptions = null ;
247243 if ( TryGetTenantSubscription (
248244 token ,
@@ -253,8 +249,7 @@ public AzureRmProfile Login(
253249 true ,
254250 out defaultSubscription ,
255251 out defaultTenant ,
256- out tempSubscriptions ,
257- isInteractiveAuthenticationFlow ) )
252+ out tempSubscriptions ) )
258253 {
259254 account . SetOrAppendProperty ( AzureAccount . Property . Tenants , new [ ] { defaultTenant . Id . ToString ( ) } ) ;
260255
@@ -267,7 +262,7 @@ public AzureRmProfile Login(
267262 {
268263 InteractiveSubscriptionSelectionHelper . SelectSubscriptionFromList (
269264 subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
270- Prompt , WriteInformationMessage ,
265+ Prompt , WriteInteractiveInformationMessage ,
271266 ref defaultSubscription , ref defaultTenant ) ;
272267 }
273268 }
@@ -283,7 +278,7 @@ public AzureRmProfile Login(
283278 IAzureSubscription tempSubscription = null ;
284279 tempSubscriptions = null ;
285280
286- WriteInformationMessage ( Resources . RetrievingSubscription ) ;
281+ WriteInteractiveInformationMessage ( Resources . RetrievingSubscription ) ;
287282
288283 foreach ( var tenant in _queriedTenants )
289284 {
@@ -323,7 +318,7 @@ public AzureRmProfile Login(
323318
324319 if ( token != null &&
325320 ( defaultTenant == null || selectSubscriptionFromList ) &&
326- TryGetTenantSubscription ( token , account , environment , subscriptionId , subscriptionName , false , out tempSubscription , out tempTenant , out tempSubscriptions , isInteractiveAuthenticationFlow ) )
321+ TryGetTenantSubscription ( token , account , environment , subscriptionId , subscriptionName , false , out tempSubscription , out tempTenant , out tempSubscriptions ) )
327322 {
328323 // If no subscription found for the given token/tenant,discard tempTenant value.
329324 // Continue to look for matched subscripitons until one subscription retrived by its home tenant is found.
@@ -350,7 +345,7 @@ public AzureRmProfile Login(
350345 {
351346 InteractiveSubscriptionSelectionHelper . SelectSubscriptionFromList (
352347 subscriptions , _queriedTenants , tenantIdOrName , tenantName , lastUsedSubscription ,
353- Prompt , WriteInformationMessage ,
348+ Prompt , WriteInteractiveInformationMessage ,
354349 ref defaultSubscription , ref defaultTenant ) ;
355350 }
356351 }
@@ -385,7 +380,7 @@ public AzureRmProfile Login(
385380 WriteWarningMessage ( string . Format ( ProfileMessages . CannotSetDefaultContext , defaultContext . ToString ( ) ) ) ;
386381 }
387382
388- if ( ! skipValidation && ! defaultSubscription . State . Equals ( "Enabled" , StringComparison . OrdinalIgnoreCase ) )
383+ if ( ! skipValidation && null != defaultSubscription . State && ! defaultSubscription . State . Equals ( "Enabled" , StringComparison . OrdinalIgnoreCase ) )
389384 {
390385 WriteWarningMessage ( string . Format (
391386 ProfileMessages . SelectedSubscriptionNotActive ,
@@ -707,9 +702,9 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
707702 bool isTenantPresent ,
708703 out IAzureSubscription subscription ,
709704 out IAzureTenant tenant ,
710- out List < AzureSubscription > subscriptions ,
711- bool isInteractiveAuthentication )
705+ out List < AzureSubscription > subscriptions )
712706 {
707+ bool isInteractiveAuthentication = AzureAccount . AccountType . User . Equals ( account . Type ) ;
713708 subscriptions = new List < AzureSubscription > ( ) ;
714709 subscription = null ;
715710 if ( accessToken != null )
@@ -881,11 +876,11 @@ private void WriteDebugMessage(string message)
881876 DebugLog ( message ) ;
882877 }
883878 }
884- private void WriteInformationMessage ( string message )
879+ private void WriteInteractiveInformationMessage ( string message )
885880 {
886- if ( InformationLog != null )
881+ if ( InteractiveInformationLog != null )
887882 {
888- InformationLog ( message ) ;
883+ InteractiveInformationLog ( message ) ;
889884 }
890885 }
891886
0 commit comments