How to register on Facebook with Owin?

Here is what I am trying to do:

First i create UserManager

var userManager = new UserManager<IdentityUser>(new CustomUserStore());

Since any user is valid, I created CustomUserStoreand modified a methodFindById

public class CustomUserStore : UserStore<IdentityUser>
{
    public override Task<IdentityUser> FindByIdAsync(string userId)
    {
        return Task.Run<IdentityUser>(() =>
        {
            return new IdentityUser
            {
                Id = userId,
                UserName = userId
            };
        });
    }
}

Then I tried to create an identifier

var user = new IdentityUser("anyusername");
var identity = userManager.CreateIdentity(
                   user,
                   DefaultAuthenticationTypes.ApplicationCookie);

Then I tried to use a method SignInfrom IAuthenticationManagerfromOwinContext

HttpContext.Current.GetOwinContext().Authentication.SignIn(
    new AuthenticationProperties
    {
        IsPersistent = true
    }, identity);

Everything works without any exceptions, but when I try to access a simple action with an attribute Authorize, it will not let me see the page as if I was not signed.

[Authorize]
public ActionResult Index()
{
    return View();
}

For more context, I added the full code here:

Why is he not signing?

0
source share
1 answer

FacebookAuthenticationProvider OnAuthenticated - , Sigin .

public async Task<ActionResult> ExternalLoginCallback(string returnUrl)

.

0

Source: https://habr.com/ru/post/1016466/


All Articles