Browse Source

Merge pull request #8419 from abpframework/maliming/windows-login

Refactor ProcessWindowsLoginAsync.
pull/8655/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
c93afc6eb5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs

56
modules/account/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/IdentityServerSupportedLoginModel.cs

@ -189,46 +189,32 @@ namespace Volo.Abp.Account.Web.Pages.Account
return await base.OnPostExternalLogin(provider); return await base.OnPostExternalLogin(provider);
} }
private async Task<IActionResult> ProcessWindowsLoginAsync() protected virtual async Task<IActionResult> ProcessWindowsLoginAsync()
{ {
var result = await HttpContext.AuthenticateAsync(AccountOptions.WindowsAuthenticationSchemeName); var result = await HttpContext.AuthenticateAsync(AccountOptions.WindowsAuthenticationSchemeName);
if (!(result?.Principal is WindowsPrincipal windowsPrincipal)) if (result.Succeeded)
{ {
return Challenge(AccountOptions.WindowsAuthenticationSchemeName); var props = new AuthenticationProperties()
}
var props = new AuthenticationProperties
{
RedirectUri = Url.Page("./Login", pageHandler: "ExternalLoginCallback", values: new { ReturnUrl, ReturnUrlHash }),
Items =
{ {
{"scheme", AccountOptions.WindowsAuthenticationSchemeName}, RedirectUri = Url.Page("./Login", pageHandler: "ExternalLoginCallback", values: new {ReturnUrl, ReturnUrlHash}),
} Items =
}; {
{
var identity = new ClaimsIdentity(AccountOptions.WindowsAuthenticationSchemeName); "LoginProvider", AccountOptions.WindowsAuthenticationSchemeName
identity.AddClaim(new Claim(JwtClaimTypes.Subject, windowsPrincipal.Identity.Name)); },
identity.AddClaim(new Claim(JwtClaimTypes.Name, windowsPrincipal.Identity.Name)); }
};
//TODO: Consider to add Windows groups the the identity
//if (_accountOptions.IncludeWindowsGroups) var id = new ClaimsIdentity(AccountOptions.WindowsAuthenticationSchemeName);
//{ id.AddClaim(new Claim(ClaimTypes.NameIdentifier, result.Principal.FindFirstValue(ClaimTypes.PrimarySid)));
// var windowsIdentity = windowsPrincipal.Identity as WindowsIdentity; id.AddClaim(new Claim(ClaimTypes.Name, result.Principal.FindFirstValue(ClaimTypes.Name)));
// if (windowsIdentity != null)
// { await HttpContext.SignInAsync(IdentityConstants.ExternalScheme, new ClaimsPrincipal(id), props);
// var groups = windowsIdentity.Groups?.Translate(typeof(NTAccount));
// var roles = groups.Select(x => new Claim(JwtClaimTypes.Role, x.Value)); return Redirect(props.RedirectUri);
// identity.AddClaims(roles); }
// }
//}
await HttpContext.SignInAsync(
IdentityServer4.IdentityServerConstants.ExternalCookieAuthenticationScheme,
new ClaimsPrincipal(identity),
props
);
return RedirectSafely(props.RedirectUri); return Challenge(AccountOptions.WindowsAuthenticationSchemeName);
} }
} }
} }

Loading…
Cancel
Save