passage-id

Crates.iopassage-id
lib.rspassage-id
version0.2.0
sourcesrc
created_at2023-01-26 10:05:45.297278
updated_at2023-04-26 16:05:16.939022
descriptionServer SDK for passage.id authentication
homepage
repositoryhttps://github.com/robyoder/passage-rust/
max_upload_size
id768341
size24,987
Rob Yoder (robyoder)

documentation

README

Passage logo

Passage SDK for Rust

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.

Installation

cargo add passage-id

Example: validation of Passage JWTs

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);
        }
    }
}
Commit count: 29

cargo fmt