Git Product home page Git Product logo

hypersign-auth-js-sdk's Introduction

Hypersign dAuth Javascript Frontend SDK

Step1: Create a DOM with id hs-auth-btn or hs-auth-qr or both

For Hypersign Login Button

<div id="hs-auth-btn"></div>

For Hypersign QR code

<canvas id="hs-auth-qr"></canvas>

Step2: Add appropriate script

You can use Hypersign dAuth in either of two modes.

  1. Websocket
  2. Polling

Using Websocket

<script
  src="https://cdn.jsdelivr.net/gh/hypersign-protocol/[email protected]/build/hs-auth-js-sdk.js"
  data-rp-socket-url="ws://localhost:4006"
></script>

Other optional paramaters:

<script
  src="https://cdn.jsdelivr.net/gh/hypersign-protocol/[email protected]/build/hs-auth-js-sdk.js"
  data-network-mode="TEST" // Network mode TEST | MAIN. Default value 'MAIN'
  data-listener-mode="SOCKET" // Listener mode SOCKET | POLLING. Default value 'SOCKET'
  data-rp-socket-url="ws://localhost:4006" // Relying party websocket URL
  data-login-button-text="lOGIN wITH hYPERSIGN" // Login button text. Default 'LOGIN USING HYPERSIGN'
></script>

Using Polling

<script
  src="https://cdn.jsdelivr.net/gh/hypersign-protocol/[email protected]/build/hs-auth-js-sdk.js"
  data-listener-mode="POLLING"
  data-rp-server-base-url="http://localhost:4006"
></script>

Other optional paramaters:

<script
  src="https://cdn.jsdelivr.net/gh/hypersign-protocol/[email protected]/build/hs-auth-js-sdk.js"
  data-network-mode="TEST" // Network mode TEST | MAIN. Default value 'MAIN'
  data-listener-mode="POLLING" // Listener mode SOCKET | POLLING. Default value 'SOCKET'
  data-rp-server-base-url="http://localhost:4006" // Relying party server base URL
  data-rp-challege-resource="/challenge" // Challenge resource path. Default value '/api/v1/auth/challenge'
  data-rp-polling-resource="/poll" // Polling resource path. Default value '/api/v1/auth/poll'
  data-login-button-text="lOGIN wITH hYPERSIGN" // Login button text. Default 'LOGIN USING HYPERSIGN'
  data-polling-interval="5000" // Polling interval. Default value 5000
></script>

Step3: Listen to Events

hs-success

You can listen to hs-success event for getting accessToken and refreshToken once the user is successfully authenticated. Example:

document.addEventListener('hs-success', function (e) {
  alert(JSON.stringify(e.detail));
});

Output

{
    "accessToken": "<JWT Token>",
    "refreshToken": "<JWT Token>"
}

hs-error

You can listen to hs-error event for any other error.

document.addEventListener('hs-error', function (e) {
  console.error(e.detail);
});

Installation

npm i

Run the project

npm run dev

Browse the login page http://localhost:1234

img

hypersign-auth-js-sdk's People

Contributors

vishwas1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

cryptozenci

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.