web push notification on mozilla - push-notification

i am testing web push on my local.
below command gives me the push when i am capturing the end point on chrome.
curl --header "Authorization: key=XXXXXXXXXXXX" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"fs...Tw:APA...SzXha\"]}"
but when i allow and capture end point on Mozilla.
response of above command:
{"multicast_id":############,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
end point i recieve on mozilla
14:20:55.180 endpoint: "https://updates.push.services.mozilla.com/wpush/v1/gAAAAABXobDz85y9Aqz5wn0PVS4ka-p7ESp8fviKNzDPQPWfR4kZfsgUZVx7MauSN4udurIBVlC8-LdG8hsC6jOchCNMEQ2vJ5pK9n-HVf2GpQm7PP6GrsfOjjIeP_uOJDOcMLD7GZKE"1 main.js:8:13

Here is a simple demo, which works in both browsers Google Chrome and Mozilla Firefox: https://serviceworke.rs/push-simple_demo.html
Try to open it in both browsers and you will see which link you have to use to send a push message for your browser and a difference between links for Google Chrome and Mozilla Firefox. For me, the links are:
Google Chrome
curl -H "TTL: 60" -X POST https://android.googleapis.com/gcm/send/f3WCPreREPE:APA91bHqGD-Oc4o8LqxnuepBvw4SGtIlFeyxP0F2ksMjxPH9yZxLfGZx_6aN7X9cqiSvIQGN4HI6KnAiuWac-_jvKMb1vTFE7_GuPZG1WsNzhyEQVT-BdXIim79SJOyWbwkV91S23isP
Mozilla Firefox
curl -H "TTL: 60" -X POST https://updates.push.services.mozilla.com/wpush/v1/gAAAAABXt1OmbjxoPG6_YpmEzYZdsYWWE9bj_JQUUbqwuqTB53t_uBKW3bOZNqJ9BG0ZBkEOpPffYHUT3VW-iI7XeBtFydNWnx4KlIGKL75443jdErWhrarb9GAuzwdP_Cen0kOhDG3G
It also have the source code for client and server side.
Or look at the source code of java lib for WebPush notifications: https://github.com/MartijnDwars/web-push/blob/master/src/main/java/nl/martijndwars/webpush/PushService.java#L88-L115
The code is really easy and it explains how to build an HTTP request for FCM/GCM or Mozilla autopush.

You must do a POST request to:
https://updates.push.services.mozilla.com/wpush/v1/gAAAAABXobDz85y9Aqz5wn0PVS4ka-p7ESp8fviKNzDPQPWfR4kZfsgUZVx7MauSN4udurIBVlC8-LdG8hsC6jOchCNMEQ2vJ5pK9n-HVf2GpQm7PP6GrsfOjjIeP_uOJDOcMLD7GZKE
You cannot use GCM for Mozilla. GCM is only for Chrome.

Related

Creating URL with headers

I can curl a website URL by passing on some header params. I am trying to get the same result on the browser but I cannot build the URL for the browser in the right way.
My curl looks something similar
curl -X GET -u 'xyz#gmail.com' -H "app-key: some-keys" -H "account-email: procurement#gmail.com" -H 'Content-Type: application/json' -d 'paused=false' https://api.pingdom.com/api/2.1/checks
When prompted for the password, i can give the password and Iget the JSON response.
Now I try to build the same URL on my browser. The browser prompts for user name and password which I have already given.
Now my URL looks like this.
https://api.pingdom.com/api/2.1/users?account-email=procurement#gmail.com&app-key=some-key
I get a forbidden (as JSON reponse) when I try from the browser and from Curl I get the proper JSON response.
How can I add header params to a URL when pinging from the browser?
How can I add header params to a URL when pinging from the browser?
That's not possible. Besides it, from the browser address bar you won't be able to use HTTP methods other than GET.
So I advise you to you proper tools to target/test your Web API such as Postman or Paw.

How to send a Firebase Cloud Messaging Notification with special characters like ä, ö, ü?

I tried for a while to send a FCM Notification with special characters like this:
curl --header "Authorization: key=Auth-CODE"
--header Content-Type:"application/json
for JSON; application/x-www-form-urlencoded;charset=UTF-8"
-d '{"to":"token","notification":{"title":"München",
"body":"Test Content with äöü",
"icon":"images/icon-192x192.png"}}'
https://fcm.googleapis.com/fcm/send
The notification I'll get looks like this:
Mnchen
Test Content with
Can anybody please guide me to the right direction?
Thanks a lot!
EDIT
The client is a browser, because the app is a web-App.
According to #LangHoang I tried to use Base64 encode and decode to get a special character support!
<?php
base64_encode ($string);
and decode the response in javascript (firebase-messaging-sw.js)
body:b64DecodeUnicode(payload.notification.body)
And now everything works very well!
With application/json;charset=UTF-8 should work. Had the same issue, that adding charset=UTF-8 to the Content-Type solved it.

Clarifai API and cURL?

I'm following Clarifai's guide to make a cURL request and get the tags related to the image.
In the guide it says that I can do either this:
curl "https://api.clarifai.com/v1/tag/?url=https://samples.clarifai.com/metro-north.jpg" \
-H "Authorization: Bearer {access_token}"
or this:
curl "https://api.clarifai.com/v1/tag/" \
-X POST --data-urlencode "url=https://samples.clarifai.com/metro-north.jpg" \
-H "Authorization: Bearer {access_token}"
So what I do is that I type in the access token that I get when I create a new application and I change the link of "samples.clarifai.com" for a random link of a random image, but every time I want to do this I get the following message on terminal:
{"status_code": "TOKEN_INVALID", "status_msg": "Token is not valid. Please use valid tokens for a application in your account."}
Any idea why I keep getting this eben though my access token is right?
Thanks!
Just so there can have an official answer for this but Marcus Müller is totally right.
You should be sure to remove the braces with the Bearer access token. But you still want to be sure everything else is fine. This does assume though that you have generated a proper access token either by the Developer Documentation or within your Applications page once you have logged in.

How to convert curl request to browser URL

Is it possible to generate equivalent browser URL from all curl request.
Example :
If I am executing following
curl -v -X GET -H "Host:something.com" "http://foo.com/some?appAction=xux&a=1&b=2"
What will corresponding browser URL.(which I can hit directly in browser)
If by "equivalent" you mean "Using a host header claiming a different host than mentioned in the request URI", then the answer is: no, you can't. The browser will pull the host header from the entered URI.
You may be able to rewrite the headers using browser plugins.

Translating from cURL to straight HTTP requests

What would the following cURL command look like as a generic (without cURL) http request?
feedUri="https://www.someservice.com/feeds\
?prettyprint=true"
curl $feedUri --silent \
--header "GData-Version: 2"
For example how could such an http request be expressed in the browser address bar? Partucluarly, how do I express the --header information if I were to just type out the plain http request?
I don't know of any browser that lets you specify header information in the address bar. I believe there are plug-ins that let you do this, but I don't have any experience with them.
Here is one for firefox that looks promising:
https://addons.mozilla.org/en-US/firefox/addon/967
Basically what you want to do is not a standard browser feature.

Resources