From sgcWebSockets 4.4.6, the Google Cloud PubSub client components adds a new authentication protocol. Till now, only OAuth2 protocol was supported, now Authenticate using JWT is supported too. This means that you can run a service or an automated application with the need to authenticate using a Web-Browser like with OAuth2.
There is a new property called Authorization, where you can set which is the authorization scheme
*JWT support requires sgcWebSockets Enterprise Edition or latest Indy version.
First, you must create a new Service Account from your Google Cloud Console. You can check the following article which shows how create a new service account.
Once created, you can use the method LoadSettingsFromFile to load the JSON configuration file in the sgcWebSockets PubSub client.
oPubSub := TsgcHTTPGoogleCloud_PubSub_Client.Create(nil); oPubSub.GoogleCloudOptions.Authorization := gcaJWT; // you can assign manually oPubSub.GoogleCloudOptions.JWT.ClientEmail := '...google email...'; oPubSub.GoogleCloudOptions.JWT.PrivateKeyId := '...private key id...'; oPubSub.GoogleCloudOptions.JWT.PrivateKey.Lines.Text := '...private key certificate...'; // or you can load from JSON file oPubSub.LoadSettingsFromFile('... path to json file ...'); // test components calling ListTopics ShowMessage(oPubSub.ListTopics('...project id...'));
You can download a sample project which shows the main features of PubSub sample downloading from the following URL
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.