Installation and usage of the platform
Using the JS SDK in a node with oAuth authorization¶
If the node uses the oAuth authorization, it is necessary to initialize the Waves API with the authorization headers for the call.
To automatically update tokens when developing applications with the JS SDK, we recommend using the external module api-token-refresher. However, you can use your solution instead.
To work with api-token-refresher, install dependencies using npm:
npm i @wavesenterprise/api-token-refresher@3.1.0 --save, axios --save-dev, cross-fetch --save-dev, @wavesenterprise/js-sdk@3.1.1 --save
Initialize api-token-refresher as follows:
import { init: initRefresher } from '@wavesenterprise/api-token-refresher/dist/fetch'
const { fetch } = initRefresher({
authorization: {
access_token,
refresh_token
}
});
const Waves = WeSdk.create({
initialConfiguration: config,
fetchInstance: fetch
});
The access_token
and refresh_token
parameters are given in the authorization response to the loginSecure
request, which is available in the browser.
The following listing contains the initialization of the library followed by the first block check: