1.1.0 • Published 3 years ago

trusona-trucode v1.1.0

Weekly downloads
239
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

Web SDK - TruCode

A JavaScript library for rendering TruCodes used for identifying Trusona enabled devices.

Requirements

The Trusona Web SDK is supported by the following browsers:

  • Internet Explorer 10 or higher
  • Microsoft Edge (latest version)
  • Google Chrome (latest version)
  • Firefox (latest version)
  • Safari (latest version)

Installation

From the Trusona CDN

Include the trucode.js script tag before the </body> of your document

  <!-- existing content -->
  <script type="text/javascript"src="https://static.trusona.net/web-sdk/js/trucode-1.1.0.js"></script>
  </body>
</html>

As an NPM package

npm install --save trusona-trucode

Import it with:

const Trusona = require('trusona-trucode')

Usage

Given this HTML:

  <div id="tru-code">
  </div>

And this Javascript on the same page:

  var handlePaired = function(truCodeId) {
    // The truCodeId that was scanned by a Trusona enabled device. Send this to your backend so they can figure out the deviceIdentifier.
  };

  var handleError = function() {
    // If an error occurred fetching the TruCode and/or it could not be rendered.
  };

  Trusona.renderTruCode({
    truCodeConfig: {
      truCodeUrl: 'https://api.trusona.net',
      relyingPartyId: '<YOUR_RELYING_PARTY_ID>',
      qr: {}
    },
    truCodeElement: document.getElementById('tru-code'),
    onPaired: handlePaired,
    onError: handleError
  });

Then an SVG representation of a QR Code will be drawn using default colors and animated using the default animation parameters.

Options

NameRequiredDefaultDescription
truCodeConfigYnullThe configuration for the fetching and rendering of TruCodes. Is provided by the Server SDK.
truCodeUrlYnullThe Trusona API URL where to fetch TruCodes from.
relyingPartyIdYnullThe Trusona issued relying party ID that has been assigned to your company.
qrNsee belowThe configuration for rendering TruCodes (colors, width, animations, etc).
truCodeElementYnullThe DOM element to contain the rendered TruCodes.
onPairedYnullThe callback function to call when a TruCode has been scanned. It will be passed a string parameter containing the TruCodeId that was paired.
onErrorYfalseThe callback function to call if an error occurred fetching or rendering TruCodes.

QR Options

An optional parameter allows for customization of the SVG drawing.

  • Shape Colors
  • Dot Color
  • Container Width
  • Animation Configuration

Shape Colors

An array of HEX color codes can be used to specify the colors to be used when drawing the SVG.

Default:

  ["#000"]

Custom:

  var qrConfig = {shapeColors: ["#0f0", "#f00", "#00f"]};

  Trusona.renderTruCode({
    truCodeConfig: {
      truCodeUrl: 'https://api.trusona.net',
      relyingPartyId: '<YOUR_RELYING_PARTY_ID>',
      qr: qrConfig
    },
    truCodeElement: document.getElementById('tru-code'),
    onPaired: handlePaired,
    onError: handleError
  });

Dot Color

A single HEX color code can be used to specify the color of any individual dots drawn in the SVG.

Default:

"#000"

Custom:

  var qrConfig = {dotColor: "#0f0"};

  Trusona.renderTruCode({
    truCodeConfig: {
      truCodeUrl: 'https://api.trusona.net',
      relyingPartyId: '<YOUR_RELYING_PARTY_ID>',
      qr: qrConfig
    },
    truCodeElement: document.getElementById('tru-code'),
    onPaired: handlePaired,
    onError: handleError
  });

Rendering Arbitrary Payloads

You can use this SDK to also render QR codes with your own provided payloads instead of the TruCode payload that is automatically fetched. For example, if you use our guide for Passwordless Authentication without an app.

Given the same HTML from above:

  <div id="tru-code">
  </div>

And this JavaScript on the page

Trusona.drawTruCode(document.getElementById('tru-code'), 'your-own-payload')

Then an SVG of a QR code with 'your-own-payload' as the content will be drawn using default colors and animated using the default animation parameters. You can also provide the QR options detailed above to customize the look of the drawn QR.

  var qrConfig = {shapeColors: ["#0f0", "#f00", "#00f"]};

  Trusona.drawTruCode(document.getElementById('tru-code'), 'your-own-payload', qrConfig);
1.1.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago