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 ];
|
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
|
// Delete old entry for that key if Available
|
||||||
NSError *aerr = nil;
|
NSError *aerr = nil;
|
||||||
BOOL canAuthenticate = [ self canCheckAuthentication:LAPolicyDeviceOwnerAuthentication error:&aerr ];
|
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!";
|
NSString *promptMessage = @"Authenticate to retrieve secret!";
|
||||||
if (options && options[kCustomPromptMessage]) {
|
if (options && options[kCustomPromptMessage]) {
|
||||||
promptMessage = options[kCustomPromptMessage];
|
promptMessage = options[kCustomPromptMessage];
|
||||||
|
|
27
index.js
27
index.js
|
@ -57,6 +57,7 @@ type SecAccessControl =
|
||||||
type LAPolicy = 'Authentication' | 'AuthenticationWithBiometrics';
|
type LAPolicy = 'Authentication' | 'AuthenticationWithBiometrics';
|
||||||
|
|
||||||
type SecureOptions = {
|
type SecureOptions = {
|
||||||
|
service?: string,
|
||||||
customPrompt?: string,
|
customPrompt?: string,
|
||||||
authenticationType?: LAPolicy,
|
authenticationType?: LAPolicy,
|
||||||
accessControl?: SecAccessControl,
|
accessControl?: SecAccessControl,
|
||||||
|
@ -96,29 +97,28 @@ export function getSupportedBiometryType(): Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the `username` and `password` combination for `service` securely - needs authentication to retrieve it.
|
* Saves the `username` and `password` combination securely - needs authentication to retrieve it.
|
||||||
* @param {string} service Associated 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 {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
|
||||||
*/
|
*/
|
||||||
export function setSecurePassword(
|
export function setPasswordWithAuthentication(
|
||||||
service: string,
|
|
||||||
username: string,
|
username: string,
|
||||||
password: string,
|
password: string,
|
||||||
options?: SecureOptions
|
options?: SecureOptions
|
||||||
): Promise {
|
): Promise {
|
||||||
if (Platform.OS !== 'ios') {
|
if (Platform.OS !== 'ios') {
|
||||||
return Promise.reject(
|
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(
|
return RNKeychainManager.setPasswordWithAuthentication(
|
||||||
service,
|
options,
|
||||||
username,
|
username,
|
||||||
password,
|
password
|
||||||
options
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
* @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
|
* @return {Promise} Resolves to `{ service, username, password }` when successful
|
||||||
*/
|
*/
|
||||||
export function getSecurePassword(
|
export function getPasswordWithAuthentication(
|
||||||
service: string,
|
|
||||||
options?: SecureOptions
|
options?: SecureOptions
|
||||||
): Promise {
|
): Promise {
|
||||||
if (Platform.OS !== 'ios') {
|
if (Platform.OS !== 'ios') {
|
||||||
return Promise.reject(
|
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 {
|
export interface SecureOptions {
|
||||||
customPrompt?: string;
|
service: string;
|
||||||
authenticationType?: string;
|
customPrompt?: string;
|
||||||
accessControl?: string;
|
authenticationType?: string;
|
||||||
|
accessControl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function canImplyAuthentication(
|
function canImplyAuthentication(
|
||||||
options?: SecureOptions
|
options?: SecureOptions
|
||||||
): Promise<boolean>;
|
): Promise<boolean>;
|
||||||
|
|
||||||
function setSecurePassword(
|
function setSecurePassword(
|
||||||
service: string,
|
username: string,
|
||||||
username: string,
|
password: string,
|
||||||
password: string,
|
options?: SecureOptions
|
||||||
options?: SecureOptions
|
|
||||||
): Promise<boolean>;
|
): Promise<boolean>;
|
||||||
|
|
||||||
function getSecurePassword(
|
function getSecurePassword(
|
||||||
service: string,
|
options?: SecureOptions
|
||||||
options?: SecureOptions
|
|
||||||
): Promise<boolean | {service: string, username: string, password: string}>;
|
): Promise<boolean | {service: string, username: string, password: string}>;
|
||||||
|
|
||||||
function setInternetCredentials(
|
function setInternetCredentials(
|
||||||
|
|
Loading…
Reference in New Issue