How to re-sign an app on a Mac

I recently changed the Info.plist file for nextcloud.app so that it would stop using the discrete GPU. However, this seemed to introduce a new issue where, apparently due to my changes to the Info.plist, the code signature for the app was no longer valid:

This meant that the app was no longer allowed to access the Keychain, and the only way I found out was by inspecting system.log in Console.app. Thus nextcloud.app would ask me for a login every time it started - the primary symptom.

While waiting for the Nextcloud developers to work on the aforementioned issue, an interim fix is as follows: