@@ -113,7 +113,7 @@ public bool TryRemoveContext(IAzureContext context)
113
113
public AzureRmProfile Login (
114
114
IAzureAccount account ,
115
115
IAzureEnvironment environment ,
116
- string tenantId ,
116
+ string tenantIdOrName ,
117
117
string subscriptionId ,
118
118
string subscriptionName ,
119
119
SecureString password ,
@@ -138,13 +138,13 @@ public AzureRmProfile Login(
138
138
bool needDataPlanAuthFirst = ! string . IsNullOrEmpty ( authScope ) ;
139
139
if ( needDataPlanAuthFirst )
140
140
{
141
- var token = AcquireAccessToken ( account , environment , tenantId , password , promptBehavior , promptAction , authScope ) ;
141
+ var token = AcquireAccessToken ( account , environment , tenantIdOrName , password , promptBehavior , promptAction , authScope ) ;
142
142
promptBehavior = ShowDialog . Never ;
143
143
}
144
144
145
145
if ( skipValidation )
146
146
{
147
- if ( string . IsNullOrEmpty ( subscriptionId ) || string . IsNullOrEmpty ( tenantId ) )
147
+ if ( string . IsNullOrEmpty ( subscriptionId ) || string . IsNullOrEmpty ( tenantIdOrName ) )
148
148
{
149
149
throw new PSInvalidOperationException ( Resources . SubscriptionOrTenantMissing ) ;
150
150
}
@@ -154,29 +154,31 @@ public AzureRmProfile Login(
154
154
Id = subscriptionId
155
155
} ;
156
156
157
- newSubscription . SetOrAppendProperty ( AzureSubscription . Property . Tenants , tenantId ) ;
157
+ newSubscription . SetOrAppendProperty ( AzureSubscription . Property . Tenants , tenantIdOrName ) ;
158
158
newSubscription . SetOrAppendProperty ( AzureSubscription . Property . Account , account . Id ) ;
159
159
160
160
newTenant = new AzureTenant
161
161
{
162
- Id = tenantId
162
+ Id = tenantIdOrName
163
163
} ;
164
164
}
165
165
else
166
166
{
167
167
// (tenant and subscription are present) OR
168
168
// (tenant is present and subscription is not provided)
169
- if ( ! string . IsNullOrEmpty ( tenantId ) )
169
+ if ( ! string . IsNullOrEmpty ( tenantIdOrName ) )
170
170
{
171
171
Guid tempGuid = Guid . Empty ;
172
- if ( ! Guid . TryParse ( tenantId , out tempGuid ) )
172
+ if ( ! Guid . TryParse ( tenantIdOrName , out tempGuid ) )
173
173
{
174
174
var tenants = ListAccountTenants ( account , environment , password , promptBehavior , promptAction ) ;
175
- var homeTenants = tenants . FirstOrDefault ( t => t . IsHome ) ;
176
- var tenant = homeTenants ?? tenants . FirstOrDefault ( ) ;
175
+ var matchesName = tenants . Where ( t => t . GetPropertyAsArray ( AzureTenant . Property . Domains )
176
+ . Contains ( tenantIdOrName , StringComparer . InvariantCultureIgnoreCase ) ) ;
177
+ var homeTenants = matchesName . FirstOrDefault ( t => t . IsHome ) ;
178
+ var tenant = homeTenants ?? matchesName . FirstOrDefault ( ) ;
177
179
if ( tenant == null || tenant . Id == null )
178
180
{
179
- string baseMessage = string . Format ( ProfileMessages . TenantDomainNotFound , tenantId ) ;
181
+ string baseMessage = string . Format ( ProfileMessages . TenantDomainNotFound , tenantIdOrName ) ;
180
182
var typeMessageMap = new Dictionary < string , string >
181
183
{
182
184
{ AzureAccount . AccountType . ServicePrincipal , string . Format ( ProfileMessages . ServicePrincipalTenantDomainNotFound , account . Id ) } ,
@@ -187,14 +189,14 @@ public AzureRmProfile Login(
187
189
throw new ArgumentNullException ( string . Format ( "{0} {1}" , baseMessage , typeMessage ) ) ;
188
190
}
189
191
190
- tenantId = tenant . Id ;
192
+ tenantIdOrName = tenant . Id ;
191
193
}
192
194
193
195
194
196
var token = AcquireAccessToken (
195
197
account ,
196
198
environment ,
197
- tenantId ,
199
+ tenantIdOrName ,
198
200
password ,
199
201
promptBehavior ,
200
202
promptAction ) ;
@@ -317,7 +319,7 @@ public AzureRmProfile Login(
317
319
if ( shouldPopulateContextList && maxContextPopulation != 0 )
318
320
{
319
321
var defaultContext = _profile . DefaultContext ;
320
- var subscriptions = maxContextPopulation > 0 ? ListSubscriptions ( tenantId ) . Take ( maxContextPopulation ) : ListSubscriptions ( tenantId ) ;
322
+ var subscriptions = maxContextPopulation > 0 ? ListSubscriptions ( tenantIdOrName ) . Take ( maxContextPopulation ) : ListSubscriptions ( tenantIdOrName ) ;
321
323
322
324
foreach ( var subscription in subscriptions )
323
325
{
0 commit comments