Create JSL functions to interact with Keychain on mac, Credential Store on Windows, and the Secret Service API on Linux. This could be very similar to the open source keyring R package.
This would provide a better solution for this post: save passwords securely and the script here: Set and get credentials in the Credential Manager via PowerShell on Windows