Page 1 of 1

"Invalid credentials" when using my own Google cloud function for ES

Posted: Sat Sep 04, 2021 1:02 pm
by Vietace
Hi asker and everyone,

My system is Zoneminder 1.32.3, ES version 6.1.27, zmNinja 1.6.009. Everything works perfectly with the current FCMV1 link 'https://us-central1-ninja-1105.cloudfun ... /send_push'. 

This is the debug log I got when using the current FCMV1 link:
FORK:Floor1 (4), eid:298774 fcmv1: Final JSON using FCMV1 being sent is: {"token":"fBJFbUdSToaEUVlRUvddlw:APA91bEWItPBz67gDP1Ra7pb2578zGt5tvVf1KwotcZ0jEmCzH4f_flq3_HUVCnvQ3S0LqfxYakxRIsVzOjX4JgsyvdM6DCQwO8E6mao1BbvDCkl9Jh_eEA6sVDM3ZXPBrREoI1fvMRF","android":{"priority":"high","channel":"zmninja","icon":"ic_stat_notification"},"title":"Floor1 Alarm (298774)","data":{"notification_foreground":"true","eid":"298774","mid":"4"},"image_url":"https://localhost/zm/index.php?view=ima ... ssword=xxx} to token: ...1fvMRF
DBG-1:2021-08-29,19:11:14 |----> FORK:Floor1 (4), eid:298774 fcmv1: FCM push message returned a 200 with body {"Success":"projects/ninja-1105/messages/0:1630239073797130%311426be311426be"}

I followed the instructions to set up Google cloud function (https://medium.com/zmninja/using-your-o ... 8897d0ff49). I kept the code intact and changed only the fcm_v1_url to my new 'Trusted App' via URL 'https://us-central1-zmninjatest.cloudfu ... send_pusha' and I could get new notifications on my Android phone. However I got this in the log "Invalid credentials: Signature verification failed" although I keep intact “<YOUR_SECRET_HERE>” and DEFAULT_FCM_V1_KEY in zmeventnotification.pl and zmeventnotification.ini. If I restart my PC then I could not receive notifications on my phone anymore. If I use the FCMV1 link 'https://us-central1-ninja-1105.cloudfun ... /send_push', everything works normal again.

I tried to set up OAuth consent screen for my 'Trust App' in APIs & Services in my Google Cloud Platform and used a new token in fcm_v1_key but I still get "Invalid credentials" in the debug log although I still get notifications on my phone.

Could you please help me to resolve this problem? Many thanks in advance.

Regards,

Hieu

Here is the debug log I got when I use my new Google cloud function URL. I still receive notifications on my Android phone if I do not restart the PC. 

DBG-2:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 rules: Checking rules for alarm caused by eid:309412, monitor:3, at: Fri Sep  3 18:30:06 2021 with cause:[s] detected:person:99%  Motion All
DBG-1:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 rules: No rules found for Monitor, allowing:3
DBG-1:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 Matching alarm to connection rules...
DBG-2:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 isAllowedChannel: got type:event_end resCode:0
INF:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 Sending event_end notification over FCM
03/09/2021 18:30:06.713976 zmeventnotification[11695].INF [main:1049] [|----> FORK:Tum (3), eid:309412 Sending event_end notification over FCM]
DBG-2:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 fcmv1: Snapshot frame matched, changing picture url to:https://localhost/zm/index.php?view=ima ... d=1Wax2qsz
DBG-2:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 setting channel to zmninja
DBG-2:2021-09-03,18:30:06 |----> FORK:Tum (3), eid:309412 fcmv1: Final JSON using FCMV1 being sent is: {"badge":2,"log_message_id":"NONE","data":{"notification_foreground":"true","mid":"3","eid":"309412"},"android":{"priority":"high","channel":"zmninja","icon":"ic_stat_notification"},"image_url":"https://localhost/zm/index.php?view=ima ... ssword=xxx} to token: ...1fvMRF
DBG-1:2021-09-03,18:30:07 |----> FORK:Tum (3), eid:309412 fcmv1: FCM push message error {"Error":"Invalid credentials: Signature verification failed"}

DBG-2:2021-09-03,18:30:07 |----> FORK:Tum (3), eid:309412 child finished writing to parent
DBG-2:2021-09-03,18:30:10 PARENT: ----------> Tick START (active forks:2, total forks:4, active hooks: 1 running for:6 min)<--------------
DBG-2:2021-09-03,18:30:10 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 1, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-09-03,18:30:10 PARENT: RAW TEXT-->fcm_notification--TYPE--fBJFbUdSToaEUVlRUvddlw:APA91bEWItPBz67gDP1Ra7pb2578zGt5tvVf1KwotcZ0jEmCzH4f_flq3_HUVCnvQ3S0LqfxYakxRIsVzOjX4JgsyvdM6DCQwO8E6mao1BbvDCkl9Jh_eEA6sVDM3ZXPBrREoI1fvMRF--SPLIT--2--SPLIT--736--SPLIT--8
DBG-2:2021-09-03,18:30:10 PARENT: GOT JOB==> update badge to 2, count to 736 for: fBJFbUdSToaEUVlRUvddlw:APA91bEWItPBz67gDP1Ra7pb2578zGt5tvVf1KwotcZ0jEmCzH4f_flq3_HUVCnvQ3S0LqfxYakxRIsVzOjX4JgsyvdM6DCQwO8E6mao1BbvDCkl9Jh_eEA6sVDM3ZXPBrREoI1fvMRF, at: 8
DBG-2:2021-09-03,18:30:10 PARENT: RAW TEXT-->timestamp--TYPE--1630668265.65701--SPLIT--3--SPLIT--1630668606.71364
DBG-2:2021-09-03,18:30:10 PARENT: Job: Update last sent timestamp of monitor:3 to 1630668606.71364 for id:1630668265.65701
DBG-2:2021-09-03,18:30:10 PARENT: There are 2 active child forks & 1 zm_detect processes running...
DBG-2:2021-09-03,18:30:10 PARENT: checkEvents() new events found=0
DBG-2:2021-09-03,18:30:10 PARENT: There are 0 new Events to process
DBG-2:2021-09-03,18:30:10 PARENT: ---------->Tick END (active forks:2, total forks:4, active hooks: 1)<--------------
DBG-1:2021-09-03,18:30:11 |----> FORK:Tum (3), eid:309412 exiting
DBG-1:2021-09-03,18:30:11 |----> FORK:Tum (3), eid:309412 Ending process:11695 to handle alarms
DBG-2:2021-09-03,18:30:15 PARENT: ----------> Tick START (active forks:2, total forks:4, active hooks: 1 running for:6 min)<--------------
DBG-2:2021-09-03,18:30:15 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 1, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-09-03,18:30:15 PARENT: RAW TEXT-->active_event_delete--TYPE--3--SPLIT--309412
DBG-2:2021-09-03,18:30:15 PARENT: Job: Deleting active_event eid:309412, mid:3
DBG-2:2021-09-03,18:30:15 PARENT: There are 1 active child forks & 1 zm_detect processes running...
DBG-2:2021-09-03,18:30:15 PARENT: checkEvents() new events found=0
DBG-2:2021-09-03,18:30:15 PARENT: There are 0 new Events to process
DBG-2:2021-09-03,18:30:15 PARENT: ---------->Tick END (active forks:1, total forks:4, active hooks: 1)<--------------
DBG-2:2021-09-03,18:30:20 PARENT: ----------> Tick START (active forks:1, total forks:4, active hooks: 1 running for:6 min)<--------------
DBG-2:2021-09-03,18:30:20 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 1, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0
DBG-2:2021-09-03,18:30:20 PARENT: There are 1 active child forks & 1 zm_detect processes running...
DBG-2:2021-09-03,18:30:20 PARENT: checkEvents() new events found=0
DBG-2:2021-09-03,18:30:20 PARENT: There are 0 new Events to process
DBG-2:2021-09-03,18:30:20 PARENT: ---------->Tick END (active forks:1, total forks:4, active hooks: 1)<--------------
DBG-2:2021-09-03,18:30:24 |----> FORK:Tum (3), eid:309414 parse of hook:[a] detected:person:83%  and {"labels": ["person"], "boxes": [[430, 352, 772, 596]], "frame_id": "alarm", "confidences": [0.8271722197532654], "image_dimensions": {"original": [480, 640], "resized": [600, 800]}}
DBG-1:2021-09-03,18:30:24 |----> FORK:Tum (3), eid:309414 hook start returned with text:[a] detected:person:83%  json:{"labels": ["person"], "boxes": [[430, 352, 772, 596]], "frame_id": "alarm", "confidences": [0.8271722197532654], "image_dimensions": {"original": [480, 640], "resized": [600, 800]}} exit:0
DBG-2:2021-09-03,18:30:24 |----> FORK:Tum (3), eid:309414 For 3 (Tum), SHM says: state=0, eid=309416
INF:2021-09-03,18:30:24 |----> FORK:Tum (3), eid:309414 Event 309414 for Monitor 3 has finished
03/09/2021 18:30:24.500391 zmeventnotification[12057].INF [main:1049] [|----> FORK:Tum (3), eid:309414 Event 309414 for Monitor 3 has finished]
DBG-2:2021-09-03,18:30:24 |----> FORK:Tum (3), eid:309414 Event end object is: state=>pending with cause=>[a] detected:person:83%  Motion: All [a] detected:person:83%  Motion: All
DBG-2:2021-09-03,18:30:25 PARENT: ----------> Tick START (active forks:1, total forks:4, active hooks: 1 running for:7 min)<--------------
DBG-2:2021-09-03,18:30:25 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 0, FCM+WEB: 0, FCM: 1, WEB: 0, MQTT:0, invalid WEB: 0, PENDING: 0

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Sun Sep 05, 2021 7:56 pm
by asker
When you are setting up your own function, you need to both change the URL and the secret

I've changed the article to add more details. Hope that helps
https://medium.com/zmninja/using-your-o ... 8897d0ff49

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Mon Sep 06, 2021 2:49 am
by Vietace
Many thanks for your help! I will follow the new instructions in your article.

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Thu Sep 23, 2021 5:00 am
by Vietace
Hi asker,
Could you please help me again? I have successfully deployed my own function but I got the error “SenderId mismatch” both in ES log and in Firebase log
DBG-2:2021-09-23,11:32:54 |----> FORK:Tum (3), eid:341658 fcmv1: Final JSON using FCMV1 being sent is: {"badge":1,"image_url":"https://localhost/zm/index.php?view=ima ... _id":"NONE"} to token: ...smzkvv
DBG-1:2021-09-23,11:32:54 |----> FORK:Tum (3), eid:341658 fcmv1: FCM push message error {"Error":"token:OiX0smzkvv=>SenderId mismatch"}
DBG-1:2021-09-23,11:33:56 |----> FORK:Tang 2 (6), eid:341659 fcmv1: FCM push message error {"Error":"token:OiX0smzkvv=>SenderId mismatch"}

Firebase log
token:OiX0smzkvv=>SenderId mismatch

I found this possible answer for the error “SenderId mismatch” which I quote here:
https://stackoverflow.com/questions/378 ... es#tab-top
“Main issue was in device_ID(UDID) to whom I have to send the notification. Actually DeviceId we got on android side in FCM is different than GCM. You can't use GCM created DeviceId in FCM. I had to ask for the app developer to include the sender id on the code, then my FCM API KEY worked.”
Could you please help me to resolve this “SenderId mismatch” error?
Many thanks for your help!
Hieu

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Sat Sep 25, 2021 2:58 pm
by asker
Hmm,
So reading https://stackoverflow.com/questions/491 ... rebase-api

I think this is the situation:

a) zmNinja is configured to receive message only from a specific project (see this). So when it starts up, it gets a tokenID that can receive messages from the firebase project it is associated with
b) Your cloud function doesn't belong to that project

So maybe you just setting up a new cloud function is not the full story. You may need to re-compile zmNinja to use your google-services.json


This is a guess to be honest, needs experimentation

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Sun Sep 26, 2021 11:47 pm
by Vietace
Thank you. I will try to re-compile zmNinja for further testings.

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Tue Jul 05, 2022 1:40 am
by tsp84
Is it confirmed that a user needs to compile zmNinja themself with their GCP project URL hardcoded somewhere?

Re: "Invalid credentials" when using my own Google cloud function for ES

Posted: Fri Sep 09, 2022 6:34 am
by Vietace
tsp84 wrote: Tue Jul 05, 2022 1:40 am Is it confirmed that a user needs to compile zmNinja themself with their GCP project URL hardcoded somewhere?
Sorry, I haven't recompiled zmNinja yet. I hope someone in this forum may try to do this and let us know the results.