T1C-JS Guide (v3)
Search…
Consent

Introduction

The Trust1Connector requires a user consent to function. This consent will be stored in the browsers localstorage for that user.
The consent token is stored with a domain specific key;t1c-consent-{{applicationDomain}}::{{apiUrl}}
When executing the consent flow, the user will be provided with a consent token which can be pasted into his clipboard. This token has to be passed with the Consent function which will perform a verfication (the token pasted in the clipboard - form the application context - should match with the token available on the clipboard for the T1C).
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.

Consent dialog for implicit consent

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/404 Unauthorized response with error No valid consent found or at initialisation of the Trust1Connector SDK an error No valid consent found. The application should detect these errors and use it to trigger the consent dialog.
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 verified consent object that is stored in the browser's localstorage. This object is used to validate the consent and retrieve the necessary information for the Trust1Connector to function. This object will be re-used the next time the user wants to use the Trust1Connector until the consent 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 can be triggered to execute the consent.
Currently, the need for a user interaction is a known limitation (aka. clipboard.js). As this is the case, the W3C has a project ' 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:
1
T1CSdk.T1CClient.initialize(config).then(res => {
2
client = res;
3
console.log("Client config: ", client.localConfig)
4
core = client.core();
5
}, err => {
6
if (err.code == 814501) {
7
console.log(err)
8
client = err.client
9
$('#consentModal').modal('show', {
10
keyboard: false
11
});
12
$('.consent-token').text(makeid(20));
13
} else if(err.code == 815500) {
14
// Agent not registered --> contact support
15
} else if (err.code == 112999) {
16
// Unavailable
17
} else {
18
console.error("T1C error:", err)
19
}
20
});
Copied!
The code below is an example of a javascript event handler on a consent button.
1
$('#consentModal .btn-primary').on('click', (ev) => {
2
const tokenNode = document.querySelector('.consent-token');
3
var range = document.createRange();
4
range.selectNode(tokenNode);
5
window.getSelection().addRange(range);
6
try {
7
document.execCommand('copy');
8
} catch (err) {
9
console.log('Oops, unable to copy');
10
}
11
window.getSelection().removeRange(range);
12
const clipboardData = tokenNode.textContent;
13
const validityInDays = 365
14
15
client.core().getImplicitConsent(clipboardData, validityInDays).then(consentRes => {
16
client = consentRes // replace the client and other set variables of the T1C
17
core = client.core();
18
core.version().then(versionResult => console.log("T1C running on core " + versionResult));
19
$('#consentModal').modal('hide');
20
}, err => {
21
console.error(err)
22
})
23
});
Copied!
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 "Invalid consent" or 814500 "No agents registered" which means that the request has been sent with the unique code but the Registry 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.
Last modified 14d ago