JSPM

@cibel/opentoken

0.7.9
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 260
  • Score
    100M100P100Q100854F
  • License MIT

OpenToken implementation

Package Exports

  • @cibel/opentoken

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cibel/opentoken) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

opentoken

CircleCI Known Vulnerabilities codecov npm GitHub

About

OpenToken implementation

https://tools.ietf.org/html/draft-smith-opentoken-02

Installation

npm install --save @cibel/opentoken

Usage

Example

Import

const OpenToken = require('@cibel/opentoken');

Encoding

Instantiation
// instantiate with pbe password
const otk = new OpenToken('mypassword');

//or instantiate with options
const otk = new OpenToken('mypassword',{notAfter: 300,renewUntil: 300, cipher: OpenToken.CIPHER_AES_256_CBC});
Encoding from raw data
//Encode from raw OpenToken format
const subject = 'Alice';
const payload = 'foo=bar\nbar=baz';
const token = otk.encode(payload, subject);
console.log(token); 
//T1RLAQHYWXG5ELaGj5iUPQr-Enh5Jnm1jxB1xYzddUN5Et3jhYtn4coNAABwodDZZuXqG-lAHs9QGYeyjILE-KmR3lqnD-0wTpEUmQH98WaW0x0fscslpO8A8uqyfWaCuTkeSQOvkit7on1Sb-qg_dnGKLmt0sWigzPhRnNfv5RnpN8lByqwZgL8VIDq3IbSrHGVyvtZ55KC6n1ttQ**
Encoding from Map
// Encode from map
const subject = 'Alice';
const payload =  new Map(['foo','bar'],['bar','baz']);
const token = otk.encodeMap(payload, subject);
console.log(token);
//T1RLAQHYWXG5ELaGj5iUPQr-Enh5Jnm1jxB1xYzddUN5Et3jhYtn4coNAABwodDZZuXqG-lAHs9QGYeyjILE-KmR3lqnD-0wTpEUmQH98WaW0x0fscslpO8A8uqyfWaCuTkeSQOvkit7on1Sb-qg_dnGKLmt0sWigzPhRnNfv5RnpN8lByqwZgL8VIDq3IbSrHGVyvtZ55KC6n1ttQ**

Decoding

Instantiation
const otk = new OpenToken('mypassword');
Decode to OpenToken format
const data = otk.decode(token);
console.log(data);
Decode to Map
const data = otk.decodeAsMap(token);
console.log(data);
//Map { 'subject' => 'Alice','not-before' => '2019-12-06T14:12:53Z','not-on-or-after' => '2019-12-06T14:17:53Z','renew-until' => '2019-12-06T14:17:53Z','foo' => 'bar','bar' => 'baz'
  }

Validation

const otk = new OpenToken('mypassword');
const data = otk.validate(token);

//If we want to validate the subject as well
const subject = 'Alice';
const data = otk.validate(token,subject);
console.log(data);

Configuration

Constants
  • OpenToken.CIPHER_AES_256_CBC
  • OpenToken.CIPHER_AES_128_CBC
  • OpenToken.CIPHER_DES_TRIPLE_168_CBC
Constructor
Arguments Type Required Description Default Value
password string Yes Password N/A
options {} {notAfter, renewUntil, cipher} No OpenToken validation options {notAfter:300,renewUntil:300,OpenToken.CIPHER_AES_256_CBC}
Encoding parameters

[token]=encode(payload, subject)

Argument Required Type Default Description Default value
payload Yes string N/A Raw OpenToken payload N/A
subject No string 'opentoken' OpenToken subject to match with N/A

[token]=encodeMap(payload, subject)

Argument Required Value Default Description Default value
payload Yes Map N/A Key value Opentoken format N/A
subject No string 'opentoken' OpenToken subject to match with N/A
Decoding parameters

[payload]=decode(token)

Argument Required Type Default Description Default value
token Yes string N/A OpenToken payload N/A

[payloadAsMap]=decodeAsMap(token)

Argument Required Type Default Description Default value
token Yes string N/A OpenToken payload as Map N/A
Validate parameters

[payload]=validate(token,subject)

Argument Required Value Default Description Default value
token Yes string N/A OpenToken payload N/A
subject No string N/A OpenToken subject to match with N/A

References

https://tools.ietf.org/html/draft-smith-opentoken-02

License

@cibel/opentoken is MIT licensed