Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. string graphResourceId = "https://graph.windows.net";
  2. string tenantId = "xxx.onmicrosoft.com";
  3. AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/xxx.onmicrosoft.com");
  4. ClientCredential credential = new ClientCredential("{clientId}", "{secret}");
  5. string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
  6. AuthenticationResult result = await authContext.AcquireTokenSilentAsync(graphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
  7. var accessToken = result.AccessToken;
  8.  
  9.  
  10. Uri servicePointUri = new Uri(graphResourceId);
  11. Uri serviceRoot = new Uri(servicePointUri, tenantId);
  12.  
  13. ActiveDirectoryClient graphClient = new ActiveDirectoryClient(serviceRoot, async () => await Task.FromResult(accessToken));
  14.  
  15. var user = new User();
  16. user.AccountEnabled = true;
  17. user.DisplayName = "testName";
  18. user.UserPrincipalName = "testName@xxx.onmicrosoft.com";
  19. user.MailNickname = "testName";
  20. user.UsageLocation = "US";
  21. user.PasswordProfile = new PasswordProfile
  22. {
  23. Password = "xxxxxx",
  24. ForceChangePasswordNextLogin = true
  25. };
  26.  
  27. await graphClient.Users.AddUserAsync(user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement