private void SaveNativeCredential(NativeCredential nativeCredential, string ssoGroupKey) { var serializedCredential = nativeCredential.Serialize(); // If there exists a credential, delete before writing new credential var existingCredential = FindCredential(nativeCredential.UserID, ssoGroupKey); if (existingCredential != null) { accountManager.RemoveAccountExplicitly(new Account(existingCredential.UserID, ssoGroupKey)); } // Add new credential Account account = new Account(nativeCredential.UserID, ssoGroupKey); Android.OS.Bundle bundle = new Android.OS.Bundle(); bundle.PutString(Constants.STR_CREDENTIAL, serializedCredential); accountManager.AddAccountExplicitly(account, "", bundle); }
private void SaveNativeCredential(NativeCredential nativeCredential, string ssoGroupKey) { var statusCode = SecStatusCode.Success; var serializedCredential = nativeCredential.Serialize(); var data = NSData.FromString(serializedCredential, NSStringEncoding.UTF8); // If there exists a credential, delete before writing new credential var existingCredential = FindCredential(nativeCredential.UserID, ssoGroupKey); if (existingCredential != null) { var query = new SecRecord(SecKind.GenericPassword); query.Service = ssoGroupKey; query.Account = nativeCredential.UserID; statusCode = SecKeyChain.Remove(query); if (statusCode != SecStatusCode.Success) { throw new KinveyException(EnumErrorCategory.ERROR_USER, EnumErrorCode.ERROR_MIC_CREDENTIAL_SAVE, statusCode.ToString()); } } // Add new credential var record = new SecRecord(SecKind.GenericPassword); record.Service = ssoGroupKey; record.Account = nativeCredential.UserID; record.Generic = data; record.Accessible = SecAccessible.WhenUnlocked; statusCode = SecKeyChain.Add(record); if (statusCode != SecStatusCode.Success) { throw new KinveyException(EnumErrorCategory.ERROR_USER, EnumErrorCode.ERROR_MIC_CREDENTIAL_SAVE, statusCode.ToString()); } }