Howdy folks,
I am trying to get a new application up with AAD as the default backend identity provider. Crawling through the various samples and examples, and trying to use the latest set of libraries, I have run into a snag in terms of creating new users with the latest libraries. (If I use the older libraries it works fine).
when using Microsoft.Azure.ActiveDirectory.GraphClient 2.0.1
try { AuthenticationContext authContext = new AuthenticationContext(authority); ClientCredential credential = new ClientCredential(clientId, appKey); ActiveDirectoryClient graphConnection = new ActiveDirectoryClient(new Uri(new Uri(graphResourceId),tenant), async () => { var result = authContext.AcquireToken(graphResourceId, credential); return result.AccessToken; }); Microsoft.Azure.ActiveDirectory.GraphClient.User newAzureUser = new Microsoft.Azure.ActiveDirectory.GraphClient.User(); newAzureUser.GivenName = User.FirstName; newAzureUser.Surname = User.LastName; newAzureUser.UserPrincipalName = User.FirstName + "." + User.LastName+"@"+tenant; newAzureUser.DisplayName = User.FirstName + User.LastName; newAzureUser.AccountEnabled = true; newAzureUser.PasswordProfile = new PasswordProfile { ForceChangePasswordNextLogin = true, Password = User.UserPassword }; graphConnection.Users.AddUserAsync(newAzureUser).Wait();
At this point, an exception is raised with an 500 internal server error, no hint as to what's wrong.
If I revert to the 1.0.3 version and use:
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority); ClientCredential credential = new ClientCredential(clientId, appKey); result = authContext.AcquireToken(graphResourceId, credential); Guid ClientRequestId = Guid.NewGuid(); GraphSettings graphSettings = new GraphSettings(); graphSettings.ApiVersion = GraphConfiguration.GraphApiVersion; GraphConnection graphConnection = new GraphConnection(result.AccessToken, ClientRequestId, graphSettings); graphConnection.Add(user);
Then it all goes through nicely. Now while I could obviously use the older version, I would prefer to use the latest to ensure tech debt is minimised. Is there something I have done that is stupid and cant spot myself, or is the problem a little deeper?
Thanks in advance