Authenticated client
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.

Introduction

The Trust1Connector API requires a valid JWT token to be provided in the Authorization header. This JWT token can be retrieved by asking the Distribution Service to generate a token for a specific API-key. It is important that this API-key is not exposed in the front-end application as this is a security violation.
When you've received a valid JWT token from the DS you can provide this into the configuration object when initialising the Trust1Connector JS client.
1
// Config object definition
2
export class T1CConfigOptions {
3
constructor(
4
public t1cApiUrl?: string,
5
public t1cApiPort?: string,
6
public t1cProxyUrl?: string,
7
public t1cProxyPort?: string,
8
public jwt?: string
9
) {}
10
}
11
12
13
14
// example
15
const configoptions = new T1CSdk.T1CConfigOptions(
16
environment.t1cApiUrl,
17
environment.t1cApiPort,
18
environment.t1cProxyUrl,
19
environment.t1cProxyPort,
20
environment.jwt
21
);
22
config = new T1CSdk.T1CConfig(configoptions);
Copied!
When using the Trust1Connector Javascript SDK the Authorization header is automatically populated with the JWT provided while initialising.
When the Token has expired there is a function which you can call to provide a new token and which will in turn return an updated client to be used.

Retrieving a JWT token

Retrieving a valid JWT token happens via the DS. When passing a valid API-key to header of the endpoint {{ds-url}}/v3/tokens/application (GET) you wil in turn receive a valid JWT token.
1
curl --location --request GET 'https://acc-ds.t1t.io/v3_5/tokens/application' \
2
--header 'apikey: your-api-key'
Copied!
Example response
1
{
2
"success": true,
3
"data": "eyJraWQiOiJ0MWNkcyIsImFsZyI6IlJTMjU2In0.eyJpc3MiOiJ0MWNkcy1hcHAiLCJzdWIiOiJkZXZlbG9wbWVudCIsImV4cCI6MTU5OTA1MTExMywiaWF0IjoxNTk5MDQ5OTEzLCJuYmYiOjE1OTkwNDk5MDh9.LE_AdYv9PWxqSRm6-lkV_3TxInCqbf_hTwHFKCFfYwkuzex6AMkeW6FaVCOxu-EBU158S2g70i4VBpeT2TAr0IoOyjK-nalvVG5aB9MwidZMtiPlidcUfsDhsyhbhwqlhI2dzB5J5KsBmvZwpoG-Pg2koUSidruixg3SxRrCMotBRlRNKItnYgfs6_wvd_OOLXs2OlufYOD876MWcJymBK48wf9ESQ50clR3zwPAQsNnXFq2Augk0gOlCgWO1--WgaFeMnBF28b7genZXIkwZCfT82nRYtiOs0zLK2WtyireTHDgjIZif4nX8pggE7t_63Hbv8wCvv8_Mg2PfdhCMQ"
4
}
Copied!

Refresh JWT token

Refreshing the JWT token can only be done after a first successfull initialisation of the Trust1Connector. This means the Trust1Connector has to be initialised with a valid configuration the first time. When the token expires after first successfull initialisation you can use the refreshJWT function described below
A JWT token is only valid for a certain period. After this period the API will return an error. At this point you need to request a new JWT token to be able to communicate with the API.
In the T1C JS SDK there is a function which you can use to re-initalise the client with a new valid JWT token. This should be done when you receive a 104026 error-code which means you do not have a valid JWT
The updateJWT function can be found in the Core service. After initialising you can retrieve the core as follows:
1
const configoptions = new T1CSdk.T1CConfigOptions(
2
environment.t1cApiUrl,
3
environment.t1cApiPort,
4
environment.t1cProxyUrl,
5
environment.t1cProxyPort,
6
environment.jwt
7
);
8
config = new T1CSdk.T1CConfig(configoptions);
9
10
T1CSdk.T1CClient.initialize(config).then(res => {
11
client = res;
12
console.log("Client config: ", client.localConfig)
13
core = client.core();
14
}, err => {});
Copied!
The function's interface is as follows;
1
updateJWT(jwt: string, callback?: (error: T1CLibException, data?: T1CClient) => void): Promise<T1CClient>
Copied!
This function returns an updated client which you can continue to use for your desired use-cases.
1
core.updateJWT("jwt").then(client => {}, error => {});
Copied!

Distribution services

Environment
DS url
Acceptance
https://acc-ds.t1t.io
Production
https://ds.t1t.io
Last modified 19d ago