# Calling perspective message handler from onAuthChallengeCompleted

**URL:** <https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 30, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384 "2024-08-30T17:07:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [August 30, 2024, 5:07pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/1 "2024-08-30T17:07:55Z")

</div>

Hi,

I am having problems getting a message handler to react from an authentication challenge complete script.

The message handler type is "saveRecord", it is saving info to a database after an authentication challenge. It is used in a few places, so it is a message handler attached to the root of my main view in the project. I have widened its scope to Session, Page, and View.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/3/933fef55363a6109a4c6eb49e8ca583e4c872203.png)

Assuming authentication is successful, I execute:

```python
		logger.info("user = {} roles = {}".format(user, roles))
		#Success - save the record		
		system.perspective.sendMessage("saveRecord", sessionID = session.info["id"], scope = "session")
		logger.info("Made it past the save")

```

I have confirmed that sessionID s match, but ithe message handler doesn't fire. I can see that it made it past the call because I see "Made it past the save" in the log. But no saving happens, and no log messages that happen every other time I successfully fire the message handler under other circumstances.

Any ideas?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 30, 2024, 5:46pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/2 "2024-08-30T17:46:17Z")

</div>

> [@ken.maze](#):
>
> Any ideas?

The message handler is on a view in the project, but Authentication happens prior the view being open. Therefore the message isn't handled.

I would recommend using a Session Message Handler.

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [August 30, 2024, 6:39pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/3 "2024-08-30T18:39:28Z")

</div>

OK, doing a little checking, it looks like the view _isn't_ there during the challenge, or at least i have found it restarts after the challenge is done.

I could move it, but it kind of shoots my scope, because the data I want to record is in the view. Or at least some of it, most of it is in session custom properties. I should be able to get everything I need to save into there

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [September 5, 2024, 5:08pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/4 "2024-09-05T17:08:37Z")

</div>

OK, I've got it, but...

I have a view with info displayed in a table and a couple of textboxes. I want to do an authentication challenge, and if it fails, I want to take the user back to the view with all of the information still filled in. I figured out how to do that, based on taking away persistence in some elements, etc

But I would also like to have a popup saying something like "Your credentials don't have privilege to do this". I'm having problems with communicating between this Authentication Challenge session and the view/page that doesn't exist during this challenge script. How would I get it to make a popup, or just communicate with the calling page that is no longer there, but will be momentarily?

Thanks

---

<div class="post-metadata">

**Author:** ![DNice](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@DNice](https://forum.inductiveautomation.com/u/DNice)\
**Post date:** [September 5, 2024, 5:49pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/5 "2024-09-05T17:49:22Z")

</div>

Have you looked into security settings on your button (or whatever object) you are using? This is a built in feature and limits an action based on roles/zones.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/92a08aaa1150d2980b45c55f4f7fd77543df3668.png)

If they done have rights they will see this popup:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/3/a3b076320aee8b7bdb4de12957d706d349bff548.png)

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [September 5, 2024, 7:55pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/6 "2024-09-05T19:55:29Z")

</div>

Yes, good idea, that would solve that problem, I wouldn't have thought of that.

But this is an authentication challenge where an operator is already logged in, and system.perspective.authenticationChallenge is called. This is so when there is an error, the operator is stopped and a supervisor has to log in to show that they saw it, therefore the username of the person about to authenticate is not known.

So, when this kind of challenge occurs, it would be good to be able for the view that is being used to be able to react to the result of the authentication challenge, whether with a popup or an error box built into the view.

As it is, the authentication challenge event is called in session scope, and I don't see how to get information back from that scope to the calling scope. Perhaps through session properties, but every time I think about doing that it becomes more and more complex in my head and seems like it would turn into a horrible can of worms.

---

<div class="post-metadata">

**Author:** ![ken.maze](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ken.maze/32/85876_2.png) [@ken.maze](https://forum.inductiveautomation.com/u/ken.maze)\
**Post date:** [September 6, 2024, 9:28pm UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/7 "2024-09-06T21:28:49Z")

</div>

I did end up doing it with a session variable. Since the view restarts when the auth challenge is done, I left a message for it from the authentication challenge. Kinda janky but it works

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 7, 2024, 7:20am UTC](https://forum.inductiveautomation.com/t/calling-perspective-message-handler-from-onauthchallengecompleted/95384/8 "2024-09-07T07:20:50Z")

</div>

Use a gateway message event instead of a perspective message event.

You can send these messages with `system.util.sendMessage` instead of `system.perspective.sendMessage`. You can even use `sendRequest` to get a response back and confirm that the recording was successful, if that matters.
