useCustomAppCheckProviderForApps function
useCustomAppCheckProvider, with supply told which app is asking: null
for the default app, else the name initNamedApp was given.
Which provider is installed is process-wide, as it is in the SDK: this replaces a debug provider on every app, not on one.
Implementation
void useCustomAppCheckProviderForApps(
Future<AppCheckToken> Function(String? app) supply,
) {
if (!hasFirebase) throw StateError('this build has no Firebase SDK');
_providerPort?.close();
final receive = RawReceivePort();
receive.handler = (Object? message) {
// The id is in the header's seq field and the app's name is the payload,
// empty for the default app.
final bytes = message! as Uint8List;
final id = ByteData.sublistView(bytes).getInt64(8, Endian.host);
final name = utf8.decode(Uint8List.sublistView(bytes, snapshotHeaderBytes));
unawaited(_answer(id, () => supply(name.isEmpty ? null : name)));
};
_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)');
}
}