ontlogin
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

ontlogin-sdk-js

OntLogin SDK for JavaScript provides easy integration for your application to OntLogin.

Documentation

Visit docs.ont.io

Getting Started

ES Module

  1. Install and import package.

via NPM package:

npm i ontlogin
import { createAuthRequest } from "ontlogin";

via js bundle:

<script src="ontlogin.min.js"></script>
<script>
  ontlogin.createAuthRequest();
</script>

via es module js bundle:

import { createAuthRequest } from "ontlogin.es.js";
  1. Generate 'auth request' and get 'challenge' from your server.
import { createAuthRequest } from "ontlogin";

const authRequest = createAuthRequest();
const challenge = await fetch("server-url", { body: authRequest });
  1. Get QR code from ontlogin QR server.
import { requestQR } from "ontlogin";

const { text, id } = await requestQR(challenge);
  1. Show QR code ui and query scan result from ontlogin QR server.
import { queryQRResult, cancelQueryQRResult, ErrorEnum } from "ontlogin";

try {
  const challengeResponse = await queryQRResult(id);
} catch (e) {
  if (e.message === ErrorEnum.UserCanceled) {
    // handle cancel
  } else {
    // handle error
  }
}

cancelQueryQRResult(); // Cancel fetching result if you need.
  1. Submit 'challenge response' to your server.
fetch("server-url", { body: challengeResponse });

Example apps

Readme

Keywords

Package Sidebar

Install

npm i ontlogin

Weekly Downloads

89

Version

0.0.11

License

ISC

Unpacked Size

450 kB

Total Files

55

Last publish

Collaborators

  • yzy123123