Initialize Trust1Connector

Introduction

For initialisation of the T1C you need to prepare your application first by adding the SDK JS files to your project and importing them in such a way that you can call for the Javascript functions when you need them. When you've succesfully downloaded and installed the Trust1Connector you can initialize and use the Trust1Connector

Creating the configuration object

We will prepare the SDK's configuration Object, this object is used to pass information about which default port the Trust1Connector is running on, JWT key, API url, ... which is needed to properly contact and use the Trust1Connector.
When the Trust1Connector is configured with a Distribution Service in mind you will need to provide a valid JWT token in the configuration object. You can retrieve such token via the Distribution Service based on the API key you received.
Retrieving JWT tokens should be handled in your own backend to maximize security
Now we can create a complete Configuration Options object to be passed to the Trust1Connector.

T1CConfigOptions

The T1C config options is a class that can be used to create a valid configuration object to initialize the Trust1Connector. Below you can find a class definition.
1
class T1CConfigOptions {
2
constructor(
3
public t1cApiUrl?: string,
4
public t1cApiPort?: string,
5
public t1cProxyUrl?: string, // deprecated
6
public t1cProxyPort?: string, // deprecated
7
public jwt?: string,
8
public applicationDomain?: string, // "rmc.t1t.be"
9
) {}
10
}
Copied!

Parameters

t1cApiUrl: string Optional The URL that connects to the local Trust1Connector instances. This can be either localhost or a domain that directs towards localhost. By default this will be https://t1c.t1t.io
t1cApiPort: string Optional The port defined to be used for the Trust1Connector. By default this is 51983
t1cProxyUrl: string Optional - Deprecated The URL that connects to the local Trust1Connector Proxy instances. This can be either localhost or a domain that directs towards localhost. By default this will be https://t1c.t1t.io
t1cProxyPort: string Optional - Deprecated The port defined to be used for the Trust1Connector Proxy. By default this is 51983
jwt: string Optional The JWT token that is used to authenticate towards the Trust1Connector. This should be retrieved from the DS and is only needed when the Trust1Connector is configured to work with a DS and requires JWT validation
applicationDomain: string Optional The domain of the application that is using the Trust1Connector. This is used to make sure the consent is only available for a specific web-application. This prevents various clients to interfere with eachother.
1
// ...
2
3
let environment = {
4
t1cApiUrl: 'https://t1c.t1t.io',
5
t1cApiPort: '51983',
6
t1cProxyUrl: 'https://t1c.t1t.io',
7
t1cProxyPort: '51983',
8
jwt: 'eyJraWQiOiJ0MWNkcyIsImFsZyI6IlJTMjU2In0..._Mg2PfdhCMQ',
9
applicationDomain: 'test-app'
10
};
11
12
const configoptions = new T1CSdk.T1CConfigOptions(
13
environment.t1cApiUrl,
14
environment.t1cApiPort,
15
environment.t1cProxyUrl,
16
environment.t1cProxyPort,
17
environment.jwt,
18
environment.applicationDomain
19
);
20
config = new T1CSdk.T1CConfig(configoptions);
21
22
// ...
Copied!
When a remote DS is used you can set the following field with the correct DS url, this will in turn use the DS's capabilities of acting as a Trust1Connector proxy for enchanced security.
1
// When remote DS is used set the following parameter
2
config.dsUrl = "https://acc-ds.t1t.io";
Copied!
Now we can continue to use the config variable to initialize and retrieve a T1CClient

Authenticated client

If you need to set up the Trust1Connector with a valid JWT token you can follow the documentation on the Authenticated Client page to retrieve a valid token from the DS.
When you have a valid token you can provide this in the Configuration. This will make sure the Trust1Connector is usable until the token becomes unvalid. At which point you can refresh your token to continue to use the Trust1Connector. More information on how to retrieve,use and refresh a token can be found on the Authenticated Client page.

Initializing the Trust1Connector SDK

Initialization of the Trust1Connector in many cases requires a user consent, the exception being when no registry is configured (either local or central). More information can be found here. The registry allowed us to create a Trust1Connector that works in any environment, without the need for Administrative rights from the users, wether it be Standalone, Multi session, RDP, Citrix, ...
To Initialize the Trust1Connector a Consent is required(when a central or local registry is present). When no consent can be found the error codes 814500 or 814501 will be thrown. This means that either the previous consent is not valid anymore or no consent was given yet. More information regarding the consent can be found on the Consent page which explains it in more detail
1
// ...
2
3
T1CSdk.T1CClient.initialize(config).then(res => {
4
client = res;
5
console.log("Client config: ", client.localConfig);
6
core = client.core();
7
core.version().then(versionResult => console.log("T1C running on core "+ versionResult));
8
}, err => {
9
if (err.code == 814500 || err.code == 814501) {
10
client = err.client;
11
// (new) Consent is required
12
}
13
else if(err.code == 112999) {
14
// Could not connect with the Trust1Connector
15
} else {
16
// an uncatched error occured
17
console.error("T1C error:", err)
18
}
19
});
20
21
// ...
Copied!
When either no consent is present or its invalid you will receive a invalid client object (line 8 in example above) that can be used to trigger the getImplicitConsent function in the Core serivce.
The Consent requires a user action to copy some data to its clipboard. This data is used by the T1C registry to make sure you're targetting the correct instance of the Trust1Connector. More information about this can be found here.
The signature of the getImplicitConsent function is as follows;
1
public getImplicitConsent(codeWord: string, durationInDays?: number,
2
callback?: (error?: T1CLibException, data?: T1CClient) => void
3
): Promise<T1CClient>
Copied!
This function expects:
codeword: string The string value that is saved to the user's clipboard needs to be sent to the Consent function.
durationInDays: number Optional Amount of days that the consent is valid.
callback: (error?: T1CLibException, data?: T1CClient) Optional Callback when you're not using ES
Below is a small javascript example of how you can trigger the getImplicitConsent function
1
client.core().getImplicitConsent(document.querySelector(".clipboard-data").innerHTML).then(res => {
2
console.log("Consent Executed")
3
client = res;
4
// Use the client for your use-cases
5
}, err => {
6
// Failed, use the error client to retry the consent
7
this.client = err.client;
8
console.error(err.description ? err.description : err)
9
})
Copied!
After this you will have a client that can be used to execute the rest of the functionality that the Trust1Connector has to offer.

Full example

1
// Global client to be used over the entire application
2
const client = null
3
4
// Prepare the configuration
5
let environment = {
6
t1cApiUrl: 'https://t1c.t1t.io',
7
t1cApiPort: '51983',
8
t1cProxyUrl: 'https://t1c.t1t.io',
9
t1cProxyPort: '51983',
10
jwt: 'eyJraWQiOiJ0MWNkcyIsImFsZyI6IlJTMjU2In0..._Mg2PfdhCMQ',
11
applicationDomain: 'test-app'
12
};
13
14
const configoptions = new T1CSdk.T1CConfigOptions(
15
environment.t1cApiUrl,
16
environment.t1cApiPort,
17
environment.t1cProxyUrl,
18
environment.t1cProxyPort,
19
environment.jwt,
20
environment.applicationDomain
21
);
22
config = new T1CSdk.T1CConfig(configoptions);
23
24
// Initialize the Trust1Connector with the previously created configuration object
25
T1CSdk.T1CClient.initialize(config).then(res => {
26
client = res;
27
console.log("Client config: ", client.localConfig);
28
core = client.core();
29
core.version().then(versionResult => console.log("T1C running on core "+ versionResult));
30
}, err => {
31
if (err.code == 814500 || err.code == 814501) {
32
// (new) Consent is required
33
}
34
else if(err.code == 112999) {
35
// Could not connect with the Trust1Connector
36
} else {
37
// an uncatched error occured
38
console.error("T1C error:", err)
39
}
40
});
41
42
43
44
// when the user has clicked on the clipboard/consent button we execute the getImplicitConsent function
45
document.querySelector(".clipboard").addEventListener("click", (ev) => {
46
if (client != null) {
47
client.core().getImplicitConsent(document.querySelector(".clipboard-data").innerHTML).then(res => {
48
console.log("Consent Executed")
49
client = res;
50
// Use the client for your use-cases
51
}, err => {
52
this.client = err.client;
53
console.error(err.description ? err.description : err)
54
})
55
}
56
57
})
Copied!

Clipboard

To provide a consent, we suggest you use the clipboard functionality available in browsers. The most supported way is via document.exeCommand and below you can find an example of this.
There is also a clipboard API but this is not fully supported yet
The code below is an example of how you can integrate a copy command in the webbrowser
1
const tokenNode = document.querySelector('.consent-token');
2
var range = document.createRange();
3
range.selectNode(tokenNode);
4
window.getSelection().addRange(range);
5
try {
6
// Now that we've selected the anchor text, execute the copy command
7
document.execCommand('copy');
8
} catch(err) {
9
console.log('Oops, unable to copy');
10
}
11
12
// Remove the selections - NOTE: Should use
13
// removeRange(range) when it is supported
14
window.getSelection().removeRange(range);
15
const clipboardData = tokenNode.textContent;
Copied!
get
https://ds.t1t.io
/v3/tokens/application
Retrieve JWT token
Last modified 24d ago