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. 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. 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. 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. 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`. 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. 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, authenticationPrompt?: string,
authenticationType?: LAPolicy, authenticationType?: LAPolicy,
service?: string, service?: string,
securityLevel?: SecMinimumLevel,
}; };
/** /**
@ -98,8 +99,6 @@ export function getSupportedBiometryType(): Promise<?($Values<typeof BIOMETRY_TY
* @param {string} server URL to server. * @param {string} server URL to server.
* @param {string} username Associated username or e-mail to be saved. * @param {string} username Associated username or e-mail to be saved.
* @param {string} password Associated password 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 * @param {object} options Keychain options, iOS only
* @return {Promise} Resolves to `true` when successful * @return {Promise} Resolves to `true` when successful
*/ */
@ -107,14 +106,13 @@ export function setInternetCredentials(
server: string, server: string,
username: string, username: string,
password: string, password: string,
minimumSecurityLevel?: SecMinimumLevel,
options?: Options options?: Options
): Promise<void> { ): Promise<void> {
return RNKeychainManager.setInternetCredentialsForServer( return RNKeychainManager.setInternetCredentialsForServer(
server, server,
username, username,
password, password,
getMinimumSecurityLevel(minimumSecurityLevel), getMinimumSecurityLevel(options),
options options
); );
} }
@ -170,34 +168,29 @@ function getOptionsArgument(serviceOrOptions?: string | Options) {
: serviceOrOptions; : serviceOrOptions;
} }
function getMinimumSecurityLevel(minimumSecurityLevel?: SecMinimumLevel) { function getMinimumSecurityLevel(serviceOrOptions?: string | Options) {
if (minimumSecurityLevel === undefined) { return typeof serviceOrOptions === 'object'
return SECURITY_LEVEL.ANY; ? serviceOrOptions.securityLevel
} else { : SECURITY_LEVEL.ANY;
return minimumSecurityLevel
}
} }
/** /**
* Saves the `username` and `password` combination for `service`. * Saves the `username` and `password` combination for `service`.
* @param {string} username Associated username or e-mail to be saved. * @param {string} username Associated username or e-mail to be saved.
* @param {string} password Associated password 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. * @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 * @return {Promise} Resolves to `true` when successful
*/ */
export function setGenericPassword( export function setGenericPassword(
username: string, username: string,
password: string, password: string,
minimumSecurityLevel?: SecMinimumLevel,
serviceOrOptions?: string | Options serviceOrOptions?: string | Options
): Promise<boolean> { ): Promise<boolean> {
return RNKeychainManager.setGenericPasswordForOptions( return RNKeychainManager.setGenericPasswordForOptions(
getOptionsArgument(serviceOrOptions), getOptionsArgument(serviceOrOptions),
username, username,
password, password,
getMinimumSecurityLevel(minimumSecurityLevel) getMinimumSecurityLevel(serviceOrOptions)
); );
} }