From 8fbf474902d0e80a92b610eb0360ec8fdea24d0b Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Sun, 24 Sep 2023 11:23:35 +0100 Subject: [PATCH 1/2] Fix nodejs.md examples --- docs/src/usage/nodejs.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/src/usage/nodejs.md b/docs/src/usage/nodejs.md index 1118a16..9ec9e8d 100644 --- a/docs/src/usage/nodejs.md +++ b/docs/src/usage/nodejs.md @@ -44,20 +44,20 @@ const root = new KeyPair(); ```javascript const { biscuit, KeyPair } = require('@biscuit-auth/biscuit-wasm'); -const root = new KeyPair(); const userId = "1234"; // a token can be created from a datalog snippet -const biscuitBuilder = biscuit` +const builder = biscuit` user(${userId}); check if resource("file1"); `; // facts, checks and rules can be added one by one on an existing builder. for (let right of ["read", "write"]) { - biscuitBuilder.addFact(fact`right(${right})`); + builder.addFact(fact`right(${right})`); } -const token = builder.build(root); +const privateKey = PrivateKey.fromString("); +const token = builder.build(privateKey); console.log(token.toBase64()); ``` @@ -66,7 +66,8 @@ console.log(token.toBase64()); ```javascript const { authorizer, Biscuit } = require('@biscuit-auth/biscuit-wasm'); -const token = Biscuit.fromBase64(""); +const publicKey = PublicKey.fromString("); +const token = Biscuit.fromBase64("", publicKey); const userId = "1234"; const auth = authorizer` @@ -93,7 +94,8 @@ const acceptedPolicyCustomLimits = authorizer.authorizeWithLimits({ ```javascript const { block, Biscuit } = require('@biscuit-auth/biscuit-wasm'); -const token = Biscuit.fromBase64(""); +const publicKey = PublicKey.fromString("); +const token = Biscuit.fromBase64("", publicKey); // restrict to read only const attenuatedToken = token.append(block`check if operation("read")`); @@ -107,7 +109,8 @@ A sealed token cannot be attenuated further. ```javascript const { Biscuit } = require('@biscuit-auth/biscuit-wasm'); -const token = Biscuit.fromBase64(""); +const publicKey = PublicKey.fromString("); +const token = Biscuit.fromBase64("", publicKey); const sealedToken = token.sealToken(); ``` @@ -118,7 +121,8 @@ const sealedToken = token.sealToken(); ```javascript const { Biscuit } = require('@biscuit-auth/biscuit-wasm'); -const token = Biscuit.fromBase64(""); +const publicKey = PublicKey.fromString("); +const token = Biscuit.fromBase64("", publicKey); // revocationIds is a list of hex-encoded revocation identifiers, // one per block From c592416430ff8fc773c110fae6d93ce82a3f65a1 Mon Sep 17 00:00:00 2001 From: Malcolm Still Date: Sun, 24 Sep 2023 11:32:01 +0100 Subject: [PATCH 2/2] Update imports + fix quote position --- docs/src/usage/nodejs.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/src/usage/nodejs.md b/docs/src/usage/nodejs.md index 9ec9e8d..f8948c2 100644 --- a/docs/src/usage/nodejs.md +++ b/docs/src/usage/nodejs.md @@ -42,7 +42,7 @@ const root = new KeyPair(); ## Create a token ```javascript -const { biscuit, KeyPair } = require('@biscuit-auth/biscuit-wasm'); +const { biscuit, PrivateKey } = require('@biscuit-auth/biscuit-wasm'); const userId = "1234"; // a token can be created from a datalog snippet @@ -56,7 +56,7 @@ for (let right of ["read", "write"]) { builder.addFact(fact`right(${right})`); } -const privateKey = PrivateKey.fromString("); +const privateKey = PrivateKey.fromString(""); const token = builder.build(privateKey); console.log(token.toBase64()); ``` @@ -64,9 +64,9 @@ console.log(token.toBase64()); ## Authorize a token ```javascript -const { authorizer, Biscuit } = require('@biscuit-auth/biscuit-wasm'); +const { authorizer, Biscuit, PublicKey } = require('@biscuit-auth/biscuit-wasm'); -const publicKey = PublicKey.fromString("); +const publicKey = PublicKey.fromString(""); const token = Biscuit.fromBase64("", publicKey); const userId = "1234"; @@ -92,9 +92,9 @@ const acceptedPolicyCustomLimits = authorizer.authorizeWithLimits({ ## Attenuate a token ```javascript -const { block, Biscuit } = require('@biscuit-auth/biscuit-wasm'); +const { block, Biscuit, PublicKey } = require('@biscuit-auth/biscuit-wasm'); -const publicKey = PublicKey.fromString("); +const publicKey = PublicKey.fromString(""); const token = Biscuit.fromBase64("", publicKey); // restrict to read only @@ -107,9 +107,9 @@ console.log(attenuatedToken.toBase64()); A sealed token cannot be attenuated further. ```javascript -const { Biscuit } = require('@biscuit-auth/biscuit-wasm'); +const { Biscuit, PublicKey } = require('@biscuit-auth/biscuit-wasm'); -const publicKey = PublicKey.fromString("); +const publicKey = PublicKey.fromString(""); const token = Biscuit.fromBase64("", publicKey); const sealedToken = token.sealToken(); @@ -119,9 +119,9 @@ const sealedToken = token.sealToken(); ```javascript -const { Biscuit } = require('@biscuit-auth/biscuit-wasm'); +const { Biscuit, PublicKey } = require('@biscuit-auth/biscuit-wasm'); -const publicKey = PublicKey.fromString("); +const publicKey = PublicKey.fromString(""); const token = Biscuit.fromBase64("", publicKey); // revocationIds is a list of hex-encoded revocation identifiers, @@ -137,9 +137,10 @@ if (containsRevokedIds(revocationIds)) { ## Query data from the authorizer ```javascript -const { authorizer, rule, Biscuit } = require('@biscuit-auth/biscuit-wasm'); +const { authorizer, rule, Biscuit, PublicKey } = require('@biscuit-auth/biscuit-wasm'); -const token = Biscuit.fromBase64(""); +const publicKey = PublicKey.fromString(""); +const token = Biscuit.fromBase64("", publicKey); const userId = "1234"; const auth = authorizer`