Skip to content

Commit

Permalink
Update imports + fix quote position
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmstill authored Sep 24, 2023
1 parent 8fbf474 commit c592416
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions docs/src/usage/nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,17 +56,17 @@ for (let right of ["read", "write"]) {
builder.addFact(fact`right(${right})`);
}

const privateKey = PrivateKey.fromString("<private key">);
const privateKey = PrivateKey.fromString("<private key>");
const token = builder.build(privateKey);
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("<public key">);
const publicKey = PublicKey.fromString("<public key>");
const token = Biscuit.fromBase64("<base64 string>", publicKey);

const userId = "1234";
Expand All @@ -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("<public key">);
const publicKey = PublicKey.fromString("<public key>");
const token = Biscuit.fromBase64("<base64 string>", publicKey);

// restrict to read only
Expand All @@ -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("<public key">);
const publicKey = PublicKey.fromString("<public key>");
const token = Biscuit.fromBase64("<base64 string>", publicKey);

const sealedToken = token.sealToken();
Expand All @@ -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("<public key">);
const publicKey = PublicKey.fromString("<public key>");
const token = Biscuit.fromBase64("<base64 string>", publicKey);

// revocationIds is a list of hex-encoded revocation identifiers,
Expand All @@ -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("<base64 string>");
const publicKey = PublicKey.fromString("<public key>");
const token = Biscuit.fromBase64("<base64 string>", publicKey);

const userId = "1234";
const auth = authorizer`
Expand Down

0 comments on commit c592416

Please sign in to comment.