Function asap_deps_jsonwebtoken::encode [−][src]
pub fn encode<T: Serialize>(
header: &Header,
claims: &T,
key: &[u8]
) -> Result<String>
Encode the header and claims given and sign the payload using the algorithm from the header and the key
ⓘThis example is not tested
#[macro_use] extern crate serde_derive; use jsonwebtoken::{encode, Algorithm, Header}; /// #[derive(Debug, Serialize, Deserialize)] struct Claims { sub: String, company: String } let my_claims = Claims { sub: "b@b.com".to_owned(), company: "ACME".to_owned() }; // my_claims is a struct that implements Serialize // This will create a JWT using HS256 as algorithm let token = encode(&Header::default(), &my_claims, "secret".as_ref()).unwrap();