0

everyone

How can I have /administrator/index.php?option=COM_MYCOMPONENT&controller=MYCONTROLLER&task=MYTASK return a "401 Unauthorized" HTTP error instead of redirecting to the administrator login page?

Many thanks.

1 Answer 1

0

In libraries/src/Application/CMSApplication.php you have two events during the login process that trigger plugins relevant to a login failure or unauthenticated user situation and if you were to create a plugin that was triggered by one of these events you could then return the 401.

In the above code search for either onUserLoginFailure or onUserAuthorisationFailure to see where/when your plugin would be triggered and use the most appropriate one to your needs.

2
  • I am using this on a Ajax call from within the administrator. It seems a bit far-fetched to build a plugin just to return a 401 instead of a redirect just for that :( Is there a way to check for the need to login again via Javascript? This is because users tend to go away, leaving the admin page open on a browser, and when they return the session is gone. Dec 9, 2022 at 11:09
  • Perhaps you should ask a new question that better explains what you are doing and what you are trying to achieve and provide some examples of your code and expectations. My answer was for the question asked but from your reply I think you are wanting something a lot more complex than a simple plugin.
    – Irata
    Dec 11, 2022 at 9:10

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.