Skip to content

Commit 2e67e02

Browse files
authored
Merge branch 'preview' into netcore11-merge
2 parents 92f2228 + 140c285 commit 2e67e02

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/ResourceManager/Subscription/Commands.Subscription/Cmdlets/NewAzureRmSubscription.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
using Microsoft.Azure.Commands.ResourceManager.Common;
1818
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1919
using Microsoft.Azure.Commands.Subscription.Models;
20+
using Microsoft.Azure.Graph.RBAC.Version1_6;
2021
using Microsoft.Azure.Graph.RBAC.Version1_6.ActiveDirectory;
22+
using Microsoft.Azure.Graph.RBAC.Version1_6.Models;
2123
using Microsoft.Azure.Management.Subscription;
2224
using Microsoft.Azure.Management.Subscription.Models;
2325
using System;
@@ -128,11 +130,25 @@ private string[] ResolveObjectIds(string[] objectIds, string[] servicePrincipalN
128130
{
129131
foreach (string upn in userPrincipalNames)
130132
{
131-
uniqueObjectIds.Add(Guid.Parse(ActiveDirectoryClient.GetObjectIdFromUPN(upn)));
133+
// TODO: Revert once available: uniqueObjectIds.Add(Guid.Parse(ActiveDirectoryClient.GetObjectIdFromUPN(upn)));
134+
uniqueObjectIds.Add(Guid.Parse(GetObjectIdFromUPN(ActiveDirectoryClient, upn)));
132135
}
133136
}
134137

135138
return uniqueObjectIds.Select(id => id.ToString()).ToArray();
136139
}
140+
141+
// Temporary until this code has moved into ActiveDirectoryClient.
142+
private static string GetObjectIdFromUPN(ActiveDirectoryClient activeDirectoryClient, string upn)
143+
{
144+
var odataQueryFilter = new Rest.Azure.OData.ODataQuery<User>(s => s.UserPrincipalName == upn);
145+
var user = activeDirectoryClient.GraphClient.Users.List(odataQueryFilter.ToString()).SingleOrDefault();
146+
if (user == null)
147+
{
148+
throw new InvalidOperationException(String.Format("User with UPN '{0}' does not exist.", upn));
149+
}
150+
151+
return user.ObjectId;
152+
}
137153
}
138154
}

0 commit comments

Comments
 (0)