2. Retrieve a PluginApi instance
Before you can use the connective-wrapper
, you must first retrieve a PluginApi
instance from the PluginApiFactory
.
If the platform you're using is not supported - because of an outdated Operating System and browser combination for instance - the PluginApiFactory
will be unable to create an instance and will throw a PlatformNotSupportedException
.
To retrieve a PluginApi instance, follow the example below:
'use strict';
import { PluginApi, PluginApiFactory, Exceptions } from 'connective-wrapper';
const pluginApiFactory = PluginApiFactory.getInstance();
let pluginApi: PluginApi = null;
try {
// note that we're also passing along a "gclOptions" object in our extraOptions dict
// the gclOptions object is used by the t1t implementation module which uses t1c-lib-js (https://github.com/Trust1Team/t1c-lib-js) library for the native layer
// it should match the GCLConfigOptions interface as defined in that library.
pluginApi = pluginApiFactory.createPluginApi({
activationToken: '<activation token goes here>',
extraOptions: {
gclOptions: {
gwOrProxyUrl: '<distribution service url goes here>',
osPinDialog: true
}
}
});
} catch(e: Error) {
if (e instanceof Exceptions.PlatformNotSupportedException) {
// current platform is not supported...
}
}
Note that an activationToken must be entered in the indicated location. To obtain the activationToken, you need to do a REST call to the Distribution Service endpoint. This GET request must include a header containing "apiKey" as name, and the actual apiKey as value. The value of the apiKey should have been communicated to you during onboarding.
The apiKey will be exchanged for a valid JWT, which is the activationToken that must be entered. This token, which has a limited lifetime, will be forwarded to the front-end, which in turn will call the Distribution Service to obtain the URL to install the plugin for instance, or to check which card types or devices you are allowed to use.
Important: the apiKey must be kept secret, and must never be exposed to the front-end!
Also note that in the example above, we make use of the extraOptions
object which includes a gclOptions
entry. This optional entry is specifically used by the SignID module.