Skip to content

Commit

Permalink
Feat: remove only username and password for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
fmariqueo-kunder committed Sep 1, 2021
1 parent 500138f commit 2f146c2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ else if (action.equals("addAccount")) {


}
else if(action.equals("removeAccount")){
else if(action.equals("removeAccount") || action.equals("removeUserPassword")){

String accountType = args.getString(0);
Account [] accounts = accountManager.getAccountsByType(accountType);
Expand Down
1 change: 1 addition & 0 deletions src/ios/AccountManagerPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- (void) initWithKey:(CDVInvokedUrlCommand*)command;
- (void) addAccount:(CDVInvokedUrlCommand*)command;
- (void) removeAccount:(CDVInvokedUrlCommand*)command;
- (void) removeUserPassword:(CDVInvokedUrlCommand*)command;
- (void) getUserAccount:(CDVInvokedUrlCommand*)command;
- (void) getPassword:(CDVInvokedUrlCommand*)command;
- (void) getDataFromKey:(CDVInvokedUrlCommand*)command;
Expand Down
26 changes: 25 additions & 1 deletion src/ios/AccountManagerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (void) addAccount:(CDVInvokedUrlCommand*)command{
}

- (void) removeAccount:(CDVInvokedUrlCommand*)command{
//Implica eliminar todo el keychain
// Implica eliminar todo el keychain

self.MyKeychainWrapper = [[KeychainWrapper alloc]init];
if([self.MyKeychainWrapper removeAllData]){
Expand All @@ -88,6 +88,30 @@ - (void) removeAccount:(CDVInvokedUrlCommand*)command{
}
}

- (void) removeUserPassword:(CDVInvokedUrlCommand*)command{
NSString *service = (NSString*)[command.arguments objectAtIndex:0];
NSString *group = (NSString*)[command.arguments objectAtIndex:1];

self.MyKeychainWrapper = [[KeychainWrapper alloc]initWithService:service withGroup:group withKey:@"userAccount"];
if (![self.MyKeychainWrapper removeData]) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Error al intentar eliminar userAccount del keychain"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}

self.MyKeychainWrapper = [[KeychainWrapper alloc]initWithService:service withGroup:group withKey:@"password"];
if (![self.MyKeychainWrapper removeData]) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Error al intentar eliminar password del keychain"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}

// TODO: Remove unknow userData

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void) getUserAccount:(CDVInvokedUrlCommand*)command{
NSString *service = (NSString*)[command.arguments objectAtIndex:0];
NSString *group = (NSString*)[command.arguments objectAtIndex:1];
Expand Down
7 changes: 7 additions & 0 deletions www/AccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ module.exports = (function() {
cordova.exec(successCallback, errorCallback, 'AccountManagerPlugin', 'addAccount', [userName, password, accountType, group, userData]);
};

// For iOS remove all data from keychain. For Android remove all account
var _removeAccount = function(accountType, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, 'AccountManagerPlugin', 'removeAccount', [accountType]);
};

// For iOS only remove user account and password. For Android remove all account
var _removeUserPassword = function(accountType, group, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, 'AccountManagerPlugin', 'removeUserPassword', [accountType, group]);
};

var _getUserAccount = function(accountType, group, returnKey, successCallback, errorCallback){
cordova.exec(successCallback, errorCallback, 'AccountManagerPlugin', 'getUserAccount', [accountType, group, returnKey]);
};
Expand Down Expand Up @@ -44,6 +50,7 @@ module.exports = (function() {
initWithKey: _initWithKey,
registerAccount: _addAccount,
removeAccount: _removeAccount,
removeUserPassword: _removeUserPassword,
getUserAccount: _getUserAccount,
getPassword: _getPassword,
getDataFromKey: _getDataFromKey,
Expand Down

0 comments on commit 2f146c2

Please sign in to comment.