0

We have an ask that we need to login user each login attempt to sitecore. We are able to do that for success scenario but for failure its not done.

If we are not using IdentityServer login, but Sitecore basic login mechanism then by having custom processor for Sitecore.Pipelines.LoggingIn.CheckClientUser able do that task successfully.

But if have middleware as IdentityServer then not able to track failure case, as code written under these pipeline don't executes, i have tried each processor of <owin.cookieAuthentication.signIn> pipeline but nothing worked.

Any idea how we can achieve it?

1
  • If you use a middleware, you will be redirected to an external system to do your login. If this system does not have an option to log failed requests you cannot access that. Depending on the external system you might or might not be able to access that information.
    – Danny Paul
    Commented Mar 6 at 9:13

1 Answer 1

0

I got it resolved now, details are given in https://rinkusitecore.wordpress.com/2024/04/14/sitecore-logging-user-login-attempts-for-success-failure-scenario/

Logging Successful Login

Its striaghtforward, for it used a patch after CookieAuthentication.SignIn.UpdateUserProperties processor and wrote code in its process method. If you are not using IdentityServer as middleware due to any reason(e.g. some issue came in its configuration) but OOTB basic authentication, then just hook into “Sitecore.Pipelines.LoggingIn.CheckClientUser” processor(e.g. use your custom processor to check authentication and then you can write your logging code in it). At identity server we have created a custom JS file(loginattemptlogger.js), in \sitecore\Sitecore.Plugin.IdentityServer\Content\lib) and placed below code:

Then we include this file in LayoutFile which shows login UI (\sitecore\Sitecore.Plugin.IdentityServer\Views\Shared)

Here custom OwinCookieAuthenticationSignin class is inherited from SignInProcessor.

This process also works whether we use IdentityServer as middleware or using basic authentication.

Logging Failure Login

As we are using default owin authentication (which intern uses claims) so somehow not able to track failure case, i have tried with placing processor at each different step on Sitecore.Pipelines.LoggingIn (LoggedIn won’t won’t work as we need to track failure case) Now everything looks good but it was not the case as when tried to call our api from this JS file we got CSP error.

To get rid of it, we had to do some update on IdentyServer config file (/sitecore/Sitecore.Plugin.IdentityServer/Config/identityServer.xml) and replaced its ContentSecurityPolicy section with

default-src 'self'; object-src 'none'; style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; frame-ancestors {AllowedCorsOrigin:Sitecore}; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self'; connect-src 'self' {AllowedCorsOrigin:Sitecore}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.