Windows Authentication in ABP.io framework

  Kiến thức lập trình

I want to implement Windows Authentication into ABP.io framework project. I want to get Windows user and login that user, if user is added into ABP.io database.

I’m using version 6.0.3 with .NET Core, MS SQL Server and Angular UI.

I’m using Authorization Code Flow, so I’ve overriden login page and created CustomLoginModel that extends LoginModel. In that model I’ve implemented Windows login like this:

var windowsUser = WindowsIdentity.GetCurrent().Name;

if (windowsUser.Contains('\'))
{
    windowsUser = windowsUser.Split('\')[1];
}

await IdentityOptions.SetAsync();

var user = await UserManager.FindByNameAsync(windowsUser);

if (user == null)
{
    Alerts.Danger($"User {windowsUser} not found!");
    return Page();
}

if (await UserManager.IsLockedOutAsync(user))
{
    Alerts.Warning(L["UserLockedOutMessage"]);
    return Page();
}

await SignInManager.SignInAsync(user, LoginInput.RememberMe);

await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext()
{
    Identity = IdentitySecurityLogIdentityConsts.Identity,
    Action = "Succeeded",
    UserName = user.UserName
});

return RedirectSafely(ReturnUrl, ReturnUrlHash);

I’m facing issue that it works when I’m running it locally and stops working when I deploy it on IIS. On IIS I’m getting user from application pool. Is there any other way to get Windows user?

New contributor

togor.235 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT