cordova plugin add https://github.com/Telerik-Verified-Plugins/Keychain-Sharing --variable KEYCHAIN_ACCESS_GROUP=com.your.sharedbundleid
appbuilder plugin add "Keychain Sharing"
The Keychain Sharing plugin allows you to securely store data in the iOS Keychain and share it with your other apps.
This plugin offers basic get, set and remove functions to interact with the iOS Keychain. Data is stored as key-value pairs inside a 'service'. You can think of a service as a bucket in which your key-value pairs are stored.
// prepare a few variables var key = "myKey"; var service = "myService"; // .. and a few functions function onSuccess(msg) { alert("OK: " + msg); } function onError(msg) { alert("NOK: " + msg); } // if a value is being set for a key which was already present in the service, the value is overwritten function set(val) { KeychainSharing.set({key: key, val: val, service: service}, onSuccess, onError); } // if no value is found, null is returned function get() { KeychainSharing.get({key: key, service: service}, onSuccess, onError); } // say bye bye to your key (and its value) function del() { KeychainSharing.remove({key: key, service: service}, onSuccess, onError); }
Imagine you have a free app and you want users to upgrade to your fancy PRO version. How nice would it be if the user can install your PRO app and would be logged in without.. ehm, logging in. That's one of the features you can use Keychain Sharing for.
This plugin adds the so-called "Keychain Sharing Entitlement" to your app. As long as the "Bundle Seed ID" (see below) of both apps is the same, and you've configured the same value for the KEYCHAIN_ACCESS_GROUP variable (see below as well), both apps can read and write in the same Keychain sandbox.
In order to share keychain information between applications, you need to setup a shared keychain access group. Before the sharing would work correctly, both apps need to have provisioning based on the same bundle seed ID.
The bundle seed ID is part of the App ID; each App ID consists of the universally unique 10 character "Bundle Seed ID" prefix generated by Apple and a "Bundle Identifier" suffix that is entered by a Team Admin in the Provisioning Portal. An example App ID would be: 7D438K8233.com.telerik.app1. An easy way to make sure the Bundle Seed ID is identical for both apps is signing them with the same wildcard provisioning profile, com.telerik.* in our case.
Sharing the same Bundle Seed ID is not all it takes for your apps to be able to share data via the Keychain. They also need to use the same "Keychain Access Group". This plugin allows you to pass this in during installation.
Using the Cordova CLI you pass it in as a variable when installing the plugin. In AppBuilder you configure it after installing the plugin in the plugin settings. In both cases it's recommended to set the value to one of the bundle ID's of your apps. So if your apps with bundle ID com.telerik.app1 and com.telerik.app2 need to share data, set the KEYCHAIN_ACCESS_GROUP variable to com.telerik.app1 for both apps.