Git Product home page Git Product logo

Comments (3)

mitsuhiko avatar mitsuhiko commented on May 22, 2024 1

That is currently somewhat intentional. What you can do today is to use serde to serialize the value into something else. That's obviously not entirely ideal, but might be what you actually need. Can you share what you are trying to do? I'm happy to try to figure out an API to iterate over values and to expose the maps (in some form), but for that it would be interesting to understand the intended use.

from minijinja.

sassman avatar sassman commented on May 22, 2024

Nice idea, I was able to go via serde_json::from_str into a HashMap<String, serde_json::Value>.
The HashMap is then mutable and all works well. The double serialization is right now not ideal, but also not a big issue in my case.

The example looks something like this:

pub fn jwt(_state: &State, claims: Value, signing_key: Option<Value>) -> Result<String, Error> {
    let mut claims: HashMap<String, serde_json::Value> =
        serde_json::from_str(claims.to_string().as_str()).unwrap();

    // in case the expiry is missing, we expire it in 15min
    if claims.contains_key(EXPIRY).not() {
        let expire_in = Utc::now()
            .add(Duration::minutes(15))
            .with_second(0)
            .unwrap()
            .timestamp();
        claims.insert(EXPIRY.to_string(), serde_json::Value::from(expire_in));
    }

    let token = jsonwebtoken::encode(
        &Header::default(),
        &claims,
        &EncodingKey::from_secret(b"secret"),
    );

    token.map_err(|e| {
        Error::new(
            ErrorKind::UndefinedError,
            "jsonwebtoken failed to encode the token.",
        )
        .with_source(e)
    })
}

from minijinja.

sassman avatar sassman commented on May 22, 2024

Thanks a lot @mitsuhiko ❤️

from minijinja.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.