Previously, I could call info.ExternalIdentity.FindAll("FacebookAccessToken").
In AspNet.Identity version 3, I can't find the access token stored anywhere using the SignInManager. I also can't use FindAll anymore from ExternalIdentity.
Can I still retrieve the Facebook Access Token within my ASP.Net MVC6 project?
You can access the access token by including it in the claims collection.
You have to tap into the mapping of the Facebook response to the ClaimsIdentity object via the FacebookAuthenticationNotifications OnAuthenticated event. In the Startup.cs file:
services.Configure<FacebookAuthenticationOptions>(options =>
{
options.AppId = Configuration["Authentication:Facebook:AppId"];
options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
options.Scope.Add("user_birthday");
options.Notifications = new FacebookAuthenticationNotifications
{
OnAuthenticated = async context => {
var accessToken = context.AccessToken;
var identity = (System.Security.Claims.ClaimsIdentity)context.Principal.Identity;
identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
}
};
});
Then you will be able to find the access token in the ExternalIdentity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With