Skip to content

Instantly share code, notes, and snippets.

@vman
Created May 8, 2015 20:48
Show Gist options
  • Save vman/11dd0131bbbf8803c859 to your computer and use it in GitHub Desktop.
Save vman/11dd0131bbbf8803c859 to your computer and use it in GitHub Desktop.
using (var client = new HttpClient())
{
//Enable signon and read users' profile
using (var request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/beta/me"))
{
request.Headers.Add("Authorization", "Bearer " + token);
request.Headers.Add("Accept", "application/json;odata.metadata=minimal");
using (var response = client.SendAsync(request).Result)
{
if (response.StatusCode == HttpStatusCode.OK)
{
var json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
ViewBag.CurrentUserDisplayName = json["displayName"].ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment