@blossm/forwarded-token 0.0.0-stage → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/index.js +9 -0
- package/package.json +18 -4
- package/test/index.js +13 -0
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
The header that carries a caller's token from one service to the next, and how to read it from a request.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```js
|
|
4
|
+
import forwardedToken, { header } from "@blossm/forwarded-token";
|
|
5
|
+
|
|
6
|
+
// Sending
|
|
7
|
+
request.get(url, { headers: { [header]: token } });
|
|
8
|
+
|
|
9
|
+
// Receiving
|
|
10
|
+
const token = forwardedToken(req);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The token travels in a header because query strings are written to request logs.
|
package/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// A caller's token is passed between services in this header, never in a
|
|
2
|
+
// query string: query strings are written to request logs.
|
|
3
|
+
export const header = "blossm-token";
|
|
4
|
+
|
|
5
|
+
// A request made for a user by a service on another network carries that
|
|
6
|
+
// network's own token here, beside the user's: the network vouches for it.
|
|
7
|
+
export const networkHeader = "blossm-network-token";
|
|
8
|
+
|
|
9
|
+
export default (req) => req.headers[header];
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blossm/forwarded-token",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "The header that carries a caller's token between services, and how to read it from a request.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"author": "blossm.network",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">= 24.22.1"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"test": "mocha --recursive"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"mocha": "^12.0.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/test/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
|
|
3
|
+
import forwardedToken, { header } from "../index.js";
|
|
4
|
+
|
|
5
|
+
describe("Forwarded token", () => {
|
|
6
|
+
it("should read the token from its header", () => {
|
|
7
|
+
assert.equal(
|
|
8
|
+
forwardedToken({ headers: { [header]: "some-token" } }),
|
|
9
|
+
"some-token",
|
|
10
|
+
);
|
|
11
|
+
assert.equal(forwardedToken({ headers: {} }), undefined);
|
|
12
|
+
});
|
|
13
|
+
});
|