Rename *SecurePassword to *PasswordWithAuthentication and unify arguments
This commit is contained in:
parent
ecaa3f0041
commit
d6544520f2
|
@ -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];
|
||||
|
|
27
index.js
27
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<boolean>;
|
||||
|
||||
function setSecurePassword(
|
||||
service: string,
|
||||
username: string,
|
||||
password: string,
|
||||
options?: SecureOptions
|
||||
username: string,
|
||||
password: string,
|
||||
options?: SecureOptions
|
||||
): Promise<boolean>;
|
||||
|
||||
function getSecurePassword(
|
||||
service: string,
|
||||
options?: SecureOptions
|
||||
options?: SecureOptions
|
||||
): Promise<boolean | {service: string, username: string, password: string}>;
|
||||
|
||||
function setInternetCredentials(
|
||||
|
|
Loading…
Reference in New Issue