in ContosoApp/ViewModels/AuthenticationViewModel.cs [260:286]
private async Task SetUserPhoto(string token)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
string url = "https://graph.microsoft.com/beta/me/photo/$value";
var result = await client.GetAsync(url);
if (!result.IsSuccessStatusCode)
{
return;
}
using (Stream stream = await result.Content.ReadAsStreamAsync())
{
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal, async () =>
{
Photo = new BitmapImage();
await Photo.SetSourceAsync(memoryStream.AsRandomAccessStream());
});
}
}
}
}