loginWithOneTimeKey method
Logs in a user with the given Voximplant username and one time key that was generated before.
username
- Full user name, including Voximplant user, application, and
account name in the format user@application.account.voximplant.com
.
hash
- Hash that was generated using following formula:
MD5(oneTimeKey+"|"+MD5(user+":voximplant.com:"+password)).
Throws VIException, if login process failed, otherwise returns VIAuthResult.
Errors:
- VIClientError.ERROR_ACCOUNT_FROZEN - If the account is frozen.
- VIClientError.ERROR_MAU_ACCESS_DENIED - Monthly Active Users (MAU) limit is reached. Payment is required.
- VIClientError.ERROR_INTERNAL - If an internal error occurred.
- VIClientError.ERROR_INVALID_PASSWORD - if the given password is invalid.
- 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.
Implementation
Future<VIAuthResult> loginWithOneTimeKey(String username, String hash) async {
_changeClientState(VIClientState.LoggingIn);
try {
Map<String, dynamic>? data = await _channel
.invokeMapMethod('Client.loginWithKey', <String, dynamic>{
'username': username,
'hash': hash,
});
if (data == null) {
_VILog._e('VIClient: login: data was null, skipping');
throw VIException(
VIClientError.ERROR_INTERNAL,
'VIClient:login: data was null',
);
}
_saveUsername(username);
return await _processLoginSuccess(data);
} on PlatformException catch (e) {
VIClientState state = await getClientState();
_changeClientState(state);
throw VIException(e.code, e.message);
} catch (e) {
VIClientState state = await getClientState();
_changeClientState(state);
rethrow;
}
}