Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove api docs from readme #36

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 1 addition & 151 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,157 +55,7 @@ let passage_flex = PassageFlex::new(

### Go Passwordless

Find more details about Passkey Flex on our [Passkey Flex Documentation](https://docs.passage.id/flex) and [Docs.rs](https://docs.rs/passage_flex/latest/passage_flex/) pages.

## API Reference

### Create a Registration Transaction

To create a transaction to start a user passkey registration, use the `create_register_transaction` method.

```rust
use passage_flex::PassageFlex;

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

let external_id = "a unique immutable string that represents your user".to_string();
let passkey_display_name =
"the label for the user's passkey that they will see when logging in".to_string();

let transaction = passage_flex
.auth
.create_register_transaction(external_id, passkey_display_name)
.await
.unwrap();
```

### Create an Authentication Transaction

To create a transaction to start a user passkey authentication, use the `create_authenticate_transaction` method.

```rust
use passage_flex::PassageFlex;

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

let external_id = "a unique immutable string that represents your user".to_string();

let transaction = passage_flex
.auth
.create_authenticate_transaction(external_id)
.await
.unwrap();
```

## Verify a Nonce

To verify a nonce that you received from the end of of passkey registration or authentication ceremony, use the `verify_nonce` method.

```rust
use passage_flex::PassageFlex;

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

let nonce =
"a unique single-use value received from the client after a passkey ceremony".to_string();

match passage_flex.auth.verify_nonce(nonce).await {
Ok(external_id) => {
// use external_id to do things like generate and send your own auth token
}
Err(err) => {
// nonce was invalid or unable to be verified
}
}
```

## Retrieve User Info

To retrieve information about a user by their external ID -- which is the unique, immutable ID you supply to associate the Passage user with your user -- use the `get` method.

```rust
use passage_flex::PassageFlex;

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

// this is the same value used when creating a transaction
let external_id = your_user.id;

// get user info
let passage_user = passage_flex.user.get(external_id).await.unwrap();
println!("{:?}", passage_user.webauthn_devices);
```

## Retrieve a user's passkey devices

To retrieve information about a user's passkey devices, use the `list_devices` method.

```rust
use passage_flex::PassageFlex;

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

// this is the same value used when creating a transaction
let external_id = your_user.id;

// list devices
let passkey_devices = passage_flex.user.list_devices(external_id).await.unwrap();
for device in passkey_devices {
println!("{}", device.usage_count);
}
```

## Revoke a User's Passkey Device

To revoke a user's passkey device, use the `revoke_device` method.

```rust
use passage_flex::PassageFlex;
use chrono::{Duration, NaiveDate, Utc};

let passage_flex = PassageFlex::new(
std::env::var("PASSAGE_APP_ID").unwrap(),
std::env::var("PASSAGE_API_KEY").unwrap(),
);

// this is the same value used when creating a transaction
let external_id = your_user.id;
let last_year = Utc::now().naive_utc().date() - Duration::days(365);

// list devices
let passkey_devices = passage_flex.user.list_devices(external_id.clone()).await.unwrap();

for device in passkey_devices {
// revoke old devices that haven't been used in the last year
let last_login_at_parsed =
NaiveDate::parse_from_str(&device.last_login_at, "%Y-%m-%dT%H:%M:%S%z").unwrap();

if last_login_at_parsed < last_year {
if let Err(err) = passage_flex
.user
.revoke_device(external_id.clone(), device.id)
.await
{
// device couldn't be revoked
}
}
}
```
Find all core functions and more implementation guidance on our [Passkey Flex Rust Documentation](https://docs.passage.id/flex/rust) page.

## Support & Feedback

Expand Down
Loading