initializeToken method

Future<void> initializeToken(
  1. String accessToken,
  2. RefreshAccessTokenType refreshAccessToken
)

Initializes the SDK with an access token that is provided by the customer backend communicating with Dolby.io servers. The token allows securing the customer key and secret. The following diagram presents the authentication flow:

Client          Customer Server       Dolby Server
|                    |                    |
|  Get Access Token  |  /oauth2/token (1) |
|------------------->|------------------->|
|    Access Token    |    Access Token    |
|<-------------------|<-------------------|
|  initializeToken(accessToken, callback) |
|---------------------------------------->|

The access token has a limited period of validity and needs to be refreshed for security reasons. In such case, the SDK calls the callback provided to initializeToken. The callback must return a promise containing the refreshed access token by calling the customer backend, as presented in the following diagram:

Client          Customer Server       Dolby Server
|      callback      |  /oauth2/token (2) |
|------------------->|------------------->|
|    Access Token    |    Access Token    |
|<-------------------|<-------------------|

Where (1) and (2) are the REST API endpoints that are available on Dolby.io servers.

The method contains two parameters:

  • accessToken: The access token provided by the customer's backend.
  • refreshAccessToken: A callback that is called when the access token needs to be refreshed.

Implementation

Future<void> initializeToken(
    String accessToken, RefreshAccessTokenType refreshAccessToken) async {
  _methodChannel.setMethodCallHandler((call) async {
    if (call.method == 'getRefreshToken') {
      return await refreshAccessToken.call();
    }
  });
  return await _methodChannel
      .invokeMethod<void>("initializeToken", {"accessToken": accessToken});
}