Integration and Usage

Example apps

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";

Generate authRequest and challenge

import { createAuthRequest } from "ontlogin";

const authRequest = createAuthRequest();
const challenge = await fetch("server-url", { body: authRequest });

Get QR code from ontlogin QR server.

import { requestQR } from "ontlogin";

const { text, id } = await requestQR(challenge);

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.

Submit challenge response to your server

fetch("server-url", { body: challengeResponse });

Last updated