#key #header #rfc #server #web-push #sign

vapid

实现了RFC 8292自愿应用程序服务器标识(VAPID)Auth头部生成器

1个不稳定版本

0.6.0 2022年12月6日

#1017 in 身份验证

Download history 22/week @ 2024-04-15 14/week @ 2024-04-22 1/week @ 2024-05-13 54/week @ 2024-07-01 29/week @ 2024-07-08 8/week @ 2024-07-29

每月75次下载

MPL-2.0 许可证

22KB
420

VAPID身份验证支持

此库仅支持最新的VAPID-draft-02+规范。

使用示例

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:[email protected]")
);
// 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();

依赖项

~5.5–7.5MB
~158K SLoC