useCustomAppCheckProvider function

void useCustomAppCheckProvider(
  1. Future<AppCheckToken> supply()
)

Installs a provider that asks supply whenever the SDK needs a token.

supply does the attesting — reads a TPM, calls a vendor service, unseals a provisioning record — and returns the token with its expiry. Throwing fails that one request; the SDK will ask again.

The SDK waits for an answer and nothing here times it out, so supply must return or throw. It runs on the Dart isolate that installed the provider, not on the SDK thread that asked.

Implementation

void useCustomAppCheckProvider(Future<AppCheckToken> Function() supply) {
  if (!hasFirebase) throw StateError('this build has no Firebase SDK');
  _providerPort?.close();
  final receive = RawReceivePort();
  receive.handler = (Object? message) {
    // The request carries nothing but its id, in the header's seq field.
    final bytes = message! as Uint8List;
    final id = ByteData.sublistView(bytes).getInt64(8, Endian.host);
    unawaited(_answer(id, supply));
  };
  _providerPort = receive;
  final rc = fdbAcUseCustomProvider(receive.sendPort.nativePort);
  if (rc != 0) {
    receive.close();
    _providerPort = null;
    throw StateError('the custom provider could not be installed ($rc)');
  }
}