All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rust-server.example-client-auth.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
use {{{externCrateName}}}::Claims;
use jsonwebtoken::{encode, errors::Error as JwtError, Algorithm, EncodingKey, Header};
use log::debug;

/// build an encrypted token with the provided claims.
pub fn build_token(my_claims: Claims, key: &[u8]) -> Result {

    // Ensure that you set the correct algorithm and correct key.
    // See https://github.com/Keats/jsonwebtoken for more information.
    let header =
        Header { kid: Some("signing_key".to_owned()), alg: Algorithm::HS512, ..Default::default() };

    let token = encode(&header, &my_claims, &EncodingKey::from_secret(key))?;
    debug!("Derived token: {:?}", token);

    Ok(token)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy