By Admin on Thursday, 03 October 2024
Category: All

Google FCM HTTP v1 Delphi

​From sgcWebSockets 2024.9.0 there is a new client component to Send Notifications using Google Firebase Cloud Messaging and the latest API HTTP v1.

Apps using the deprecated FCM legacy APIs for HTTP and XMPP should migrate to the HTTP v1 API at the earliest opportunity. Sending messages (including upstream messages) with those APIs was deprecated on June 20, 2023, and shutdown begins on July 22, 2024.

In addition to ongoing support and new features, the HTTP v1 API has these advantages over the legacy APIs:

- Better security via access tokens The HTTP v1 API uses short-lived access tokens according to the OAuth2 security model. In the event that an access token becomes public, it can only be maliciously used for an hour or so before it expires. Refresh tokens are not transmitted as often as the security keys used in the legacy API, so they are much less likely to be captured.

- More efficient customization of messages across platforms For the message body, the HTTP v1 API has common keys that go to all targeted instances, plus platform-specific keys that let you customize the message across platforms. This allows you to create "overrides" that send slightly different payloads to different client platforms in a single message.

- More extendable and future-proof for new client platform versions The HTTP v1 API fully supports messaging options available on Apple platforms, Android and Web. Since each platform has its own defined block in the JSON payload, FCM can extend the API to new versions and new platforms as needed.

Google FCM Delphi Client

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4096 bytes to a client app.

The component supports the HTTP v1 API.

Authorization

Google FCM component client can login to Google Servers using the following methods:

OAuth2

The login is done using a webbrowser where the user logins with his own user and authorizes the FCM requests.


Service Accounts

The login is done signing the requests using a private key provided by google, these method is recommended for automated services or applications without user interaction.

When a new service account is created, you can download a JSON file with all configurations. This file can be processed by the FCM component, just call the method LoadSettingsFromFile and pass the JSON filename as argument. 

Sample

Find below a simple example to send notifications using FCM and JWT as authentication method.

Compiled Demo

Related Posts