public Task <bool> GetAuthentication() { var tcs = new TaskCompletionSource <bool>(); var lac = new LAContext(); if (lac.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out var authError)) { if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { lac.LocalizedReason = "Authorize for access to secrets"; // iOS 11 lac.EvaluatePolicy( LAPolicy.DeviceOwnerAuthenticationWithBiometrics, new NSString("Login to tSecret"), new LAContextReplyHandler((isSuccess, error) => { tcs.SetResult(isSuccess); }) ); } } else if (lac.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out var authError2)) { lac.EvaluatePolicy( LAPolicy.DeviceOwnerAuthentication, new NSString("Login to tSecret"), new LAContextReplyHandler((isSuccess, error) => { tcs.SetResult(isSuccess); }) ); } return(tcs.Task); }
partial void btnTouchId_TouchUpInside(UIButton sender) { //Lets double check the device supports Touch ID if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error)) { var replyHandler = new LAContextReplyHandler((success, error) => { InvokeOnMainThread(() => { if (success) { var newVC = new UIViewController(); PresentViewController(newVC, true, null); } else { var alert = new UIAlertView("OOPS!", "Something went wrong.", null, "Oops", null); alert.Show(); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Logging in with Touch ID", replyHandler); } else { var alert = new UIAlertView("Error", "TouchID not available", null, "BOOO!", null); alert.Show(); } }
/// <summary> /// Prompts for touch id authenticaion. /// </summary> /// <param name="responseAction">Code to execute after a response is received from Touch ID.</param> public static LAContext PromptForTouchID(LAContextReplyHandler responseAction) { var context = new LAContext(); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Logging in with Touch ID", responseAction); return(context); }
public void Authenticate(Action successAction, Action failAction) { NSError AuthError; if (_context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler(async(success, error) => { if (success) { await GlobalObject.curMainPage.Navigation.PushAsync(new MainPage()); } else { //Show fallback mechanism here if (failAction != null) { failAction.Invoke(); } } }); _context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Fingerprint Authentication", replyHandler); } ; }
public Task <OperationResult> PerformBiometricAuthentication(string promptText) { var tcs = new TaskCompletionSource <OperationResult>(); var context = new LAContext(); NSError authError; var message = new NSString(promptText); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { if (success) { tcs.SetResult(OperationResult.AsSuccess()); } else { tcs.SetResult(OperationResult.AsFailure((error as NSError).LocalizedDescription)); } }); // This starts the authentication dialog. context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, message, replyHandler); } return(tcs.Task); }
public void AuthenticateMe() { var context = new LAContext(); NSError AuthError; var myReason = new NSString("Log in to proceed"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { Console.WriteLine("You logged in!"); UIApplication.SharedApplication.KeyWindow.RootViewController = AppDelegate.CachedViewController; } else { //Show fallback mechanism here } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } ; }
public void Authenticate(Action successAction, Action failAction) { _context = new LAContext(); NSError AuthError; if (_context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { if (success) { if (successAction != null) { successAction.Invoke(); } } else { //Show fallback mechanism here if (failAction != null) { failAction.Invoke(); } } }); _context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Fingerprint Authentication", replyHandler); } ; }
void PerformAuthentication(object sender, EventArgs e) { NSError authError; var context = new LAContext(); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => this.InvokeOnMainThread(() => { if (success) { PerformSegue("AuthScreen", this); } else { UIAlertController uac = UIAlertController.Create("Authentication Failed. Is this your phone?", "Security Failure", UIAlertControllerStyle.Alert); uac.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); this.PresentViewController(uac, true, null); } })); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Access Account", replyHandler); } else { UIAlertController uac = UIAlertController.Create("Biometrics not supported", "Policy not supported", UIAlertControllerStyle.Alert); uac.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); this.PresentViewController(uac, true, null); } }
partial void AuthenticateMe(UIButton sender) { var context = new LAContext(); NSError AuthError; var localizedReason = new NSString("To add a new chore"); //Use canEvaluatePolicy method to test if device is TouchID enabled //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background this.InvokeOnMainThread(() => { if (success) { Console.WriteLine("You logged in!"); PerformSegue("AuthenticationSegue", this); } else { //Show fallback mechanism here unAuthenticatedLabel.Text = "Oh Noes"; AuthenticateButton.Hidden = true; } }); }); //Use evaluatePolicy to start authentication operation and show the UI as an Alert view //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler); } ; }
public Task <bool> AuthenticateUserIDWithTouchID() { bool outcome = false; var tcs = new TaskCompletionSource <bool>(); var context = new LAContext(); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { Device.BeginInvokeOnMainThread(() => { if (success) { outcome = true; } else { outcome = false; } tcs.SetResult(outcome); }); }); //This will call both TouchID and FaceId context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Login with touch ID", replyHandler); } ; return(tcs.Task); }
partial void AuthenticateMe (UIButton sender) { var context = new LAContext(); NSError AuthError; var localizedReason = new NSString("To add a new chore"); //Use canEvaluatePolicy method to test if device is TouchID enabled //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)){ replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background this.InvokeOnMainThread(()=>{ if(success){ Console.WriteLine("You logged in!"); PerformSegue("AuthenticationSegue", this); } else{ //Show fallback mechanism here unAuthenticatedLabel.Text="Oh Noes"; AuthenticateButton.Hidden= true; } }); }); //Use evaluatePolicy to start authentication operation and show the UI as an Alert view //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler); }; }
public void Authenticate(Func <Task> action, string title) { try { OnBiometrics = true; var context = new LAContext(); if (_Current == AuthenticationTypes.FaceID || _Current == AuthenticationTypes.TouchID) { if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out var authError)) { context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, $"{title ?? "Logging in"} with {_Current}", GetReplyHandler(action)); } else { //DisplayAlert($"{_Current} is temporarily unavailable. Please check if you have set up {_Current} in your phone Settings."); OnBiometrics = false; return; } } else { //DisplayAlert($"Please check if you have set up any available biometrics in your phone Settings."); OnBiometrics = false; return; } } catch (Exception ex) { //DisplayAlertError("Something went wrong while using biometric authentication."); } }
void AuthenticateThroughFingerprint() { var context = new LAContext(); NSError authError; var myReason = new NSString( "Please, provide your fingerprint to acess the app."); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(async() => { if (success) { return; } var dialogService = Mvx.Resolve <IDialogService>(); await dialogService.AlertAsync( "We could not detect your fingerprint. " + "You will be asked again to enter your Azure AD credentials. " + "Thank you.", "Touch ID", "OK"); // If fingerprint not detected, repeat Azure AD auth. AuthenticateThroughAzureADAndAddFingerprintAsync() .ConfigureAwait(false); }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } }
public Task <bool> LoginAsync() { LAContextReplyHandler replyHandler; var retVal = new TaskCompletionSource <bool>(); var context = new LAContext(); NSError AuthError; var localizedReason = new NSString("Access to STATAlert"); // because LocalAuthentication APIs have been extended over time, need to check iOS version before setting some properties context.LocalizedFallbackTitle = "Fallback"; // iOS 8 if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { context.LocalizedCancelTitle = "Cancel"; // iOS 10 } if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { context.LocalizedReason = "Authorize for access to STATAlert"; // iOS 11 BiometryType = context.BiometryType == LABiometryType.TouchId ? "TouchID" : "FaceID"; } //Use canEvaluatePolicy method to test if device is TouchID or FaceID enabled //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { Console.WriteLine("TouchID/FaceID available/enrolled"); replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background Xamarin.Essentials.MainThread.BeginInvokeOnMainThread( () => { if (success) { retVal.SetResult(success); } else { Console.WriteLine(error.LocalizedDescription); retVal.SetResult(success); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler); } return(retVal.Task); }
private void EvaluatePolicy(string reason) { if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var context = new LAContext(); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, reason, HandleLAContextReplyHandler); } else { SystemLogger.Log(SystemLogger.Module.PLATFORM, "EvaluatePolicy - device OS is under iOS 8 - touch ID not available"); } }
public void AuthenticateWithTouchId(LoginPage page) { if (!UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { return; } var hasLoginKey = NSUserDefaults.StandardUserDefaults.BoolForKey("hasLogin"); if (string.IsNullOrEmpty(App.UserName)) { return; } var username = NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString("username")).ToString(); if (string.IsNullOrEmpty(username)) { return; } var context = new LAContext(); NSError AuthError; var myReason = new NSString("Login to expense portal"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { if (error != null) { if (error.LocalizedDescription == "Canceled by user.") { return; } } if (success) { Console.WriteLine("Success!!"); var userName = NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString("username")).ToString(); Xamarin.Insights.Identify(userName, new Dictionary <string, string> { { "User Type", "NonApprover" }, }); } page.TouchIdSuccess = success; }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } ; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. authenticationButton.TouchUpInside += (sender, e) => { var context = new LAContext(); var result = context.EvaluatePolicyAsync(LAPolicy.DeviceOwnerAuthentication, "Authentication Request").GetAwaiter().GetResult(); var can = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out Foundation.NSError error); if (result.Item1) { UserDialogs.Instance.Alert("Authentication"); } else { var code = Convert.ToInt16(result.Item2.Code); var status = (LAStatus)code; UserDialogs.Instance.Alert(status.ToString()); } }; authenButton.TouchUpInside += (sender, e) => { var context = new LAContext(); var myReason = new NSString("To add a new chore"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { UserDialogs.Instance.Alert("Login Success"); } else { //Show fallback mechanism here } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } ; }; }
public Task <bool> GetAuthentication() { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); LAContext context = new LAContext(); NSString caption = new NSString("Login to tSecret"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError ae)) { LAContextReplyHandler replyHandler = new LAContextReplyHandler((success, error) => { tcs.SetResult(success); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, caption, replyHandler); } ; return(tcs.Task); }
public bool Authenticted() { var context = new LAContext(); NSError AuthError; var localizedReason = new NSString("To access secrets"); // because LocalAuthentication APIs have been extended over time, need to check iOS version before setting some properties context.LocalizedFallbackTitle = "Fallback"; // iOS 8 if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { context.LocalizedCancelTitle = "Cancel"; // iOS 10 } if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { Console.WriteLine("TouchID/FaceID available/enrolled"); replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background this.InvokeOnMainThread(() => { if (success) { //Console.WriteLine($"You logged in with {BiometryType}!"); //PerformSegue("AuthenticationSegue", this); IsValidFace = true; } else { IsValidFace = false; //Console.WriteLine(error.LocalizedDescription); //Show fallback mechanism here //unAuthenticatedLabel.Text = $"{BiometryType} Authentication Failed"; //AuthenticateButton.Hidden = true; } }); }); //Use evaluatePolicy to start authentication operation and show the UI as an Alert view //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler); return(IsValidFace); } return(IsValidFace); }
/// <inheritdoc /> public Task <AuthenticationResult> AuthenticateAsync(string alertMessage = null) { if (AvailableBiometricType == BiometricType.None) { Logger.Debug("[BiometricAthenticationService] Authentication not available on this device"); return(Task.FromResult(new AuthenticationResult(false, "Authentication not available"))); } var tcs = new TaskCompletionSource <AuthenticationResult>(); var context = new LAContext(); NSError authError; if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError) || context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background UIApplication.SharedApplication.InvokeOnMainThread(() => { if (success) { System.Diagnostics.Debug.WriteLine("Authentication Success"); tcs.TrySetResult(new AuthenticationResult(true)); } else { System.Diagnostics.Debug.WriteLine("Authentication Failure : " + error.Description); tcs.TrySetResult(new AuthenticationResult(false, error.Description)); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, alertMessage ?? "Please scan fingerprint", replyHandler); } else { //No Auth setup on Device Logger.Debug($"This device doesn't have authentication configured: {authError.ToString()}"); tcs.TrySetResult(new AuthenticationResult(false, "This device does't have authentication configured.")); } return(tcs.Task); }
partial void LoginButtonOnUpInside (UIButton sender) { if (!PerformValidation ()) { return; } var context = new LAContext(); NSError AuthError; if (context.CanEvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => InvokeOnMainThread (() => { if (success) { AttemptLogin(); } })); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Logging in with Touch ID", replyHandler); } else { AttemptLogin(); } }
/// <summary> /// Views the will appear. /// </summary> /// <param name="animated">If set to <c>true</c> animated.</param> public override void ViewWillAppear(bool animated) { //get user connection profile ConnectionProfile connectionProfile = ConnectionHelper.GetConnectionProfile(); if (connectionProfile == null) { return; } //create nre Local Auth context var laContext = new LAContext(); NSError AuthError; var authReason = new NSString("Connect to pet la forme"); //if can evaluate policy with biometrics (FACE/TOUCH ID) if (laContext.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { //new reply handler var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { Auth(connectionProfile); } else { Console.WriteLine("Auth fail"); } }); }); //evaluate policy in actual local context laContext.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, authReason, replyHandler); } else { //also connect user because ios simulator don't have secret code and biometrics Auth(connectionProfile); } }
private void AddFingerprintAuthentication() { var context = new LAContext(); NSError authError; var myReason = new NSString( "Please, provide your fingerprint to simplify the authentication."); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { var dialogService = Mvx.Resolve <IDialogService>(); if (success) { Settings.TouchIdEnrolledAndFingerprintDetected = true; dialogService.AlertAsync( "Your fingerprint was successfully detected. " + "You can access the app through it from now on. " + "Thank you.", "Touch ID", "OK"); } else { Settings.TouchIdEnrolledAndFingerprintDetected = false; dialogService.AlertAsync( "We could not detect your fingerprint. " + "You will need to authenticate through Azure AD. " + "Thank you.", "Touch ID", "OK"); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } }
partial void UIButton5_TouchUpInside(UIButton sender) { var context = new LAContext (); var error = new NSError (); if (context.CanEvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error)) { var replyHandler = new LAContextReplyHandler((success, err) => { this.InvokeOnMainThread(() => { if(success){ new UIAlertView("Success", "You logged in", null, "Close").Show(); } else { new UIAlertView("Login Error", err.LocalizedDescription, null, "Close").Show(); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "You need to login", replyHandler); } }
void LaunchTouchID() { var context = new LAContext(); NSError AuthError; var reason = new NSString("Security validation"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { DismissViewController(false, null); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, reason, replyHandler); } }
public void Authenticate(string userId, Action onSuccess, Action onFailure) { var context = new LAContext(); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out NSError AuthError) || context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { if (success) { onSuccess?.Invoke(); } else { onFailure?.Invoke(); } }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, $"Sign in with Online Id for {userId}", replyHandler); } }
public static void Authenticate(Action onSuccess, Action onFailure) { var context = new LAContext(); NSError AuthError; if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError) || context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { if (success) { onSuccess?.Invoke(); } else { onFailure?.Invoke(); } }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, Strings.PleaseAuthenticateToProceed, replyHandler); } }
void LaunchTouchID() { var context = new LAContext(); NSError AuthError; var reason = new NSString("Security validation"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { //go to initial page UIViewController uiview = Storyboard.InstantiateViewController("MainViewController"); PresentViewController(uiview, false, null); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, reason, replyHandler); } }
partial void UIButton5_TouchUpInside(UIButton sender) { var context = new LAContext(); var error = new NSError(); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error)) { var replyHandler = new LAContextReplyHandler((success, err) => { this.InvokeOnMainThread(() => { if (success) { new UIAlertView("Success", "You logged in", null, "Close").Show(); } else { new UIAlertView("Login Error", err.LocalizedDescription, null, "Close").Show(); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "You need to login", replyHandler); } }
public void FaceAuthentication() { var context = new LAContext(); var myReason = new NSString("Athenticate"); NSError AuthError; //Check if Face ID is available on mobile device. if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { Device.BeginInvokeOnMainThread(() => { //If authetification is successfull navigate to Select Type page. //If authentication is successful continue to next page. if (success) { if (count > 0) // If record count for User table is > 0 then an account exist { Xamarin.Forms.Application.Current.MainPage = new Home(); } else // If the record count is 0 then no User account exist { Xamarin.Forms.Application.Current.MainPage = new SelectType(); } } }); }); //Handle the result of Face ID authentification (Sucess/Failure) according to replyHandler above. context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } else { //If FaceID NOT available on mobile device, display appropriate error message. Xamarin.Forms.Application.Current.MainPage.DisplayAlert("Authentication Failed", "Could not Authenticate with FaceID", "Ok"); } }
/// <summary> /// Authenticates the user. /// </summary> public static void AuthenticateUser(MvxViewController controller) { var viewModel = (AuthenticationViewModel)controller.ViewModel; var context = new LAContext(); NSError AuthError; var authenticationReason = new NSString("Authentication is needed to access the application"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { controller.InvokeOnMainThread(() => { if (viewModel != null) { if (success) { //Calling the success handler viewModel.OnAuthenticationSuccess(); Console.WriteLine("You logged in!"); } else { //Calling the failure handler viewModel.OnAuthenticationFailure(); } } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, authenticationReason, replyHandler); } else { viewModel.OnAuthenticationFailure(); } }
partial void btnLogin_TouchUpInside(UIButton sender) { NSError _error; using (var _context = new LAContext ()) { // Allows us to reuse Touch ID verificaton from unlocking device up to 30 seconds later _context.TouchIdAuthenticationAllowableReuseDuration = 30; if (_context.CanEvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out _error)) { // Get enrollment state if (_context.EvaluatedPolicyDomainState != null) { var policyState = _context.EvaluatedPolicyDomainState.ToString().Replace("<", "").Replace(">", "").Replace(" ", ""); if (TouchIDPolicyDomainState != null) { if (policyState != TouchIDPolicyDomainState) Console.WriteLine("Fingerprints enrollments changed."); else Console.WriteLine("Fingerprints enrollments remain the same."); } // Store enrollment TouchIDPolicyDomainState = policyState; } var replyHandler = new LAContextReplyHandler ((success, error) => { InvokeOnMainThread (() => { if (success) { PerformSegue("SegueToTest", null); } else { DisplayAlertOKPopup("", "Unable to authenticate."); } }); }); // Add reason why we are using Touch ID _context.EvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, "Login as user: X", replyHandler); } else { DisplayAlertOKPopup("", "Touch ID not available on this device."); } } }
private void EvaluatePolicy () { var context = new LAContext (); context.EvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, Text.UNLOCK_ACCESS_TO_LOCKED_FATURE, HandleLAContextReplyHandler); }
/// <inheritdoc /> public Task <AuthenticationResult> AuthenticateAsync(string alertMessage = null) { if (AvailableBiometricType == BiometricType.None) { Console.WriteLine("[BiometricAthenticationService] Authentication not available on this device"); return(Task.FromResult(new AuthenticationResult(false, "Authentication not available"))); } var tcs = new TaskCompletionSource <AuthenticationResult>(); var context = new LAContext(); NSError authError; // Because LocalAuthentication APIs have been extended over time, // you must check iOS version before setting some properties context.LocalizedFallbackTitle = "Fallback"; if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { context.LocalizedCancelTitle = "Cancel"; } if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { context.LocalizedReason = "Authorize for access to secrets"; BiometryType = context.BiometryType == LABiometryType.TouchId ? "TouchID" : "FaceID"; Console.WriteLine(BiometryType); } if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background UIApplication.SharedApplication.InvokeOnMainThread(() => { if (success) { System.Diagnostics.Debug.WriteLine("Authentication Success"); tcs.TrySetResult(new AuthenticationResult(true)); } else { System.Diagnostics.Debug.WriteLine("Authentication Failure : " + error.Description); tcs.TrySetResult(new AuthenticationResult(false, error.Description)); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, alertMessage ?? localizedReason, replyHandler); } else if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out authError)) { var replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background UIApplication.SharedApplication.InvokeOnMainThread(() => { if (success) { System.Diagnostics.Debug.WriteLine("Authentication Success"); tcs.TrySetResult(new AuthenticationResult(true)); } else { System.Diagnostics.Debug.WriteLine("Authentication Failure : " + error.Description); tcs.TrySetResult(new AuthenticationResult(false, error.Description)); } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, alertMessage ?? localizedReason, replyHandler); } else { //No Auth setup on Device Console.WriteLine($"This device doesn't have authentication configured: {authError.ToString()}"); tcs.TrySetResult(new AuthenticationResult(false, "This device does't have authentication configured.")); } return(tcs.Task); }
public Task <bool> AuthenticateMe() { var context = new LAContext(); NSError AuthError; var localizedReason = new NSString("To access secrets"); // because LocalAuthentication APIs have been extended over time, need to check iOS version before setting some properties context.LocalizedFallbackTitle = "Fallback"; // iOS 8 if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { context.LocalizedCancelTitle = "Cancel"; // iOS 10 } if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { context.LocalizedReason = "Authorize for access to secrets"; // iOS 11 BiometryType = context.BiometryType == LABiometryType.TouchId ? "TouchID" : "FaceID"; } var tcs = new TaskCompletionSource <bool>(); //Use canEvaluatePolicy method to test if device is TouchID or FaceID enabled //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { Console.WriteLine("TouchID/FaceID available/enrolled"); replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background UIApplication.SharedApplication.InvokeOnMainThread(() => { if (success) { Console.WriteLine($"You logged in with {BiometryType}!"); tcs.SetResult(success); //PerformSegue("AuthenticationSegue", this); } else { Console.WriteLine(error.LocalizedDescription); //Show fallback mechanism here tcs.SetResult(success); tcs.SetException(new Exception(error.Description)); } }); }); //Use evaluatePolicy to start authentication operation and show the UI as an Alert view //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason, replyHandler); } else if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, out AuthError)) { Console.WriteLine("When TouchID/FaceID aren't available or enrolled, use the device PIN"); replyHandler = new LAContextReplyHandler((success, error) => { //Make sure it runs on MainThread, not in Background UIApplication.SharedApplication.InvokeOnMainThread(() => { if (success) { Console.WriteLine($"You logged in with {BiometryType}!"); //PerformSegue("AuthenticationSegue", this); tcs.SetResult(success); } else { Console.WriteLine(error.LocalizedDescription); //Show fallback mechanism here tcs.SetResult(success); tcs.SetException(new Exception(error.Description)); } }); }); //Use evaluatePolicy to start authentication operation and show the UI as an Alert view //Use the LocalAuthentication Policy DeviceOwnerAuthenticationWithBiometrics context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthentication, localizedReason, replyHandler); } else { // User hasn't configured a PIN or any biometric auth. // App may implement its own login, or choose to allow open access tcs.SetResult(false); } return(tcs.Task); }
private void EvaluatePolicy(string reason) { if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { var context = new LAContext (); context.EvaluatePolicy (LAPolicy.DeviceOwnerAuthenticationWithBiometrics, reason, HandleLAContextReplyHandler); } else { SystemLogger.Log (SystemLogger.Module.PLATFORM, "EvaluatePolicy - device OS is under iOS 8 - touch ID not available"); } }
/// <summary> /// TouchId authentication test /// </summary> private void AuthenticateMe() { var context = new LAContext(); NSError AuthError; var myReason = new NSString("Login to take a picture"); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { Console.WriteLine("You logged in!"); _authenticateButton.Hidden = true; Initialize(); } else { // Inform the user authentication failed } }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); }; }
public void BiometricsLogin() { var context = new LAContext(); NSError AuthError; var myReason = new NSString(LoginScreenData.BioLoginMessage); if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError)) { var replyHandler = new LAContextReplyHandler((success, error) => { this.InvokeOnMainThread(() => { if (success) { var obj = Global.DatabaseManager.GetUsername(); var pwd = Encrypt.DecryptString(obj.PWD); Dictionary<string, string> parameters = new Dictionary<string, string>(); parameters.Add("username", obj.Username); parameters.Add("password", pwd); parameters.Add("app_device_number", Device.DeviceID); loginScreenView.Hide(); initLoadingScreenView(LoginScreenData.LoadingScreenTextLogin); atimer = new Timer(1000); atimer.Elapsed += (s, e) => { if (ServerURLReady) { InvokeOnMainThread(() => { LoginWebCall(parameters); atimer.Stop(); atimer.Dispose(); }); } }; atimer.AutoReset = true; atimer.Enabled = true; } else if (error!=null && error.ToString().Contains("Application retry limit exceeded")){ //Show fallback mechanism here new UIAlertView(LoginScreenData.AlertScreenBioLoginFailTitle, error.ToString()+" "+LoginScreenData.AlertScreenBioLoginFaildMessage, null, LoginScreenData.AlertScreenBioLoginFaildCancelBtnTitle, null).Show(); } PWDLogin(); }); }); context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler); } else { loginScreenView.userNameTextField.Hidden = false; loginScreenView.passwordTextField.Hidden = false; loginScreenView.loginBtn.Hidden = false; loginScreenView.fingerPrintView.Hidden = true; } }