register method

  1. @override
Future<RegisterResponseType> register(
  1. RegisterRequestType request
)
override

Creates a new passkey and stores it on the device. Returns RegisterResponseType which must be sent to the relying party server.

Implementation

@override
Future<RegisterResponseType> register(RegisterRequestType request) async {
  if (debugMode) {
    await _doctor?.check(request.relyingParty.id);
  }

  try {
    await _platform.cancelCurrentAuthenticatorOperation();

    _isValidChallenge(request.challenge);

    _isValidUserID(request.user.id);

    for (final credential in request.excludeCredentials) {
      _isValidCredentialID(credential.id);
    }

    final r = await _platform.register(request);

    return r;
  } on PlatformException catch (e) {
    if (debugMode) {
      _doctor?.recordException(e);
    }

    switch (e.code) {
      case 'cancelled':
        throw PasskeyAuthCancelledException();
      case 'exclude-credentials-match':
        throw ExcludeCredentialsCanNotBeRegisteredException();
      case 'android-missing-google-sign-in':
        throw MissingGoogleSignInException();
      case 'android-sync-account-not-available':
        throw SyncAccountNotAvailableException();
      case 'domain-not-associated':
        throw DomainNotAssociatedException(e.message);
      case 'deviceNotSupported':
        throw DeviceNotSupportedException();
      case 'android-passkey-unsupported':
        throw PasskeyUnsupportedException(e.message);
      case 'android-no-create-option':
        throw NoCreateOptionException(e.message);
      case 'android-timeout':
        throw TimeoutException(e.message);
      case 'ios-security-key-timeout':
        throw TimeoutException(e.message);
      default:
        if (e.code.startsWith('android-unhandled')) {
          throw UnhandledAuthenticatorException(e.code, e.message, e.details);
        } else if (e.code.startsWith('ios-unhandled')) {
          throw UnhandledAuthenticatorException(e.code, e.message, e.details);
        } else {
          rethrow;
        }
    }
  }
}