serverNotificationHandler static method
Handler for server-to-server notifications coming from Apple.
To be mounted as a POST
handler under the URL configured in Apple's
developer portal, for example:
Router<Handler>()..post(
'/hooks/apple-notification',
handleAppleNotification, // your function to handle the notification
);
If the notification is of type AppleServerNotificationConsentRevoked
or
AppleServerNotificationAccountDelete
, all sessions based on the Apple
authentication should be removed.
Implementation
static Handler serverNotificationHandler(
final FutureOr<void> Function(AppleServerNotification notification) handler,
) {
return (final RequestContext ctx) async {
final body = await utf8.decodeStream(ctx.request.body.read());
final payload = (jsonDecode(body) as Map)['payload'] as String;
final notification = await _siwa.decodeAppleServerNotification(
payload,
);
await handler(notification);
return (ctx as RespondableContext).respond(Response.ok());
};
}