mirror of
https://github.com/bitwarden/browser
synced 2026-01-30 00:03:30 +00:00
Implement macOS user verification
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#ifndef USER_VERIFICATION_H
|
||||
#define USER_VERIFICATION_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
void userVerification(void *context, NSDictionary *params);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <LocalAuthentication/LocalAuthentication.h>
|
||||
#import "../../utils.h"
|
||||
#import "../../interop.h"
|
||||
#import "user_verification.h"
|
||||
|
||||
void userVerification(void* context, NSDictionary *params) {
|
||||
// TODO: Make this more functional by using LAAuthenticationView from @import LocalAuthenticationEmbeddedUI;
|
||||
LAContext *uvContext = [[LAContext alloc] init];
|
||||
uvContext.localizedCancelTitle = @"Enter Password";
|
||||
LAPolicy policy = LAPolicyDeviceOwnerAuthentication;
|
||||
NSError *error;
|
||||
if (![uvContext canEvaluatePolicy: policy error:&error]) {
|
||||
NSLog(@"Could not evaluate UV policy: %@", [error localizedDescription]);
|
||||
return _return(context, _error_er(error));
|
||||
}
|
||||
|
||||
NSString *displayHint = params[@"displayHint"];
|
||||
[uvContext evaluatePolicy:policy localizedReason:displayHint reply:^(BOOL success, NSError * _Nullable error) {
|
||||
if (!success) {
|
||||
return _return(context, _error_er(error));
|
||||
}
|
||||
_return(context, _success(@{}));
|
||||
}];
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "commands/sync.h"
|
||||
#import "commands/status.h"
|
||||
#import "commands/user_verification.h"
|
||||
#import "../interop.h"
|
||||
#import "../utils.h"
|
||||
#import "run_autofill_command.h"
|
||||
@@ -14,6 +15,9 @@ void runAutofillCommand(void* context, NSDictionary *input) {
|
||||
} else if ([command isEqual:@"sync"]) {
|
||||
return runSync(context, params);
|
||||
}
|
||||
else if ([command isEqual:@"user-verification"]) {
|
||||
return userVerification(context, params);
|
||||
}
|
||||
|
||||
_return(context, _error([NSString stringWithFormat:@"Unknown command: %@", command]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user