title: WEB API 2 : get profile data during oauth RegisterExternal (facebook)
body: <p>In the out of the box ASP.NET WEB API oAuth implementation after a new user calls:</p>
  
  <pre><code>GET api/Account/ExternalLogins?returnUrl=%2F&amp;generateState=true
  </code></pre>
  
  <p>user is redirected to external log in (in my case Facebook) resulting in a token that they use for registration (out of the box code bellow)</p>
  
  <pre><code>        // POST api/Account/RegisterExternal
          [OverrideAuthentication]
          [HostAuthentication(DefaultAuthenticationTypes.ExternalBearer)]
          [Route("RegisterExternal")]
          public async Task&lt;IHttpActionResult&gt; RegisterExternal([FromBody]RegisterExternalBindingModel model)
          {
              if (!ModelState.IsValid)
              {
                  return BadRequest(ModelState);
              }
  
              ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);
  
              if (externalLogin == null)
              {
                  return InternalServerError();
              }
  
              IdentityUser user = new IdentityUser
              {
                  UserName = model.UserName
              };
              user.Logins.Add(new IdentityUserLogin
              {
                  LoginProvider = externalLogin.LoginProvider,
                  ProviderKey = externalLogin.ProviderKey
              });
              IdentityResult result = await UserManager.CreateAsync(user);
              IHttpActionResult errorResult = GetErrorResult(result);
  
              if (errorResult != null)
              {
                  return errorResult;
              }
  
              return Ok();
          }
  </code></pre>
  
  <p>During RegisterExternal I want to populate another database using the data on their Facebook (first name, last name, email, friends, ext..)</p>
  
  <p>The Bearer token I am getting during registration can <strong>not</strong> simply be called as such:</p>
  
  <pre><code>var accessToken = "token from header";
  var client = new FacebookClient(accessToken);
  </code></pre>
  
  <p>So from what I understand I need to modify Startup.Auth with claims for this data as i have done by adding:</p>
  
  <pre><code>        var facebookProvider = new FacebookAuthenticationProvider()
          {
              OnAuthenticated = (context) =&gt;
              {
                  // Add the email id to the claim
                  context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email));
                  return Task.FromResult(0);
              }
          };
          var options = new FacebookAuthenticationOptions()
          {
              AppId = "xxxxxxxxxxxxxxxxx",
              AppSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
              Provider = facebookProvider
          };
          options.Scope.Add("email");
          options.Scope.Add("user_friends");
          options.Scope.Add("public_profile");
          app.UseFacebookAuthentication(options);
  </code></pre>
  
  <p>But then how do I go about fetching that data in my RegisterExternal method?</p>