Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get access token (using ADAL)
- var authenticationContext = new AuthenticationContext(AuthString, false);
- var clientCred = new ClientCredential(ClientId, ClientSecret);
- var authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, clientCred);
- var token = authenticationResult.Result.AccessToken;
- //HTTP POST CODE
- const string mail = "new@email.com";
- // Create a new user object.
- var user = new CustomUser
- {
- accountEnabled = true,
- country = "MS",
- creationType = "LocalAccount",
- displayName = mail,
- passwordPolicies = "DisablePasswordExpiration,DisableStrongPassword",
- passwordProfile = new passwordProfile { password = "jVPmEm)6Bh", forceChangePasswordNextLogin = true },
- signInNames = new signInNames { type = "emailAddress", value = mail }
- };
- var url = "https://graph.windows.net/" + TenantId + "/users?api-version=1.6";
- var jsonObject = JsonConvert.SerializeObject(user);
- using (var client = new HttpClient())
- {
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
- var response = client.PostAsync(url,
- new StringContent(JsonConvert.SerializeObject(user).ToString(),
- Encoding.UTF8, "application/json"))
- .Result;
- if (response.IsSuccessStatusCode)
- {
- dynamic content = JsonConvert.DeserializeObject(
- response.Content.ReadAsStringAsync()
- .Result);
- // Access variables from the returned JSON object
- var appHref = content.links.applications.href;
- }
- }
- {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content:....}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement