1 unstable release
0.6.0 | Dec 6, 2022 |
---|
#908 in Authentication
22KB
420 lines
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();
Dependencies
~5–12MB
~158K SLoC