Passkey Flex Rust SDK
Install
Install the Passage Passkey Flex Rust package (opens in a new tab).
cargo add passage_flex
Initialize
Initialize a Passage Passkey Flex instance using your app ID found in Passage Console.
use passage_flex::PassageFlex;
let passage_flex = PassageFlex::new(
std::env::var("YOUR_PASSAGE_APP_ID").unwrap(),
std::env::var("YOUR_PASSAGE_API_KEY").unwrap(),
);
Core functions
See full documentation on Github and Docs.rs (opens in a new tab).
create_authenticate_transaction()
Create a transaction to start a user's authentication process.
Parameters
Property | Data Type | Description |
---|---|---|
external_id | String | The external ID used to associate the user with Passage. |
Returns
Result<String, Error>
The transaction ID.
Example
let transaction = passage_flex
.create_authenticate_transaction(
"00000000-0000-0000-0000-000000000001".to_string(),
)
.await
.unwrap();
create_register_transaction()
Create a transaction to start a user's registration process.
Parameters
Property | Data Type | Description |
---|---|---|
external_id | String | The external ID used to associate the user with Passage. |
passkey_display_name | String | The label for the user’s passkey that they will see when logging in. |
Returns
Result<String, Error>
transaction ID as a String or an Error.
Example
let transaction = passage_flex
.create_register_transaction(
"00000000-0000-0000-0000-000000000001".to_string(),
"user@example.com".to_string(),
)
.await
.unwrap();
get_app()
Retrieve information about an app.
Returns
A Result<Box<AppInfo>, Error>
the AppInfo
struct or an Error
.
Example
let app_info = passage_flex.get_app().await.unwrap();
println!("{}", app_info.auth_origin);
get_devices()
Get a user's devices by their external ID.
Parameters
Property | Data Type | Description |
---|---|---|
external_id | String | The external ID used to associate the user with Passage. |
Returns
Result<Vec<WebAuthnDevices>, Error>
a vector of WebAuthnDevices
or an Error
.
Example
// same value used when creating the transaction
let external_id = "00000000-0000-0000-0000-000000000001";
// get devices
let passkey_devices = passage_flex.get_devices(external_id.to_string()).await.unwrap();
for device in passkey_devices {
println!("{}", device.usage_count);
}
get_user()
Get a user by their external ID.
Parameters
Property | Data Type | Description |
---|---|---|
external_id | String | The external ID used to associate the user with Passage. |
Returns
Result<Box<UserInfo>, Error>
the UserInfo
struct or an Error
.
Example
// this should be the same value you used when creating the transaction
let external_id = "00000000-0000-0000-0000-000000000001";
// get user info
let user_info = passage_flex.get_user(external_id.to_string()).await.unwrap();
println!("{:?}", user_info.id);
revoke_device()
Revoke a user's device by their external ID and the device ID.
Parameters
Property | Data Type | Description |
---|---|---|
external_id | String | The identifier used to associate your user with Passage. |
device_id | String | The Passage user's device ID. |
Returns
Result<(), Error>
Whether the user's device has been revoked ()
or an Error.
Example
// same value you used when creating the transaction
let external_id = "00000000-0000-0000-0000-000000000001";
let last_year = Utc::now().naive_utc().date() - Duration::days(365);
// get devices
let passkey_devices = passage_flex.get_devices(external_id.to_string()).await.unwrap();
for device in passkey_devices {
let last_login_at_parsed =
NaiveDate::parse_from_str(&device.last_login_at, "%Y-%m-%dT%H:%M:%S%z").unwrap();
// revoke old devices that haven't been used
if last_login_at_parsed < last_year {
if let Err(err) = passage_flex
.revoke_device(external_id.clone(), device.id)
.await
{
// device couldn't be revoked
}
}
}
verify_nonce()
Verify the nonce received from a WebAuthn registration or authentication ceremony.
Parameters
Property | Data Type | Description |
---|---|---|
nonce | String | The nonce to send to Passage for verification of a successful registration or authentication. |
Returns
Result<String, Error>
the external ID of the verified user as a String
or an Error
.
Example
match passage_flex.verify_nonce("01234567890123456789".to_string()).await {
Ok(external_id) => {
// continue with your custom auth solution, like returning an auth token or initializing a session
}
Err(err) => {
// nonce was invalid or unable to be verified
}
}