How to get extra fields using Facebook provider in ASP.NET Core RC1?

I use the RC1 kernel for ASP.NET (and I can’t upgrade to the non-RC2 nightly collections because of the lack of VS support in RC2).

I'm trying to get additional fields from Facebook ( first_name, last_name, emailand significant_other).

I used the code suggested by Github :

app.UseFacebookAuthentication(options =>
{
    options.AppId = Configuration["Authentication:Facebook:AppId"];
    options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
    options.Scope.Add("email");
    options.Scope.Add("user_relationships");
    options.BackchannelHttpHandler = new HttpClientHandler();
    options.UserInformationEndpoint = 
        "https://graph.facebook.com/v2.5/me?fields=id,email,first_name,last_name,significant_other";

This solution really returns the emailuser, but with errors first_name, last_nameand significant_other(and any other field that I tried, except for the name, identifier and email).

, FB? Facebook, ASP.NET Core ( , RC1).

, .

+4
2

Facebook (first_name, last_name, email significant_other). , first_name, last_name significant_other ( , , , ).

RC1 Facebook , , , :

app.UseFacebookAuthentication(options => {
    options.Events = new OAuthEvents {
        OnCreatingTicket = context => {
            var surname = context.User.Value<string>("last_name");
            context.Identity.AddClaim(new Claim(ClaimTypes.Surname, surname));

            return Task.FromResult(0);
        }
    };
});

RC2 , : https://github.com/aspnet/Security/issues/688.


, FB? Facebook, ASP.NET Core ( , RC1).

SaveTokensAsClaims / ( RC1). , PR, : https://github.com/aspnet/Security/pull/257.

app.UseFacebookAuthentication(options => {
    options.SaveTokensAsClaims = true;
});

, :

var token = User.FindFirst("access_token")?.Value

: RC2 , , : https://github.com/aspnet/Security/pull/698.

+7

@Pinpoint: SaveTokensAsClaims. SaveTokens option:

, Http.Authentication.AuthenticationProperties . false, cookie.

, Claims. AuthenticationTokenExtensions

, GetToken, AuthenticationTokenExtensions. , :

var token = await HttpContext.Authentication.GetTokenAsync("access_token");

github:

+1

All Articles