Crates.io | passage-id |
lib.rs | passage-id |
version | 0.2.0 |
source | src |
created_at | 2023-01-26 10:05:45.297278 |
updated_at | 2023-04-26 16:05:16.939022 |
description | Server SDK for passage.id authentication |
homepage | |
repository | https://github.com/robyoder/passage-rust/ |
max_upload_size | |
id | 768341 |
size | 24,987 |
This crate provides a library for working with Passage, a modern passwordless authentication experience based on passkeys and magic links. This library currently implements a very small subset of the available Passage API endpoints.
At the moment, this SDK assists with server-side authentication.
cargo add passage-id
extern crate passage_id;
use crate::passage_id::Passage;
fn main() {
// Your app id from https://console.passage.id/settings
let app_id = "...";
// Create an api key for your app at https://console.passage.id/settings/apikeys
let api_key = "...";
// Download your app's public jwk key from https://auth.passage.id/v1/apps/{app_id}/.well-known/jwks.json. Note this is a single key, not an array.
let pub_key = r#"{
"alg": "RS256",
"kty": "RSA",
"use": "sig",
"n": "...",
"e": "AQAB",
"kid": "..."
}"#;
// The Passage struct can be created once, stored/cached, and reused across multiple requests.
let passage = Passage::new(String::from(app_id), String::from(api_key), String::from(pub_key));
// If you are using an Element, the Passage JWT will be sent to your application via a cookie with the key `psg_auth_token`
let psg_auth_token = "...";
let result = passage.authenticate_token(psg_auth_token);
match result {
Ok(passage_user_id) => println!(
"Passage JWT is valid. passage_user_id=<{}>",
passage_user_id
),
Err(err) => {
println!("Auth error: {:?}", err);
}
}
}