generateAuthEvent function

Event? generateAuthEvent(
  1. InvocationContext invocationContext,
  2. Event functionResponseEvent
)

Builds an auth request event from functionResponseEvent, when needed.

Implementation

Event? generateAuthEvent(
  InvocationContext invocationContext,
  Event functionResponseEvent,
) {
  if (functionResponseEvent.actions.requestedAuthConfigs.isEmpty) {
    return null;
  }

  final Map<String, AuthConfig> authRequests = <String, AuthConfig>{};
  functionResponseEvent.actions.requestedAuthConfigs.forEach((
    String functionCallId,
    Object authConfig,
  ) {
    if (authConfig is AuthConfig) {
      authRequests[functionCallId] = authConfig;
    }
  });
  if (authRequests.isEmpty) {
    return null;
  }

  return buildAuthRequestEvent(
    invocationContext,
    authRequests,
    role: functionResponseEvent.content?.role,
  );
}