Crie um novo usuário no Azure Active Directory (B2C) com a API do Graph, usando a solicitação de postagem http
Anteriormente, adicionei usuários programaticamente usando o ADAL (Active Directory Authentication Library), mas agora preciso definir "signInNames" (= email do usuário) e isso não parece possível com o ADAL (informe-me se estiver errado) .
Agora estou tentando adicionar um novo usuário (conta local) programaticamente usando HTTP POST, seguindoa documentação no MSDN.
//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 = "[email protected]";
// 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;
}
}
Mas não tenho sucesso, obtendo esta resposta:
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content:....}
Alguma idéia do que devo fazer? Consegui usar o script Powershell, mas preciso fazer isso no meu aplicativo C #.