1.0.1 • Published 5 years ago

url-expire-token-builder v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

Url Expire Token Builder

Allows you to send files and have the link expire after a certain amount of time. Can be used for hotlink protection.

This is separate from minio url sharing, which saves data in the background for each share you do, which can be too slow for mass sharing of many files (aka a app that builds expire tokens for 20 files automatically for each pageload). A good use for this would be a sidecar node app that serves files, while minio itself is in the private network (where private kube deps upload the files to minio).

A possible usecase would be a kube minio/node sidecar:

  • minio is locked in the private network, and allows uploads from other kube deployments.
  • public node app that serves the files, but locks them down based on expire tokens.

Install

npm i --save url-expire-token-builder

Usage

Create a builder. You will need to use the same key for both the requester and the server.

var UrlExpireTokenBuilder = require('url-expire-token-builder');
var builder = new UrlExpireTokenBuilder({
    key: 'lkwjrklnV*O&349743',
    ttl: 60 * 60 * 2 * 1000, // 2 hrs
});

Build the url when sending the html for the file:

<img src="//example.com/aa/bb.png" />
becomes:
<img src="${builder.addTokenToUrl('//example.com/aa/bb.png')}" />

Require the token when serving the file:

router.use(builder.requireTokenMiddleware());
router.use(express.static(path.join(__dirname, 'files')));

Tada. Now files are only valid for 2 hrs after pageload.

Config

You can pass an obj with these vars to the constructor:

{
    "key": a string to encrypt the tokens with
    "ttl": how long to live in ms
    "verbose": bool. makes it clutter your logs
}
1.0.1

5 years ago

1.0.0

5 years ago