ontlogin-sdk-js
OntLogin SDK for JavaScript provides easy integration for your application to OntLogin.
Documentation
Visit docs.ont.io
Getting Started
ES Module
- 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 'auth request' and get 'challenge' from your server.
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 });