Why chrome browser is changing endpoint frequently - google-chrome

I’m developing chrome push notification for my web site and doing the development in localhost (local machine) environment. Sending push notification is success with specific endpoint which I got when I subscribe the notification first time. I use same endpoint for all push messages.
Here sometime push notification got failed due to endpoint mismatch. When I see in chrome console (debugging mode) there was different endpoint.
Why chrome browser is changing endpoint? In this case how do we handle this scenario and update the new endpoint in the db?
sample endpoint:
https://android.googleapis.com/gcm/send/AWERdvfdfdsfdobRH4zlXGuyeuie3543uTBuP6air5dzZfltNa-FKF6K6S-9P5SdfbCbyvn9RdsfsdvU1XwSBwIrekjdK6_i4Cg-5rZAj8UvL1s-Bbr61yvvt_y2Hg9RdsyV
when i check next time, above endpoint got changed as like below
https://android.googleapis.com/gcm/send/reytryMkQwtY:YTUNMdsjjfhsdf349851VS6McDE7s_GITe_djsgfdkjghcdfdfgdftrkddfdsXiwX1vP_XclmDqrKPOAMJDfsYYXdhMX164694Q&ksdhfksdfhkjfhksdcndsk
Thank you.

The push notification endpoint is dependant on the service-worker. When a service-worker is unregistered and created again, the PushManager.getSubscription() method will indeed return null. You then need to call subscribe() again, which will return a new endpoint.
If you server tries to send a push notification to the first endpoint after the service-worker was unregistered, you will get a NotRegistered (for Chrome) or a Gone (for Firefox) error. So make sure to register the new endpoint as soon as the app loads or the device may become unreachable.
Note that this does not seem to affect service-worker updates.

Related

Sending a message from FCM Console not working for Web Tokens

I am implementing Web Push Notification in an application and I have successfully registered the client app with GCM. I have the subscription object that contains the endpoint that looks like this.
"https://android.googleapis.com/gcm/send/dV4lSfI5J6Q:APA91bEU28F9YG5qNr3xSjvYlH2Mh1GPgiqMaRcjandHbpfqnVyAeZxqoE31OXYq4yzW2_vrkn74YHdgsITZP_6SELO8-xHf1hylquJefJdY85-Xx9AWTAPP9H6kfq7CKp23dsoQHbH
I read and found out that we need to use a third party library like web-push to send push using this endpoint to the clients because the payload needs to be encrypted according to spec. My objective is to send notifications to all my users, web + mobile, at once, using Firebase Console's Notification feature.
Is there a way to send push to web clients using Firebase console or to convert the GCM endpoint to an FCM token?
Update: If I try to use Firebase console to send push the token generated above, I get the following error.
As per testing this out, for some reason, registration tokens for Web are not working or allowed in the Firebase Console. Only tokens for Android and iOS do:
The request could still proceed where the console would show that it is sent/complete, but there wouldn't be any messages received.

why does chrome not send cookies from a webworker?

I have a page on domain A which loads a webworker script from domain B. The webworker is fetching some PNGs from doman A's server.
In Firefox, the request to get the PNGs contains the cookie for my site (domain A).
In Chrome, it does not include the cookie for my site, and so fails because the request must be coming from a logged in user (which requires the session cookie to be sent in the request).
Which browser is behaving correctly, and can I do anything to make Chrome send the cookie for the current domain from within a webworker?
UPDATE:
I pulled all the files from domain B and hosted them on my server at domain A, so the webworker file is now on the same domain as the site itself, but Chrome still does not send the session cookie with the requests from the web worker.
With regards to the first problem, it looks like the Firefox is incorrect, you shouldn't be able to instantiate a Worker on another domain to quote the spec:
"If the scheme component of worker URL is not "data", and the origin
of worker URL is not the same as the origin specified by the incumbent
settings object, then throw a SecurityError exception and abort these
steps."
With regards to Chrome the Workers run in a separate they work for me and without seeing more code it's hard to answer. But if you visit this demo and break before the postMessage to the worker set document.cookie='test=1' you will see that when the request goes out from the worker it is set.

Does Box.net SDK or API supports notification for any changes(add/delete/modification of any file or Folder)

Is it possible get notification on application level on client side in iOS(and Android) whenever some changes happens like new file/folder added or removed on Box.net? Please confirm if SDK supports this behaviour, if not then is there any way to implement this behaviour on client side.
Thanks.
You should be able to get notifications about events happening in a user's account by using the /events endpoint:
http://developers.box.com/docs/#events
Essentially, you'll need to authenticate as the user via OAuth2 and issue an OPTIONS request to the /events endpoint to get a realtime server URL. You should set up a long poller to poll that realtime server, and when it issues a response that notifications are available, issue an authenticated GET request to /events?stream_type=....
Both the iOS SDK and the Java/Android SDKs should support this.
https://github.com/box/

EWS: getting past Forefront security trying to access /EWS/Exchange.asmx

I have this app that uses EWS to access mail, using the standard /EWS/Exchange.asmx SOAP endpoint.
One my user's mail servers is protected by Microsoft Forefront, and the initial HTTP request to
https://server_name/EWS/Exchange.asmx
is redirected (HTTP 302) to:
https://server_name/
CookieAuth.dll?GetLogon?curl=Z2FEWSZ2FExchange.asmx&reason=0&formdir=3
which is an regular HTML page, the point of which, I guess, is to make the user authenticate "manually".
I've not heard about Forefront until today, not sure how to handle it.
Is this normal behavior for Forefront (i.e. it always redirects the initial HTTP request), or is it triggered by something in my app? For example, user-agent?
If it's normal, how am I supposed to get past this page and access /EWS/Exchange.asmx?
If it's triggered by something my app is doing, how can I find out what it is?
My code runs on Android and forms its own XML requests without using any SOAP library. At the transport level, I use Apache HTTP client components. The code works fine with Office 365/Exchange Online, and, according to user reports, "self-hosted" corporate Exchange servers with NTLM.
However, in this case, I'm not even getting an HTTP 401: the HTTP 302 is returned by the very first HTTP roundtrip.
Trying to preemptively authenticate the initial request using Basic authentication didn't make any difference.
The user who reported this issue also mentioned that another EWS based app works, so there must be a solution to it.

box.com api OAuth authentication

Either I'm dense, or the docs assume I already know what they're telling me, but I need some clarification on doing authentication for a box.com app. I really don't understand whate's going on. As I read it:
the app running on the user's machine sends a request to Box, including all the little secrets (Which aren't all that secret any more if the user knows how to read the code).
The user is directed to the Box login page, which then sends the user to my server (with no page specified) attaching an authentication code.
The app somehow magically gets that code back from my server and sends a request to Box for the access token.
Box sends the access token to my server?
The app again magically gets the access token from my server and sends its APT requests.
Obviously I got lost somewhere.
And, why do I have to have a server involved in the process? The article on making a JavaScript app refers to a direct request for a token. Is there documentation on that somewhere?
You register your application on Box
After registration you receive clientId and clientSecret once on Box website
You hardcode your credentials somewhere in your application
First time your application needs to access Box API it should redirect user to https://www.box.com/api/oauth2/authorize, specifying your clientId, clientSecret and redirectURI as parameters. About redirectURI see below.
The box.com website opens. User enters his own credentials in the web form on box.com
User allows your application to access his files via API on the box.com website
Box redirects user back to you application using redirectURI specified before. One of the parameters to this request is "code". This is a very short-lived (30 seconds) access code that is only aligable for obtaining real access token.
During next 30 seconds your application should make another call to Box API to next URL: https://www.box.com/api/oauth2/token, specifying the previously obtained code. If everything was correct, your application receives an access_token, a refresh_token and "expires" values.
Now your application can make requests to Box API, specifying access_token every time
access_token expires in number of seconds, specified in "expires" field. It should be about 3600 seconds or 1 hour. Each time your application sees that access_token has expired, it should make another request to Box with the refresh_token and obtain a fresh access_token for another 1 hour.
refresh_token itself expires in 14 days
Note: if you develop a desktop application, then you should open browser for user on the step 4, redirectURI should be something like http://127.0.0.1:8080/Callback and you should run a small webserver just to catch the redirect with the code as in step 7.
Box requires that you specify a redirect_uri in your application's profile, and it must be an HTTPS URL.
As a result, it is not possible to use box with what google's oauth2 documentation calls "Client Side" or "Installed" applications, only "Web Server Applications" are allowed. Web Server applications do not have the secret leaking problem, because only the server knows the secret. You can pass the access token from your server to javascript on the client after
the oauth transaction is complete, if you want the client to make api requests directly.
In your question you are not totally clear in what you are actually trying to produce.
I however suspect that you are trying to write a client application what needs to authenticate to box using the OAUTH2 solution they have delivered in API V2.
If this is for an IPhone for example BOX has a great example of how to handle it.
In a WinForm application you would need to capture the resulting code sent back by box in the browser1.isnavigating event.
Windows console application you register a custom URI registration to collect the code.
Neither of these need to be registered in the API developers Application on box as you would pass the redirect required in the request to box.
If this does not point you in the right direction and your writing a .NET app then post again and I will try to clarify a little more.
Box requires some form user interaction which is short sighted in my opinion but try a web service that simulates a user interaction which then you can save/pass the token to your application to sync up with the Box "Cloud".