use std::sync::mpsc;
use robius_authentication::{
AndroidText, BiometricStrength, Context, PolicyBuilder, Text, WindowsText,
};
const TEXT: Text = Text {
android: AndroidText {
title: "Title",
subtitle: None,
description: None,
},
apple: "authenticate",
windows: match WindowsText::new("Title", "Description") {
Some(text) => text,
None => panic!("Windows text too long"),
},
};
fn main() {
let context = Context::new(());
let mut policy = PolicyBuilder::new()
.action_ids([
"org.robius.authentication",
"org.robius.authentication.settings",
])
.biometrics(Some(BiometricStrength::Strong))
.password(true)
.companion(true)
.build()
.unwrap();
if let Err(e) = policy.set_action_id("org.robius.authentication.settings") {
eprintln!("Invalid action_id: {:?}", e);
return;
}
let (tx, rx) = mpsc::channel();
let res = context.authenticate(TEXT, &policy, move |result| {
let _ = tx.send(result);
});
if let Err(e) = res {
eprintln!("Failed to start authentication: {:?}", e);
return;
}
match rx.recv() {
Ok(Ok(_)) => println!("Authentication successful"),
Ok(Err(e)) => println!("Authentication failed: {:?}", e),
Err(e) => eprintln!("Failed to receive auth result: {:?}", e),
}
}