tokenRefresh method
Performs refresh of access token for the given Voximplant username using refresh token.
username
- Full user name, including Voximplant user, application, and
account name in the format user@application.account.voximplant.com
.
token
- Refresh token can be obtained from VIAuthResult.loginTokens after
previous successful login.
Throws VIException, if refresh process failed, otherwise returns new tokens.
Errors:
- VIClientError.ERROR_ACCOUNT_FROZEN - If the account is frozen.
- VIClientError.ERROR_INTERNAL - If an internal error occurred.
- VIClientError.ERROR_INVALID_STATE - If the client is not connected, already logged in, or currently logging in.
- VIClientError.ERROR_INVALID_USERNAME - If the given username is invalid.
- VIClientError.ERROR_NETWORK_ISSUES - If the connection to the Voximplant Cloud is closed while the client is logging in.
- VIClientError.ERROR_TIMEOUT - If timeout occurred.
- VIClientError.ERROR_TOKEN_EXPIRED - If the refresh token is expired.
Implementation
Future<VILoginTokens> tokenRefresh(String username, String token) async {
try {
Map<String, dynamic>? data = await _channel
.invokeMapMethod<String, dynamic>(
'Client.tokenRefresh', <String, String>{
'username': username,
'refreshToken': token,
});
if (data == null) {
_VILog._e('VIClient: tokenRefresh: data was null, skipping');
throw VIException(
VIClientError.ERROR_INTERNAL,
'VIClient:tokenRefresh: data was null',
);
}
VILoginTokens loginTokens = VILoginTokens(
accessExpire: data['accessExpire'],
accessToken: data['accessToken'],
refreshExpire: data['refreshExpire'],
refreshToken: data['refreshToken'],
);
return loginTokens;
} on PlatformException catch (e) {
throw VIException(e.code, e.message);
}
}