J'ai créé un nouveau projet à l'aide de Visual Studio 2015 et activé l'authentification à l'aide de comptes professionnels et scolaires sur Azure Active Directory. Voici à quoi ressemble la fonction de configuration générée:
app.UseStaticFiles();
app.UseCookieAuthentication();
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = Configuration["Authentication:AzureAd:ClientId"],
ClientSecret = Configuration["Authentication:AzureAd:ClientSecret"],
Authority = Configuration["Authentication:AzureAd:AADInstance"] + Configuration["Authentication:AzureAd:TenantId"],
CallbackPath = Configuration["Authentication:AzureAd:CallbackPath"],
ResponseType = OpenIdConnectResponseType.CodeIdToken
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Voici le code d'action rudimentaire essayant d'obtenir des groupes d'utilisateurs:
public async Task<IActionResult> Index()
{
var client = new HttpClient();
var uri = "https://graph.windows.net/myorganization/users/{user_id}/$links/memberOf?api-version=1.6";
var response = await client.GetAsync(uri);
if (response.Content != null)
{
ViewData["response"] = await response.Content.ReadAsStringAsync();
}
return View();
}
De quoi ai-je besoin pour utiliser ou modifier ce code pour m'assurer de pouvoir obtenir des groupes d'utilisateurs? Actuellement, la réponse est:
{
"odata.error":{
"code":"Authentication_MissingOrMalformed",
"message":{
"lang":"en",
"value":"Access Token missing or malformed."
},
"values":null
}
}