title: Trying to get user profile info from Azure using Graph
body: <p>I am trying to get user profile info from Azure using Graph. If I download one of the samples, it works, but I can't figure it out for a real app. I haven't had any issues registering the app in the new app portal, but I am unable to successfully view the user profile data. Here's some code:</p>
  
  <pre><code>[Authorize]
  public async Task&lt;ActionResult&gt; About() {
      try {
          string signedInUserID = ClaimsPrincipal
              .Current
              .FindFirst(ClaimTypes.NameIdentifier)
              .Value;
  
          TokenCache userTokenCache = new MSALSessionCache(signedInUserID, this.HttpContext)
              .GetMsalCacheInstance();
  
          ConfidentialClientApplication cca = new ConfidentialClientApplication(
              clientId,
              redirectUri,
              new ClientCredential(appKey),
              userTokenCache,
              null);
  
          if (cca.Users.Count() &gt; 0) {
  
              string[] scopes = { "User.Read" };
  
              AuthenticationResult result =
                  await cca.AcquireTokenSilentAsync(scopes, cca.Users.First());
  
              HttpClient hc = new HttpClient();
              hc.DefaultRequestHeaders.Authorization =
                  new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", result.AccessToken);
  
              HttpResponseMessage hrm = await hc.GetAsync("https://graph.microsoft.com/v1.0/me/");
              string rez = await hrm.Content.ReadAsStringAsync();
              ViewBag.Message = rez;
  
              ViewBag.UserName = ClaimsPrincipal.Current.FindFirst("preferred_username").Value;
  
          } else { }
          return View();
      } catch (MsalUiRequiredException) {
          ViewBag.Relogin = "true";
          return View();
      } catch (Exception eee) {
          ViewBag.Error = "An error has occurred. Details: " + eee.Message;
          return View();
      }
  }
  </code></pre>
  
  <p>After logging in, I get nothing in the view:</p>
  
  <pre><code>@{
      ViewBag.Title = "About";
  }
  &lt;h2&gt;@ViewBag.Title.&lt;/h2&gt;
  &lt;h3&gt;@ViewBag.Message&lt;/h3&gt;
  
  &lt;p&gt;Use this area to provide additional information.&lt;/p&gt;
  @{
      if (ViewBag.Error != null)
      {
          &lt;p class="red"&gt;Error: @ViewBag.Error&lt;/p&gt;
      }
  }
  
  &lt;div&gt;Name: @ViewBag.UserName&lt;/div&gt;
  &lt;div&gt;ObjectId: @ViewBag.ObjectId &lt;/div&gt;
  &lt;div&gt;Given Name: @ViewBag.GivenName &lt;/div&gt;
  &lt;div&gt;Surname: @ViewBag.Surname &lt;/div&gt;
  &lt;div&gt;UPN: @ViewBag.UPN&lt;/div&gt;
  &lt;div&gt;Home phone: @ViewBag.HomePhone&lt;/div&gt;
  &lt;div&gt;Mobile phone: @ViewBag.MobileNumber&lt;/div&gt;
  &lt;div&gt;Other phone: @ViewBag.OtherPhone&lt;/div&gt;
  &lt;div&gt;User Data: @ViewBag.UserData&lt;/div&gt;
  </code></pre>