pub fn make_token<K: AsRef<str>, D: Serialize>(
    key: K,
    data: D
) -> Result<String>
Expand description

Generate a signed token from an encryption key and a serializable payload.

The generated token will be valid for six hours.

The encryption key must be exactly 32 characters long, else an error will be returned.

Examples

use serde::Serialize;

#[derive(Serialize)]
struct UserInfo {
    username: String,
    is_admin: bool
}

let encryption_key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // 32 characters.
let token_data = UserInfo{username: "johnsmith".into(), is_admin: true};

let token = menmos_auth::make_token(encryption_key, &token_data)?;