# Consent

{% hint style="warning" %}
Sample code uses ES6 language features such as arrow functions and promises. For compatibility with IE11, code written with these features must be either transpiled using tools like Babel or refactored accordingly using callbacks.
{% endhint %}

## Introduction

The Trust1Connector supports user consent mechanism for applications:

implicit user consent: the user will be provided with a consent token which can be pasted into his clipboard. The T1C-GCL will implicitly retrieve the consent token form the clipboard and perform a verification (the token pasted in the clipboard - form the application context - should match with the token available on the clipboard for the T1C-GCL)

The consent can be configured to have an expiration date, when this expiration date has been exceeded, a new consent will be asked towards the user.

{% hint style="info" %}
The implementation of the consent flows only apply with the T1C JS SDK. Implementation with the API directly is different
{% endhint %}



## Consent dialog for implicit consent

If the consent has been enabled upon installation of the Trust1Connector, a user will not be able to retrieve any data from the connector without first giving its consent, agreeing to give access to his/her card reader of filestorage. Without this consent, all requests will return a **401 Unauthorized** response with  error code **500 No valid consent found** or at initialisation of the Trust1Connector SDK an error code **500 No valid consent found**. The application should detect these error codes and use it to trigger the consent dialog.&#x20;

![](https://162049279-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MA0NIpdSCJTdfFxKB45%2F-MBiH3rSHZ1Mt6pzfgBB%2F-MBiHHOgHk62Cajaejgr%2Fimage.png?alt=media\&token=d081e647-4327-4b28-97f1-24caef7e2566)

The application shows this code word on screen and provide a button for 'copy-to-clipboard'. When the user has copied the code word to the clipboard (on user click button event), an implicit consent request can be executed towards the T1C. The T1C will grab the pasted code word from the user system clipboard and if both match, an implicit user consent has been granted for the calling application. The relation between the application and the local T1C instance is 'approved'. At this point the Trust1Connector returns a cookie that should be stored in the browser. This cookie will be re-used the next time the user wants to use the Trust1Connector until the cookie expires.

### User clipboard remark

Initially the concept was based on copying programmatically the code word, from the application context, to the user system clipboard. Although, through CAB forum, this not allowed; A user interaction is mandatory. The application should provide a 'copy-to-clipboard' button or alike in order to 'trigger' a user action. Once this action has been done, the T1C executes the flow automatically, this is retrieval and verification of the code word.&#x20;

Currently, the need for a user interaction is a known limitation (aka. [clipboard.js](https://github.com/zenorocha/clipboard.js/wiki/Known-Limitations)). As this is the case, the W3C has a project ' [Clipboard APIs](https://w3c.github.io/clipboard-apis)' to propose a solution for a new clipboard API in browsers. The use case for 'Remote clipboard synchronisation' as a use case included in this draft proposal. As this is a draft, and not yet supported by the browsers, we can not perform an automatic 'paste' ('copy' in terms of the browser) to the clipboard.

Sending an implicit consent request can be done as follows:

```javascript
T1CSdk.T1CClient.initialize(config).then(res => {
    client = res;
    console.log("Client config: ", client.localConfig)
    core = client.core();
}, err => {
    if (err.code == 814501) {
        console.log(err)
        client = err.client
        $('#consentModal').modal('show', {
            keyboard: false
        });
        $('.consent-token').text(makeid(20));
    } else if (err.code == 815500) {
        $('.consent-token').text(makeid(20));
    } else if (err.code == 112999) {
        // General
    } else {
        console.error("T1C error:", err)
    }
});
    
```

```javascript
$('#consentModal .btn-primary').on('click', (ev) => {
    const tokenNode = document.querySelector('.consent-token');
    var range = document.createRange();
    range.selectNode(tokenNode);
    window.getSelection().addRange(range);
    try {
        document.execCommand('copy');
    } catch (err) {
        console.log('Oops, unable to copy');
    }
    window.getSelection().removeRange(range);
    const clipboardData = tokenNode.textContent;
    
    client.core().getImplicitConsent(clipboardData).then(consentRes => {
        client = consentRes // replace the client and other set variables of the T1C
        core = client.core();
        core.version().then(versionResult => console.log("T1C running on core " + versionResult));
        $('#consentModal').modal('hide');
    }, err => {
        console.error(err)
    })
});
```

This call has 1 required and 2 optional parameters:

1. **Code Word** _(required)_: a code word in string format that will be shown in the consent dialog.
2. **Consent duration in days** _(optional)_: Allows the application the specify how long this consent is to be valid if granted. If not provided, the default value is 365 days.
3. **Callback function** _(optional)_: function to be called with the result of the consent request.

The response of the consent will be an updated T1C Client which you after this point can use to continue your use-case(s).

The response can also be a **400 Bad Request with status code 814501 or 814500 "No agents registered to the proxy service"** which means that the request has been sent with the unique code but the Proxy cannot not find the user associated with it by checking the clipboards of all connected users.

This could mean that there is no T1C API client present or it is not running correctly.
