# Integration and Usage

## Example apps

* [vue](https://github.com/ontology-tech/ontlogin-sdk-js/tree/main/example/vue-demo)
* [pure HTML](https://github.com/ontology-tech/ontlogin-sdk-js/tree/main/example/html-demo)

## Install and import package

&#x20;via NPM [package](https://npmjs.com/package/ontlogin)

```javascript
npm i ontlogin
```

```javascript
import {createAuthRequest} from "ontlogin";
```

via [js bundle](https://github.com/ontology-tech/ontlogin-sdk-js/blob/main/dist/ontlogin.min.js)

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

via [es module js bundle](https://github.com/ontology-tech/ontlogin-sdk-js/blob/main/dist/ontlogin.es.js)

```javascript
import {createAuthRequest} from "ontlogin.es.js";
```

## Generate `authRequest` and challenge

```javascript
import { createAuthRequest } from "ontlogin";

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

## Get QR code from ontlogin QR server.

```javascript
import { requestQR } from "ontlogin";

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

## Show QR code UI and query scan result from ontlogin QR server

```javascript
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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ont.io/decentralized-identity-and-data/ontid/ont-login/front-end-javascript-sdk/integration-and-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
