New Token API
- Move all of the previous structs to the
legacy
module - Introduce more idiomatic
Header
,Claims
, andToken
types - Support more algorithms with optional OpenSSL support
- Convenience methods to just sign and verify claims
For most, the following should be enough with their own defined claims types:
With the following key:
let key: Hmac<Sha256> = Hmac::new_varkey(b"some-secret").unwrap();
Signing:
let mut claims = BTreeMap::new();
claims.insert("sub", "someone");
let token_str = claims.sign_with_key(&key).unwrap();
Verification:
let token_str = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJzb21lb25lIn0.5wwE1sBrs-vftww_BGIuTVDeHtc1Jsjo-fiHhDwR8m0";
let claims: BTreeMap<String, String> = VerifyWithKey::verify_with_key(token_str, &key).unwrap();