address review feedback: move security level into the Options object

This commit is contained in:
Igor Mandrigin 2019-01-20 20:28:08 +01:00
parent c2701a516c
commit 3a94ace6bd
2 changed files with 10 additions and 17 deletions

View File

@ -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.

View File

@ -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)
);
}