Hi all,

i'm trying to setup a backend system able to send push notification to mobile app (not developed in creatio) through FCM rest API.

The first hurdle is obtaining a valid token to authenticate to notification api exposed by firebase. In order to obtain this token i do have to call another rest api passing a jwt token generated by me and signed by a private key downloaded from fcm.

I've got a code (pasted below) that manages to generate this encrypted token and it's working in visual studio. But if i try to use it in a script task i got the exception 

'RSA' does not contain a definition for 'ImportPkcs8PrivateKey' and no accessible extension method 'ImportPkcs8PrivateKey' accepting a first argument of type 'RSA' could be found (are you missing a using directive or an assembly reference?)

As far as i know this exception is thrown if .net core being used is version 5 or below. But i'm on a demo instance with creation 8.2.0.4183 which should be already using net core 6 right?

Do you have any suggestion? (the flow is already configured to import System.Security.Cryptography)

 

 

--code--

   var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
var header = new Dictionary
       {
           { "alg", "RS256" },
           { "typ", "JWT" }
       };
string headerJson = JsonConvert.SerializeObject(header);
string encodedHeader = Convert.ToBase64String(Encoding.UTF8.GetBytes(headerJson)).TrimEnd('=').Replace('+', '-').Replace('/', '_');

var payload = new Dictionary
       {
           { "iss", CLIENT_EMAIL },
           { "scope", SCOPE },
           { "aud", TOKEN_URI },
           { "iat", now },
           { "exp", now + 3600 }
       };
string payloadJson = JsonConvert.SerializeObject(payload);
string encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(payloadJson)).TrimEnd('=').Replace('+', '-').Replace('/', '_');
string unsignedJwt = $"{encodedHeader}.{encodedPayload}";
byte[] dataBytes = Encoding.UTF8.GetBytes(unsignedJwt);

// Decode PEM -> PKCS#8 bytes
string cleanKey = PRIVATE_KEY
   .Replace("-----BEGIN PRIVATE KEY-----", "")
   .Replace("-----END PRIVATE KEY-----", "")
   .Replace("\\n", "\n")  // ← decodifica reale da stringa JSON
   .Trim();


byte[] privateKeyBytes = Convert.FromBase64String(cleanKey);

// Firma con RSA-SHA256
byte[] signature;
using (var rsa = RSA.Create())
{
   rsa.ImportPkcs8PrivateKey(privateKeyBytes, out _);
   signature = rsa.SignData(dataBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
}
string encodedSignature = Convert.ToBase64String(signature)
   .TrimEnd('=').Replace('+', '-').Replace('/', '_');

string jwt = $"{unsignedJwt}.{encodedSignature}";


return true;

Like 0

Like

0 comments
Show all comments

I've used following article to create Business process to send push notifications:
https://academy.creatio.com/docs/8.x/no-code-customization/bpm-tools/bpm-process-examples/set-up-push-notifications-for-mobile-users

Goal of Business process is to send Push notifications to mobile app about calendar Activities for Owners:

 

  1. Run every 15 minutes (don't know if we can use some Signals based on Activitiy Start time, so decided to run every 15 minutes and check for Activities within next 15 minutes, which is also fine for us)
  2. So next setting Start and End dates within next 15 minutes interval
  3. Then Read Activitiy records (collection)

     

  4. and then Send push notification
     

  5. Issue is than I cannot pass Recepient User, as Owner of activity is Contact, but User is expected

 

So looking for your help:
1) How to pass respective User for collection of records?

Owner is not available for selection

2) Is it possible to send to multiple users (dynamically defined Owner from Read Collection and static Manager defined manually in Business Process)?

3) How to pass Lead_Name (text) or Lead_Status (lookup) to "Push notification text", instead of Lead_ID? ( I know how to handle this with Read single first record, to Read Lead Data and filter by Lead ID, but don't know how to handle such cases for Collection of records)

 

Huge thanks,

Leo

Like 1

Like

4 comments
Best reply

As far as getting the user for each contact, you could do this by creating another process inbetween the two. Create a subprocess and add parameters for the columns you want to include in the push notification (subject, lead, start, and contact). In this subprocess, you would read System Administration Unit (user) for the contact passed, then pass the values including the user to the Send Push Notification subprocess. In the main process, you'd change things so after reading the activities for the time period as a collection, you'd pass each to this new subprocess, and it would read the user for the contact and call the subprocess to send the push notification.

Ryan

As far as getting the user for each contact, you could do this by creating another process inbetween the two. Create a subprocess and add parameters for the columns you want to include in the push notification (subject, lead, start, and contact). In this subprocess, you would read System Administration Unit (user) for the contact passed, then pass the values including the user to the Send Push Notification subprocess. In the main process, you'd change things so after reading the activities for the time period as a collection, you'd pass each to this new subprocess, and it would read the user for the contact and call the subprocess to send the push notification.

Ryan

it works, huge thanks!

Is it possible to pass 2 or more users to singe Push notification subprocess?

Or should I use similar approach and create a fork (AND) in business process to call Push notification subprocess in case I need to sent the same Push notification to 2 or more persons?

Leonid,

You'd have to call that subprocess twice, once for each user.

thanks!

Show all comments

Hi Community,

I used this below link to setup push notification in mobile

https://academy.bpmonline.com/documents/technic-bpms/7-11/how-set-push-notifications-mobile-application-users

Licensed users using mobile are getting push notifications but Portal users using mobile application is not getting push notification. Is there any other setup needs to do for portal users?

 

Like 0

Like

1 comments

Dear Fulgen,

The most possible cause is access rights to the object and settings for portal users. Please check the access for the following objects:

PushNotificationToken

PushNotificationService 

Regards,

Anastasia

Show all comments