create method

  1. @override
Future<Authenticator> create(
  1. RealmSettings realm,
  2. Map<String, Object?> options
)
override

Builds an authenticator instance for the given realm and options.

Implementation

@override
Future<Authenticator> create(
  RealmSettings realm,
  Map<String, Object?> options,
) async {
  final config = RemoteAuthenticatorConfig.parse(options, realm);
  final delegates = <RemoteAuthenticatorDelegate>[];
  final delegateIds = <String>[];
  if (config.rpcDelegate != null) {
    final rpcConfig = config.rpcDelegate!;
    delegates.add(RemoteWampDelegateRegistry.forConfig(rpcConfig));
    delegateIds.add(rpcConfig.cacheKey());
  } else {
    for (final id in config.delegateIds) {
      final delegate = RemoteAuthenticatorRegistry.delegateFor(id);
      if (delegate == null) {
        throw StateError(
          'Remote authenticator delegate "$id" not registered. '
          'Call RemoteAuthenticatorRegistry.register(..., id: "$id") first.',
        );
      }
      delegates.add(delegate);
      delegateIds.add(id);
    }
  }
  return RemoteAuthenticator(config, delegates, delegateIds: delegateIds);
}