RE: How to integrate a Canvas or Model driven app with Mpos/Cpos
I'm no expert but suggestions.
If you aim to do this without any customization I can only think of one thing. Change the URL to be the Sign out URL with a redirect to your App. Everytime a user would be clicking any of the buttons they would be sent to the sign out page first. It's not a solve all or good solution as it could be the same user trying to open the app a second time.
An example of this is how when you activate a CPOS you get sent to the sign out page and then sent back to the CPOS afterwards. I can't guarantee it will work, because there are limits on how you can redirect after a sign out.
If you want to consider customizations. You could have a PreOpenUrlTrigger. The options value provided includes the URI trying to be opened and this way you can tell if you need to have logic verifying the user or not.
For the verification scenario I would put a static variable on the class that holds the currently signed in user or an empty string if no actions have been taken yet.
There are two ways to handle the sign out. Either attempt to use code to open the sign out page in a new window. Or force the user to press a separate button called sign out that have the correct uri.
If you go with a separate button then the first thing you need to do is send a message to the user and then cancel the operation with the return response. Once the user press the sign out button you can then set the variable to "Signed out". When a user later press a button for model driven app set the variable to the worker id (As long as the previous value was Signed out).
If the user closes the pos then the variable value is lost. So a newly instantiated value should not be "Signed out" as you want to enforce a sign out incase the pos was closed while a user was signed in.
While you can force the user to use the "sign out button" this way, this will not enforce that the sign out is successful. Afterall you have no data back from the browser that the button open.
I hope this could be somewhat useful to you and finding a way forward.