> For the complete documentation index, see [llms.txt](https://docs.hypersign.id/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hypersign.id/hypersign-kyc/kyc-widget/integrations/frontend-integration.md).

# Frontend Integration

### Pre-requisites

Generate your access tokens before proceeding:

{% content-ref url="/pages/u8XWTiyGTIJULYI41CYW" %}
[Generate AccessTokens](/hypersign-kyc/kyc-widget/integrations/backend-integration/generate-accesstokens.md)
{% endcontent-ref %}

Optionally, generate KYC `sessionId` as well.&#x20;

{% content-ref url="/pages/dqe0KT4UsPFvWfC1fCqr" %}
[Generate KYC Session Id](/hypersign-kyc/kyc-widget/integrations/backend-integration/generate-kyc-session-id.md)
{% endcontent-ref %}

### Widget Integration

You'll need to generate a **Widget URL** and insert it into a DOM element. Additionally, you can monitor events triggered by the widget on your webpage to showcase either success or failure. Once the user completes the KYC process successfully, you'll receive an `idToken`, which can be utilised to request the user's data/credentials from the KYC server.

### Forming Widget URL

The Widget URL has  three query params:

1. **`kycAccessToken`**: KYC Access Token
2. **`ssiAccessToken`**: SSI Access Token
3. **`sessionId`**: KYC Session Id

The final Widget URL format would look something like this:

> ```
> https://verify.hypersign.id
> ?kycAccessToken=${kycAccessToken}&ssiAccessToken=${ssiAccessToken}&sessionId=${sessionId}
> ```

### Invoking the widget

You can invoke the Hypersign KYC widget through popup from your page

```javascript
const widgetUrl = `https://verify.hypersign.id
?kycAccessToken=${kycAccessToken}&ssiAccessToken=${ssiAccessToken}&sessionId=${sessionId}`

window.open(widgetUrl, 'Popup Window', 'width=850,height=900');
```

### Listening to events

You can listen to events thrown by the widget to get the result of verification.&#x20;

```javascript
window.addEventListener('message', function (event) {
    if (event.origin === 'https://verify.hypersign.id') {
        console.log('Received message from popup:', event.data);
        // make sure to parse the data before use
        const data = JSON.parse(event.data)
        
        // we send these 3 vaules: 
        // status = success / fail, 
        // message = a simple message (if any)
        const { status, message} = data;
        if (status === 'success') {
            console.log('Successfully finished the KYC')
        }
        else if (status === 'fail') {
            console.log('Failed to finish KYC')
        }
    }
});
```

You can only obtain status of verification through events. But in order to **get user data,** developers need to configure the **webhook** on their KYC dashboard.&#x20;

{% content-ref url="/pages/7FKd4OGFmtwj3wLKU2HT" %}
[Webhook](/hypersign-kyc/integrations/webhook.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.hypersign.id/hypersign-kyc/kyc-widget/integrations/frontend-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
