GithubHelp home page GithubHelp logo

Comments (4)

MidasLamb avatar MidasLamb commented on August 9, 2024 2

I've also discovered in the meantime that querying is only possible for tuples out of the box, and if you'd expect a singular string, you have to use (String, ), so I can also try to add TryFrom<Fact> for some commonly used "base" types

from biscuit-rust.

MidasLamb avatar MidasLamb commented on August 9, 2024

After a bit of investigating it seems to be that when the authorizer is constructed from the token, it doesn't populate the world with the information from the token, which it seems that it should do that?

pub(crate) fn from_token(token: &'t Biscuit) -> Result<Self, error::Token> {
        let mut v = Authorizer::new()?;
        v.token = Some(token);

        Ok(v)
    }

Or the querying must be extended in the same way that authorize_with_limits extends the world with information from the token if it's present:

 if let Some(token) = self.token.as_ref() {
            for fact in token.authority.facts.iter().cloned() {
                let fact = Fact::convert_from(&fact, &token.symbols).convert(&mut self.symbols);
                self.world.facts.insert(fact);
            }

            let mut revocation_ids = token.revocation_identifiers();
            let revocation_id_sym = self.symbols.get("revocation_id").unwrap();
            for (i, id) in revocation_ids.drain(..).enumerate() {
                self.world.facts.insert(datalog::Fact::new(
                    revocation_id_sym,
                    &[datalog::Term::Integer(i as i64), datalog::Term::Bytes(id)],
                ));
            }

            for rule in token.authority.rules.iter().cloned() {
                let r = Rule::convert_from(&rule, &token.symbols);
                let rule = r.convert(&mut self.symbols);

                if let Err(_message) = r.validate_variables() {
                    return Err(
                        error::Logic::InvalidBlockRule(0, token.symbols.print_rule(&rule)).into(),
                    );
                }
            }
        }

however re-adding information to the world each time one of these functions is called seems off, so I think the best way forward would be to extract the above snippet into the functions that set the token, to ensure the world is populated once.

If you agree I'll create a PR for this approach.

from biscuit-rust.

johnhainline avatar johnhainline commented on August 9, 2024

Did this ever go anywhere? I'm having a similar issue of pulling data from a Biscuit. It'd be great to have easy access to user/expiration facts inside the token.

from biscuit-rust.

MidasLamb avatar MidasLamb commented on August 9, 2024

@johnhainline , the issues I had were resolved in #52

from biscuit-rust.

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.