2

Currently i am working on one POC with Identity server4 where i have to show my own login page if windows authentication get failed(in this case i just want to show my own login page and avoid browser login popup .

My question is where to inject my own login page in code? and how application will know windows authentication get failed?If you check below code, first request to AuthenticateAsync always return null and then it call Challenge from else block which ask browser to send Kerberos token and we achieve SSO but now i want to show my own login page if SSO fail. My scenario is exactly similar like this

Anyone know how to achieve this?

  private async Task<IActionResult> ProcessWindowsLoginAsync(string returnUrl)
        {
            // see if windows auth has already been requested and succeeded.
            var result = await HttpContext.AuthenticateAsync(_windowsAuthConfig.WindowsAuthenticationProviderName);
            if (result?.Principal is WindowsPrincipal wp)
            {
                var props = new AuthenticationProperties
                {
                    RedirectUri = Url.Action("Callback"),
                    Items =
                    {
                        { "returnUrl", returnUrl},
                        { "scheme", _windowsAuthConfig.WindowsAuthenticationProviderName}
                    }
                };                
                var id = new ClaimsIdentity(_windowsAuthConfig.WindowsAuthenticationProviderName);
                var claims = await _userStore.GetClaimsForWindowsLoginAsync(wp);
                id.AddClaims(claims);
                _logger.LogDebug("Signing in user with windows authentication.");
                await HttpContext.SignInAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme,new ClaimsPrincipal(id),props);
                return Redirect(props.RedirectUri);
            }
            else
            {
                _logger.LogDebug("Re-triggered windows authentication using ChallengeResult.");
                // Trigger windows auth
                // since windows auth don't support the redirect uri,
                // this URL is re-triggered when we call challenge
                return Challenge(_windowsAuthConfig.WindowsAuthenticationSchemes);
            }
        }
nikhil
  • 51
  • 3

0 Answers0