Switching user with perspective

Hello I am wondering is there a script to switch users that will work with perspective?

1 Like

Hi @sebastian.zanotto -

You can call call system.perspective.logout which will log the current user out. You can then call system.perspective.login to redirect them to the IdP to login as a new user.

Hello,

I tried to do the method you mentioned above but haven’t had any luck getting it to work.

when I try to call both functions, the screen refreshes and doesn’t log the user out. If I manually logout, then the button will redirect to a login screen. It’s as though only the login function is called before the logout function gets the chance to execute. I’ve tried making this work as a Logout action followed by a Login action, as well as a single script that calls both system.perspective.logout followed by system.perspective.login.

Thanks for any help

I’m assuming your project requires authentication? In this case, isn’t it enough to simply log the user out? The next user will be on the Sign In screen, and they can click the button to login to the IdP.

I would not call the logout and login scripts or actions back to back (in one script or one action sequence) since the process of logging in or out will navigate the user away from the Perspective page and to the IdP. 8.0.10-RC has a fix which prevents any login and logout attempts from happening on the current page once a single login or logout attempt has been invoked. This should prevent the issue you are seeing with the login “overwriting” the logout attempt that was made before it.

Thanks for the quick reply.

Just logging out would likely be enough, but this is a project where we are upgrading a vision project to perspective and want as close to 1 to 1 as possible for the lowest amount of friction for the user. The previous just uses a popup window with a system.security.switchUser call.

Sure, that makes sense. User authentication is one of those areas where Vision and Perspective start to diverge. There is no way to do exactly what system.security.switchUser does in Perspective right now. It’s possible that we can devise a good pattern for this from lessons learned once we really start digging into making Vision IdP-enabled.

Has there been any updates to switching users in perspective? Looking at the System Function Appendix in the user manual, it specifically says not do what has been suggested by @jspecht

You can call call system.perspective.logout which will log the current user out. You can then call system.perspective.login to redirect them to the IdP to login as a new user.

Caution:
Be advised that this function should not be used in the same script, or in the same triggering event as system.perspective.login . Logging in and Logging out should always be triggered by separate events.

1 Like

I believe system.perspective.login() has since been updated to allow for forcing a user to login even if already logged in. I believe this would cover the use case where you want to switch users as they would need to go through the Login process anyway.

# forces log-out and then requires re-authentication, which is essentially equivalent to what chaining
# the functions would have done previously.
system.perspective.login(forceAuth=True)
2 Likes

Is it possible to log in automatically by passing username and password in the script?

No. I believe this is because the authentication is happening through an IdP which could be separate from Ignition itself.

2 Likes