graph console Azure AD sample–for federated user


To make a federated usera; change the code, adding a subroutine, called when making a user:

    public class Program     {         static void immut(IUser newUser)         {             var bytes = System.Text.Encoding.Default.GetBytes(newUser.UserPrincipalName);             var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();              var hashbytes = md5.ComputeHash(bytes);              var result = new Guid(hashbytes);              var resultstring = result.ToString();             var resultstringbytes = System.Text.Encoding.Default.GetBytes(resultstring);             var base64 = System.Convert.ToBase64String(resultstringbytes);              newUser.ImmutableId = base64;         }  ....            #region Create a new User              IUser newUser = new User();             if (defaultDomain.Name != null)             {                 newUser.DisplayName = "Sample App Demo User (Manager)";                 newUser.UserPrincipalName = Helper.GetRandomString(10) + "@" + defaultDomain.Name;                 newUser.AccountEnabled = true;                 newUser.MailNickname = "SampleAppDemoUserManager";                 newUser.PasswordProfile = new PasswordProfile                 {                     Password = "TempP@ssw0rd!",                     ForceChangePasswordNextLogin = true                 };                 newUser.UsageLocation = "US";                 immut(newUser);                  try                 {                     activeDirectoryClient.Users.AddUserAsync(newUser).Wait();                     Console.WriteLine("\nNew User {0} was created", newUser.DisplayName);                 }                 catch (Exception e)                 {                     Console.WriteLine("\nError creating new user {0} {1}", e.Message,                         e.InnerException != null ? e.InnerException.Message : "");                 }             }     
Advertisements

About home_pw@msn.com

Computer Programmer who often does network administration with focus on security servers. Very strong in Microsoft Azure cloud!
This entry was posted in AAD. Bookmark the permalink.