In Gateway : Config- Security- User Sources, I set two user Roles:
Operator and TeamLeader
In Vision,I add a button. I wish when Operator users click it, don't execute PLC commands. Must need TeamLeader Roles User authorizes it. When TeamLeader users authorizes it,then Operator users can execute PLC commands.
such as double authentication....
If you want an easier client based solution, change the script on the authenticate button to toggle the enabled property of the button that executes PLC commands. If the only role that needs to select it is Operator, put additional security on the main button.
If you want a universal solution, set the enabled property binding to a tag, then set your authenticate button to toggle the value of the tag.
I would be using tag security for this. Set the write permissions on your tag(s) to require the security levels needed (eg the roles needed - you'll need to first add your roles under the security levels tab in the gateway config page). This will centralise your permissions requirement and avoid any potential for having different permissions if control is given on different Windows.
For users to know if they have control, as @Tyler_Shoemake said, bind to the button's enabled property. Bind to the tag's canWrite property to read if the user has write permissions. I usually also add an icon with a tooltip to let the user know why they don't have access. Then they have the option to login via the standard login button to gain control
I think the issue here is that tag security only works for the logged in user. I believe the OP is using a workflow that requires an operator to be logged in to a session, and when they need to run a couple of functions on the system, a supervisor has to authorise the actions individually. The Supervisor account can never be logged into because the operator would then have all the supervisor access, so the authentication challenge is done to verify that the supervisor has approved an action requiring elevated access. Thus the operator is still logged into the system on the lower privileged account, but the single action has been performed at a higher level of access.
This is the system I have used for Perspective, for exactly this task. I have not seen it done in Vision before.
The former to verify the supervisor's identity with their password, and the latter to obtain their roles to ensure they have the appropriate privileges.
For others, it helps to know that orange button = "Unload Truck" and bottom button = "Authorise"
I misunderstood what these buttons were, but given this, you definitely shouldn't use a global tag to store the authorised state, since this is global and hence will give other clients access to the Unload Truck button if another client authorises it.
It would be far simpler to have a single button the operator presses, "Unload Truck", and then have it prompt for the team leader to enter their user/pass, and if valid and has the correct role, write to the PLC tag. Unless you also want the operator to validate their credentials as well? Could you stack the validations in that case, and have the operator validate theirs, then the team leader's? Then you don't need to worry about caching any validation results and worrying about clearing them out on timeout.
Alternatively, if you do need/want to have two buttons, maybe a popup is better, and use a custom prop on the popup to store the validation result(s), then clear it upon popup exit. Then you could also make this more of a standard component that you could reuse elsewhere whenever you need authorisation to action something (I would recommend making this a standard component regardless of method actually)