Crate vapid

source ·
Expand description

VAPID auth support

This library only supports the latest VAPID-draft-02+ specification.

Example Use:

use vapid::{Key, sign};
use std::collections::HashMap;

// Create a key from an existing EC Private Key PEM file.
// You can generate this with
// Key::generate().to_pem("pem/file/path.pem");
let my_key = Key::from_pem("pem/file/path.pem").unwrap();

// Construct the Claims hashmap
let mut claims:HashMap<String, serde_json::Value> = HashMap::new();
claims.insert(
    String::from("sub"), serde_json::Value::from("mailto:bob@example.com")
);
// while `exp` can be filled in for you, `aud` should point to the net location of the
// Push server you wish to talk to. (e.g. `https://push.services.mozilla.org`)
// `aud` is optional for Mozilla, but may be required for GCM/FCM or other systems.
claims.insert(
    String::from("aud"), serde_json::Value::from("https://host.ext")
);

// The result will contain the `Authorization:` header. How you inject this into your
// request is left as an exercise.
let authorization_header = sign(my_key, &mut claims).unwrap();

Structs

a Key is a helper for creating or using a VAPID EC key.

Functions

Convert the HashMap containing the claims into an Authorization header. key must be generated or initialized before this is used. See Key::from_pem() or Key::generate().
Verify that the auth token string matches for the verification token string