Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string graphResourceId = "https://graph.windows.net";
- string tenantId = "xxx.onmicrosoft.com";
- AuthenticationContext authContext = new AuthenticationContext("https://login.microsoftonline.com/xxx.onmicrosoft.com");
- ClientCredential credential = new ClientCredential("{clientId}", "{secret}");
- string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
- AuthenticationResult result = await authContext.AcquireTokenSilentAsync(graphResourceId, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
- var accessToken = result.AccessToken;
- Uri servicePointUri = new Uri(graphResourceId);
- Uri serviceRoot = new Uri(servicePointUri, tenantId);
- ActiveDirectoryClient graphClient = new ActiveDirectoryClient(serviceRoot, async () => await Task.FromResult(accessToken));
- var user = new User();
- user.AccountEnabled = true;
- user.DisplayName = "testName";
- user.UserPrincipalName = "testName@xxx.onmicrosoft.com";
- user.MailNickname = "testName";
- user.UsageLocation = "US";
- user.PasswordProfile = new PasswordProfile
- {
- Password = "xxxxxx",
- ForceChangePasswordNextLogin = true
- };
- await graphClient.Users.AddUserAsync(user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement