Working pretty roughly on iOS with cordova-plugin-secure-storage.
This commit is contained in:
parent
63c76fe13e
commit
90d321033b
3 changed files with 104 additions and 4 deletions
|
|
@ -72,6 +72,7 @@
|
|||
<plugin name="cordova-plugin-queries-schemes" spec="~0.1.5" />
|
||||
<plugin name="cordova-plugin-firebase" spec="https://github.com/arnesson/cordova-plugin-firebase.git" />
|
||||
<plugin name="cordova-plugin-wkwebview-inputfocusfix" spec="https://github.com/onderceylan/cordova-plugin-wkwebview-inputfocusfix.git" />
|
||||
<plugin name="cordova-plugin-secure-storage" spec="~2.6.8" />
|
||||
<!-- Supported Platforms -->
|
||||
<engine name="ios" spec="~4.5.3" />
|
||||
<engine name="android" spec="~6.3.0" />
|
||||
|
|
|
|||
93
src/js/services/secureStorageService.js
Normal file
93
src/js/services/secureStorageService.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('secureStorageService', function($log, appConfigService, platformInfo) {
|
||||
var root = {};
|
||||
|
||||
var ssIsReady = false;
|
||||
var ssInitialisationFailed = false;
|
||||
var pending = [];
|
||||
|
||||
var ss = new cordova.plugins.SecureStorage(
|
||||
function () {
|
||||
console.log('ss Success');
|
||||
ssIsReady = true;
|
||||
for (var i = 0; i < pending.length; i++) {
|
||||
pending[i]();
|
||||
}
|
||||
pending = [];
|
||||
},
|
||||
function (error) {
|
||||
console.log('ss Error ' + error);
|
||||
ssInitialisationFailed = true;
|
||||
},
|
||||
appConfigService.packageNameId);
|
||||
|
||||
|
||||
|
||||
root.get = function(key, cb) {
|
||||
$log.debug('secureStorageService.get()');
|
||||
if (!ssIsReady) {
|
||||
$log.debug("ss not ready.");
|
||||
if (ssInitialisationFailed) {
|
||||
$log.debug("returning error because initialisation failed.");
|
||||
cb(new Error("Secure storage initialisation failed."));
|
||||
} else {
|
||||
$log.debug("adding get to pending.");
|
||||
pending.push(function(){ root.get(key, cb); });
|
||||
}
|
||||
return
|
||||
}
|
||||
$log.debug("ss is ready.");
|
||||
|
||||
ss.get(
|
||||
function (value) {
|
||||
console.log('ss Success, got ' + value);
|
||||
cb(null, value);
|
||||
},
|
||||
function (error) {
|
||||
console.log('ss Error "' + error.message + '" ' + JSON.stringify(error));
|
||||
|
||||
if (error.message === 'Failure in SecureStorage.get() - The specified item could not be found in the keychain') {
|
||||
$log.debug("Sending back null error.");
|
||||
// The callback expects no error, but also no value, if it cannot be found.
|
||||
cb(null);
|
||||
} else {
|
||||
cb(new Error(error));
|
||||
}
|
||||
},
|
||||
key);
|
||||
|
||||
};
|
||||
|
||||
root.set = function(key, value, cb) {
|
||||
$log.debug('secureStorageService.set()');
|
||||
if (!ssIsReady) {
|
||||
$log.debug("ss not ready.");
|
||||
if (ssInitialisationFailed) {
|
||||
$log.debug("returning error because initialisation failed.");
|
||||
cb(new Error("Secure storage initialisation failed."));
|
||||
} else {
|
||||
$log.debug("adding set to pending.");
|
||||
pending.push(function(){ root.set(key, value, cb); });
|
||||
}
|
||||
return
|
||||
}
|
||||
$log.debug("ss is ready.");
|
||||
|
||||
ss.set(
|
||||
function (value) {
|
||||
console.log('ss Success, got ' + value);
|
||||
cb();
|
||||
},
|
||||
function (error) {
|
||||
console.log('ss Error ' + error);
|
||||
cb(new Error(error));
|
||||
},
|
||||
key, value);
|
||||
|
||||
};
|
||||
|
||||
|
||||
return root;
|
||||
});
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, $timeout) {
|
||||
.factory('storageService', function(logHeader, fileStorageService, localStorageService, sjcl, $log, lodash, platformInfo, secureStorageService, $timeout) {
|
||||
|
||||
var root = {};
|
||||
var storage;
|
||||
|
|
@ -116,15 +116,21 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.storeNewProfile = function(profile, cb) {
|
||||
storage.create('profile', profile.toObj(), cb);
|
||||
//storage.create('profile', profile.toObj(), cb);
|
||||
secureStorageService.set('profile', profile.toObj(), cb);
|
||||
};
|
||||
|
||||
root.storeProfile = function(profile, cb) {
|
||||
storage.set('profile', profile.toObj(), cb);
|
||||
//storage.set('profile', profile.toObj(), cb);
|
||||
secureStorageService.set('profile', profile.toObj(), cb);
|
||||
};
|
||||
|
||||
root.getProfile = function(cb) {
|
||||
storage.get('profile', function(err, str) {
|
||||
$log.debug("getProfile() 31 7");
|
||||
|
||||
//storage.get('profile', function(err, str) {
|
||||
secureStorageService.get('profile', function(err, str) {
|
||||
|
||||
if (err || !str)
|
||||
return cb(err);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue