mirror of
https://github.com/status-im/react-native-keychain.git
synced 2025-02-21 09:28:10 +00:00
address review feedback: move security level into the Options
object
This commit is contained in:
parent
c2701a516c
commit
3a94ace6bd
@ -45,7 +45,7 @@ See `KeychainExample` for fully working project example.
|
||||
|
||||
Both `setGenericPassword` and `setInternetCredentials` are limited to strings only, so if you need to store objects etc, please use `JSON.stringify`/`JSON.parse` when you store/access it.
|
||||
|
||||
### `setGenericPassword(username, password, securityLevel, [{ accessControl, accessible, accessGroup, service }])`
|
||||
### `setGenericPassword(username, password, [{ accessControl, accessible, accessGroup, service, securityLevel }])`
|
||||
|
||||
Will store the username/password combination in the secure storage. Resolves to `true` or rejects in case of an error.
|
||||
|
||||
@ -57,7 +57,7 @@ Will retreive the username/password combination from the secure storage. Resolve
|
||||
|
||||
Will remove the username/password combination from the secure storage.
|
||||
|
||||
### `setInternetCredentials(server, username, password, securityLevel, [{ accessControl, accessible, accessGroup }])`
|
||||
### `setInternetCredentials(server, username, password, [{ accessControl, accessible, accessGroup, securityLevel }])`
|
||||
|
||||
Will store the server/username/password combination in the secure storage.
|
||||
|
||||
@ -89,7 +89,7 @@ Inquire if the type of local authentication policy is supported on this device w
|
||||
|
||||
Get what type of hardware biometry support the device has. Resolves to a `Keychain.BIOMETRY_TYPE` value when supported, otherwise `null`.
|
||||
|
||||
### `getSecurityLevel()`
|
||||
### `getSecurityLevel()` (Android only)
|
||||
|
||||
Get security level that is supported on the current device with the current OS.
|
||||
|
||||
|
21
index.js
21
index.js
@ -55,6 +55,7 @@ export type Options = {
|
||||
authenticationPrompt?: string,
|
||||
authenticationType?: LAPolicy,
|
||||
service?: string,
|
||||
securityLevel?: SecMinimumLevel,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -98,8 +99,6 @@ export function getSupportedBiometryType(): Promise<?($Values<typeof BIOMETRY_TY
|
||||
* @param {string} server URL to server.
|
||||
* @param {string} username Associated username or e-mail to be saved.
|
||||
* @param {string} password Associated password to be saved.
|
||||
* @param {string} minimumSecurityLevel `SECURITY_LEVEL` defines which security
|
||||
* level is minimally acceptable for this password.
|
||||
* @param {object} options Keychain options, iOS only
|
||||
* @return {Promise} Resolves to `true` when successful
|
||||
*/
|
||||
@ -107,14 +106,13 @@ export function setInternetCredentials(
|
||||
server: string,
|
||||
username: string,
|
||||
password: string,
|
||||
minimumSecurityLevel?: SecMinimumLevel,
|
||||
options?: Options
|
||||
): Promise<void> {
|
||||
return RNKeychainManager.setInternetCredentialsForServer(
|
||||
server,
|
||||
username,
|
||||
password,
|
||||
getMinimumSecurityLevel(minimumSecurityLevel),
|
||||
getMinimumSecurityLevel(options),
|
||||
options
|
||||
);
|
||||
}
|
||||
@ -170,34 +168,29 @@ function getOptionsArgument(serviceOrOptions?: string | Options) {
|
||||
: serviceOrOptions;
|
||||
}
|
||||
|
||||
function getMinimumSecurityLevel(minimumSecurityLevel?: SecMinimumLevel) {
|
||||
if (minimumSecurityLevel === undefined) {
|
||||
return SECURITY_LEVEL.ANY;
|
||||
} else {
|
||||
return minimumSecurityLevel
|
||||
}
|
||||
function getMinimumSecurityLevel(serviceOrOptions?: string | Options) {
|
||||
return typeof serviceOrOptions === 'object'
|
||||
? serviceOrOptions.securityLevel
|
||||
: SECURITY_LEVEL.ANY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the `username` and `password` combination for `service`.
|
||||
* @param {string} username Associated username or e-mail to be saved.
|
||||
* @param {string} password Associated password to be saved.
|
||||
* @param {string} minimumSecurityLevel `SECURITY_LEVEL` defines which security
|
||||
* level is minimally acceptable for this password.
|
||||
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object.
|
||||
* @return {Promise} Resolves to `true` when successful
|
||||
*/
|
||||
export function setGenericPassword(
|
||||
username: string,
|
||||
password: string,
|
||||
minimumSecurityLevel?: SecMinimumLevel,
|
||||
serviceOrOptions?: string | Options
|
||||
): Promise<boolean> {
|
||||
return RNKeychainManager.setGenericPasswordForOptions(
|
||||
getOptionsArgument(serviceOrOptions),
|
||||
username,
|
||||
password,
|
||||
getMinimumSecurityLevel(minimumSecurityLevel)
|
||||
getMinimumSecurityLevel(serviceOrOptions)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user