#passage #sdk #id #server #server-side #assists

passage-id

Server SDK for passage.id authentication

5 releases

0.2.0 Apr 26, 2023
0.1.3 Feb 3, 2023
0.1.2 Feb 3, 2023
0.1.1 Jan 26, 2023
0.1.0 Jan 26, 2023

#606 in Authentication

MIT license

24KB
206 lines

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);
        }
    }
}

Dependencies

~6.5–9MB
~263K SLoC