completeAuthentication method
Future<AuthenticationResult>
completeAuthentication(
- AuthenticationProcess process,
- String validationCode,
- Tuple2<
String, String> userKeyPair, - Future<
Tuple3< tokenAndKeyPairProvider(),String, String, String> ?>
override
Completes the authentication process of a user, by verifying the provided validation code and :
- In the case of a sign-up, create the user data;
- In the case of a login, re-generate keys if needed (new keys different from previous ones);
Parameters
process
The AuthenticationProcess previously provided in the startAuthentication servicevalidationCode
The validation code the user received by email/mobile phoneuserKeyPair
The key pairprivate, public
that will be used by the user to encrypt/decrypt data;tokenAndKeyPairProvider
A custom function to generate an authentication token and a key pair for user
Returns
- The result of the authentication and the related MedTechApi object corresponding to the newly authenticated user.
Implementation
@override
Future<AuthenticationResult> completeAuthentication(
AuthenticationProcess process,
String validationCode,
Tuple2<String, String> userKeyPair,
Future<Tuple3<String, String, String>?> Function(String, String) tokenAndKeyPairProvider
) async {
final Response res = await _validateAuthenticationProcess(process.requestId, validationCode, process.bypassTokenCheck);
if (res.statusCode < 400) {
final Tuple2<MedTechApi, ApiInitialisationResult> initInfo =
await retry(() async => await _initApiAndUserAuthenticationToken(process, validationCode, tokenAndKeyPairProvider), trials: 5, delay: 1000);
MedTechApi authenticatedApi =
await _initUserCrypto(initInfo.item1, initInfo.item2.token, initInfo.item2.user, initInfo.item2.keyPair ?? userKeyPair);
return AuthenticationResult(
authenticatedApi, initInfo.item2.keyPair ?? userKeyPair, initInfo.item2.token, initInfo.item2.user.groupId!, initInfo.item2.user.id);
}
throw FormatException("iCure could not complete authentication process with requestId ${process.requestId}. Try again later.");
}