title: IdentityServer4 - missing claims from Google
body: <p><strong>TLDR;</strong> In the context of using IdentityServer4</p>
  
  <ol>
  <li>How do you get email address and hd claims from Google? </li>
  <li>How do you get User.Identity.Name to be populated? </li>
  </ol>
  
  <hr>
  
  <p>I have worked through the IdentityServer <a href="https://identityserver4.readthedocs.io/en/release/quickstarts/0_overview.html" rel="nofollow noreferrer">quickstarts</a> and have a working MVC client talking to a IdentityServer instance (apologies if using the wrong terminology). I am using External Authentication (Google) and do not have anything mildly complicated such as local logins / database etc. I am <em>not</em> using ASP.NET Identity. This is all working just fine.</p>
  
  <p>I can successfully authenticate in my MVC app and the following code produces the claims in the screenshot below:</p>
  
  <pre><code>@foreach (var claim in User.Claims)
  {
      &lt;dt&gt;@claim.Type&lt;/dt&gt;
      &lt;dd&gt;@claim.Value&lt;/dd&gt;
  }
  &lt;dt&gt;Identity.Name&lt;/dt&gt;
  &lt;dd&gt;&amp;nbsp;@User.Identity.Name&lt;/dd&gt;
  
  &lt;dt&gt;IsAuthenticated&lt;/dt&gt;
  &lt;dd&gt;@User.Identity.IsAuthenticated&lt;/dd&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eVyaQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eVyaQ.png" alt="enter image description here"></a></p>
  
  <h2>Questions:</h2>
  
  <ol>
  <li>I cannot retrieve extra claims (right term?) from Google. Specifically 'hd' or even 'email' - note that they don't show up in the claims in the above screenshot. How do I get the email address and hd claims from Google? What am I missing or doing wrong?</li>
  <li>Note that the output of User.Identity.Name is empty. Why is this and how do I get this populated? This seems to be the only property of User.Identity that isn't set.</li>
  </ol>
  
  <hr>
  
  <p>My setup is as follows - you can see the output of this as above:</p>
  
  <h2>Client (MVC)</h2>
  
  <p><em>In Startup.cs, ConfigureServices</em></p>
  
  <pre><code>JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
  
  services.AddAuthentication(options =&gt;
  {
      options.DefaultScheme = "Cookies";
      options.DefaultChallengeScheme = "oidc";
  })
  .AddCookie("Cookies")
  .AddOpenIdConnect("oidc", options =&gt;
  {
      options.SignInScheme = "Cookies";
      options.Authority = Configuration["App:Urls:IdentityServer"];
      options.RequireHttpsMetadata = false;
      options.Resource = "openid profile email";
      options.Scope.Add("openid");
      options.Scope.Add("profile");
      options.Scope.Add("email");
      options.Scope.Add("domain");
      options.ClientId = "ctda-web";
      options.SaveTokens = true;
      options.GetClaimsFromUserInfoEndpoint = true;
  });
  </code></pre>
  
  <h2>Identity Server</h2>
  
  <p><em>Client definition</em></p>
  
  <pre><code>// OpenID Connect implicit flow client (MVC)
  new Client
  {
      ClientId = "ctda-web",
      ClientName = "Company To Do Web App",
      AllowedGrantTypes = GrantTypes.Implicit,
      EnableLocalLogin = false,
  
      // where to redirect to after login
      RedirectUris = { "http://localhost:53996/signin-oidc" },
  
      // where to redirect to after logout
      PostLogoutRedirectUris = { "http://localhost:53996/signout-callback-oidc" },
  
      AllowedScopes = new List&lt;string&gt;
      {
          IdentityServerConstants.StandardScopes.OpenId,
          IdentityServerConstants.StandardScopes.Profile,
          IdentityServerConstants.StandardScopes.Email,
          "domain"
      }
  }
  </code></pre>
  
  <p><em>IdentityResource definition</em></p>
  
  <pre><code>return new List&lt;IdentityResource&gt;
  {
      new IdentityResources.OpenId(),
      new IdentityResources.Profile(),
      new IdentityResources.Email(),
      new IdentityResource
      {
          Name = "domain",
          DisplayName = "Google Organisation",
          Description = "The hosted G Suite domain of the user, if part of one",
          UserClaims = new List&lt;string&gt; { "hd"}
      } 
  };
  </code></pre>