react-native-keychain icon indicating copy to clipboard operation
react-native-keychain copied to clipboard

Is not possible to have multiple accessControl for different usernames.

Open MFrat opened this issue 1 year ago • 3 comments

Basically I want to store multiple data (more precisely 3: accessToken, refreshToken, local storage encryption) in keychain and I'm achieving it by using different service names for each (username, password). Although I think this is very weird and non-intuitive, since in native ios and android libraries we can set different (username,password) without overwriting old ones, but ok.

The problem is: I want to have a different accessControl for one specific username. But I simply can't because when I set it for one username it also set for all other usernames. Is it possible to overcome this with this library?

MFrat avatar Jul 10 '24 00:07 MFrat

Hi @MFrat, could you please share the names of libraries that allow this?

DorianMazur avatar Nov 12 '24 07:11 DorianMazur

Hi @DorianMazur, Thank you for being an active maintainer! I need some suggestions on how to use this library to store two different values under different keychain options. Each value may be associated with a different service class, and I would like to apply different keychain options for unlocking them during retrieval like one using biometric authentication and the other with a direct method. Is this still feasible using this library?

vikassharma96 avatar Dec 06 '24 15:12 vikassharma96

@vikassharma96 Absolutely. Use different service for each item.

// First
await setGenericPassword(
  'firstKey',
  firstKeyData,
  {
    service: 'com.myapp.firstKey'
    storage: STORAGE_TYPE.AES_GCM_NO_AUTH,
  }
);
// Second
await setGenericPassword(
  'secondKey',
  secondKeyData,
  {
    service: 'com.myapp.secondKey'
    storage: STORAGE_TYPE.AES_GCM,
  }
);

DorianMazur avatar Dec 06 '24 18:12 DorianMazur