From d6544520f27f3ad3a28be0603546deedf2f2b5de Mon Sep 17 00:00:00 2001 From: Joel Arvidsson Date: Sun, 25 Feb 2018 19:20:49 +0100 Subject: [PATCH] Rename *SecurePassword to *PasswordWithAuthentication and unify arguments --- RNKeychainManager/RNKeychainManager.m | 6 ++++-- index.js | 27 ++++++++++++++------------- typings/react-native-keychain.d.ts | 19 +++++++++---------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/RNKeychainManager/RNKeychainManager.m b/RNKeychainManager/RNKeychainManager.m index 073ad3c..a7c410b 100644 --- a/RNKeychainManager/RNKeychainManager.m +++ b/RNKeychainManager/RNKeychainManager.m @@ -200,8 +200,9 @@ RCT_EXPORT_METHOD(getSupportedBiometryType:(RCTPromiseResolveBlock)resolve rejec return [[[ LAContext alloc] init ] canEvaluatePolicy:policyToEvaluate error:err ]; } -RCT_EXPORT_METHOD(setSecurePasswordForService:(NSString *)service withUsername:(NSString *)username withPassword:(NSString *)password withOptions:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_METHOD(setPasswordWithAuthentication:(NSDictionary *)options withUsername:(NSString *)username withPassword:(NSString *)password resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { + NSString *service = serviceValue(options); // Delete old entry for that key if Available NSError *aerr = nil; BOOL canAuthenticate = [ self canCheckAuthentication:LAPolicyDeviceOwnerAuthentication error:&aerr ]; @@ -254,8 +255,9 @@ RCT_EXPORT_METHOD(setSecurePasswordForService:(NSString *)service withUsername:( }); } -RCT_EXPORT_METHOD(getSecurePasswordForService:(NSString *)service withOptions:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +RCT_EXPORT_METHOD(getPasswordWithAuthentication:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { + NSString *service = serviceValue(options); NSString *promptMessage = @"Authenticate to retrieve secret!"; if (options && options[kCustomPromptMessage]) { promptMessage = options[kCustomPromptMessage]; diff --git a/index.js b/index.js index 9c9ea2a..43ac1cd 100644 --- a/index.js +++ b/index.js @@ -57,6 +57,7 @@ type SecAccessControl = type LAPolicy = 'Authentication' | 'AuthenticationWithBiometrics'; type SecureOptions = { + service?: string, customPrompt?: string, authenticationType?: LAPolicy, accessControl?: SecAccessControl, @@ -96,29 +97,28 @@ export function getSupportedBiometryType(): Promise { } /** - * Saves the `username` and `password` combination for `service` securely - needs authentication to retrieve it. - * @param {string} service Associated service. + * Saves the `username` and `password` combination securely - needs authentication to retrieve it. * @param {string} username Associated username or e-mail to be saved. * @param {string} password Associated password to be saved. * @param {object} options Keychain options, iOS only * @return {Promise} Resolves to `true` when successful */ -export function setSecurePassword( - service: string, +export function setPasswordWithAuthentication( username: string, password: string, options?: SecureOptions ): Promise { if (Platform.OS !== 'ios') { return Promise.reject( - new Error(`setSecurePassword() is not supported on ${Platform.OS} yet`) + new Error( + `setPasswordWithAuthentication() is not supported on ${Platform.OS} yet` + ) ); } - return RNKeychainManager.setSecurePasswordForService( - service, + return RNKeychainManager.setPasswordWithAuthentication( + options, username, - password, - options + password ); } @@ -127,16 +127,17 @@ export function setSecurePassword( * @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object. * @return {Promise} Resolves to `{ service, username, password }` when successful */ -export function getSecurePassword( - service: string, +export function getPasswordWithAuthentication( options?: SecureOptions ): Promise { if (Platform.OS !== 'ios') { return Promise.reject( - new Error(`getSecurePassword() is not supported on ${Platform.OS} yet`) + new Error( + `getPasswordWithAuthentication() is not supported on ${Platform.OS} yet` + ) ); } - return RNKeychainManager.getSecurePasswordForService(service, options); + return RNKeychainManager.getPasswordWithAuthentication(options); } /** diff --git a/typings/react-native-keychain.d.ts b/typings/react-native-keychain.d.ts index 28e79ad..206ac80 100644 --- a/typings/react-native-keychain.d.ts +++ b/typings/react-native-keychain.d.ts @@ -12,25 +12,24 @@ declare module 'react-native-keychain' { } export interface SecureOptions { - customPrompt?: string; - authenticationType?: string; - accessControl?: string; + service: string; + customPrompt?: string; + authenticationType?: string; + accessControl?: string; } function canImplyAuthentication( - options?: SecureOptions + options?: SecureOptions ): Promise; function setSecurePassword( - service: string, - username: string, - password: string, - options?: SecureOptions + username: string, + password: string, + options?: SecureOptions ): Promise; function getSecurePassword( - service: string, - options?: SecureOptions + options?: SecureOptions ): Promise; function setInternetCredentials(