authenticate method
Returns false
if fails in authenticating atsign
with cramSecret
/privateKey
.
Throws Excpetion if atsign is null.
Implementation
Future authenticate(String? atsign,
{String? cramSecret,
String? jsonData,
String? decryptKey,
OnboardingStatus? status}) async {
_isPkam = false;
atsign = formatAtSign(atsign);
if (atsign == null) {
throw '@sign cannot be null';
}
Completer c = Completer();
try {
serverStatus = await _checkAtSignServerStatus(atsign);
if (serverStatus != ServerStatus.teapot &&
serverStatus != ServerStatus.activated) {
c.complete(ResponseStatus.SERVER_NOT_REACHED);
if (cramSecret == null) {
_isPkam = true;
}
return c.future;
}
var atClientService = _getClientServiceForAtsign(atsign)!;
_atClientPreference..cramSecret = cramSecret;
if (cramSecret != null) {
_atClientPreference..privateKey = null;
}
await atClientService
.authenticate(atsign, _atClientPreference,
jsonData: jsonData, decryptKey: decryptKey, status: status)
.then((value) async {
_atsign = atsign;
atClientServiceMap.putIfAbsent(_atsign, () => atClientService);
c.complete(ResponseStatus.AUTH_SUCCESS);
await _sync();
});
} catch (e) {
_logger.severe("error in authenticating => ${e.toString()}");
if (e == ResponseStatus.TIME_OUT) {
c.completeError(e);
} else {
c.completeError(
e.runtimeType == OnboardingStatus ? e : ResponseStatus.AUTH_FAILED);
}
}
return c.future;
}