C2DM - problems when Using the new AuthToken after I get Update-Client-Auth - android-c2dm

Im developing push notification server that works with google's C2DM service.
When I get "Update-Client-Auth" in the response header , I replace the previous token , for use on the next push notification.
When I send notification right after I got new token , it fails -
with the response - "InvalidRegistration"
My questions are ?
How to avoid this ? Should I wait before I use the new token ?
When do I need to start using the new token ? is the expiration date included on header should be used ?
I havent found this phenomenon mentioned anywhere.
thanks for any advice.

I don't think the problem is with your Auth. token.
"InvalidRegistration" means that the Registration token of the device to which you're sending the C2DM Message is invalid. You should make sure that the device sends you an updated Registration Id/token if it changes (apparently it can).
Clear your server cache/DB and start again by getting the device to re-register with Google and then send the registration token to your server and see what happens.
Of course, I'm guessing you don't have lots of registrations in your DB, if you're still in development...
Regards,
Mark

Related

Google Home "Couldn't update the setting. Check your connection.'

So this type of error is being reported on a lot of community boards over the course of the last year with no acceptable answer we could find. We have just started our journey integrating with Google Home and created a Home Automation Action and we are getting a similar error …
{
insertId: "10wvnj2fyb1thy"
logName: "projects/bitdog-home-f69bd/logs/actions.googleapis.com%2Factions"
Show matching entries
Hide matching entries
Add field to summary line
receiveTimestamp: "2018-12-06T13:28:13.939975519Z"
resource: {
labels: {
action_id: "SMART_HOME_SYNC"
project_id: "bitdog-home-f69bd"
version_id: ""
}
type: "assistant_action"
}
severity: "ERROR"
textPayload: "SYNC: Request ID 742344561631232315 failed with code: OPEN_AUTH_FAILURE"
timestamp: "2018-12-06T13:28:13.931998358Z"
}
This shows on Google Home app as "Couldn't update the setting, check your connection"
The OAuth service logs show a successful account linking and a successful refresh_token request. Google does not attempt a SYNC call to the Action handler from what we can tell.
We have other systems using the OAuth server and they are working well and we are little lost on how to proceed to debug this issue. We created a support ticket today but I don't feel confident that we will get meaningful help.
We have also tried using the Google Home app on Android and iOS. We have tried changing the default browser from Chrome to Firefox. Nothing has changed the outcome. We also made sure that our access_token was in JWT format to see if google was sensitive to token size or format and nothing worked. We even made sure that the Google Home app user matched the user logged into the browser.
Help!
I did get it working. It was already working with an Amazon Echo Skill but it seems that Google's implementation (OpenAuth) is a bit more strict. I changed my access_token from a proprietary encrypted token format to a legit signed JWT token. I also removed expires_in from the response and it started working, not sure if it was the access_token JWT token format or removal of expires_in. I'm happy I can move on. If I get a chance, I will test to see which change made it work and comment here again.
Thank you.
To anyone with this problem–
I had to take multiple steps to resolve this issue, which are not clearly outlined in any documentation.
As per Google support:
Please adjust your account linking implementation from implicit to auth code flow then perform test again.
On the documentation for OAuth account linking, it says there are two methods of authentication: implicit and auth code. Apparently, only the auth code flow works for smart home.
I am using the Actions on Google Node.js library. While poking through the documentation, I found that:
[The SYNC request fulfillment] should return a valid response or a Promise that resolves to valid response.
The problem is that I was doing a database operation (which took time), so I couldn't simply return a value when it was ready; I had to return a Promise insead, then fulfill that promise later.
Hopefully this is helpful to anyone stuck on this reoccurring issue! Basically, check your auth flow and make SYNC is returning a valid JS object on time.
I was facing the same issue from last 2 weeks and was wonder when saw it is a 3 steps problem.
Check your SYNC intent is properly parsed
Incorrect Response Structure (Verify here-Smart Home SYNC Data Validator)
Device Response time-out should be less than 5 sec.
You can check Link
My problem started when I connected by Sonoff Bridge.
So I got it working by removing my 'Sonoff Bridge' and connecting it to Google Home. (All mu light are now working). Added the Bridge again to Sonoff and using IFTTT to connect to my Bridge

Where is GCM documentation for 'InvalidTokenVersion' error?

I am using the Google Cloud Messaging services described at https://developers.google.com/instance-id/reference/server but I am getting a HTTP response status of 400 and this response text:
{"error":"InvalidTokenVersion"}
At the time I write this, that exact error code has zero results on Google! Has anyone else encountered it? I could understand "InvalidToken" but it is the "Version" bit which is confusing me.
I'd like to see a nice list of all the possible error codes for the https://iid.googleapis.com/iid/info/ and https://iid.googleapis.com/iid/v1/*/rel/topics/* services, if you know where that is?!
All the GCM pages say at present is...
HTTP status 400 (Bad request) - request parameters are missing or invalid. Check error messages for detailed information.
Background information:
I am using a registration token from an Android device which still shows a log of successful notifications in the GCM Diagnostics (part of Google Play Developer Console). So surely the token cannot be wrong?
If I try a token value of "bum" I get error "InvalidToken" instead.
However, trying to send a new notification with https://gcm-http.googleapis.com/gcm/send results in the "InvalidRegistration" error, so I guess something has gone screwy.
I'd like to claim that I've changed nothing recently, but something to do with SSL on the server might have expired I suppose.
The token you are providing is regId not instanceId.token. Follow the documentation:
https://developers.google.com/cloud-messaging/android/client.
see examples here.
https://github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart

how to validate Apple APN device token - WCF .NET

I am building a WCF REST web service that is called by the mobile app to insert the Apple device Token into the database. I would like to validate a device token before inserting into the database. Is there anyway to validate a device token to know if it is valid??
I have searched around the forum and could not find any sample code (in .NET) to do this, there were recommendations that I should use the Apple FeedBack service but how do I do that in .NET??
Could anyone please provide me a piece of sample code to validate an Apple Device Token in .NET.
Many thanks,
You can't validate the device token. The only thing you can validate before inserting the token to your DB is that its length is 32 bytes (in binary representation) or 64 Hexadecimal characters (in a String representation).
Beyond that, you should check the responses from Apple to see if you get an InvalidToken error response. If you do, you know the device token sent with the message that causes the error is invalid.
The Feedback Service does not return invalid tokens. It returns valid tokens of devices that uninstalled your app.
I can't give you any C# code, but PushSharp should support calling the Feedback Service and reading error responses from Apple.
This is the little irrelevant answer, but recently i came across this question, as my problem was that i have long list of Notification Token and in that some of them are invalide.
So i need to filter them, but there is not easy way for that but there is 1 app that i use to send/test notification certificate,
Knuff : https://github.com/KnuffApp/Knuff/releases
In that if you give it wrong notification token than it will display error like this,
So that way anyone can validate the push notification token.
Hope it will help user like me.

Notification via open graph

I have a problem with adding notifications on Facebook.
According to:
https://developers.facebook.com/docs/reference/api/user/#notifications
I prepare request:
https://graph.facebook.com/FACEBOOK_USER_ID/notifications?template=hello&href=track_123&access_token=USER_ACCESS_TOKEN
but I get the response:
Sorry, something went wrong.
We're working on getting this fixed as soon as we can.
Is this request correct?
There is a slight problem in the above url , access token to be used is not of the user but of your app. First you need to get your app access_token by the use of the following get call.
GET https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID
&client_secret=YOUR_APP_SECRET
&&grant_type=client_credentials
This will return you app access token which you need to use in the above url.
Hopefully this will solve your problem.

IOS Authentication with DB online

I have to build an App that need authentication over a DB (online).
When application load, at first appear a login screen to insert user credentials.
Thus after a correct login, user can access every areas of this app.
I think to use this steps, what do you think about?
1) Build a PHP (or other lang) Webservice that accept username/password(crypt) and check this data. When user is found, create a token with some strange unique string and adding a expiration time information. Send token back as response with some sort of json structure.
2) The IOS APP call this service passing username/password, if the webservice response is positive, store the received token in NSUserdefault and add time of creation (so i can calculate when it expire.
3) From my APP i can make request toward webservice sending my token. WS checks Token validity and send back a response.
Is this a good practice ???
Yes and no.
I think your approach will work as you wrote it. But keep in mind, that your users needs an internet connection to use your app. So I would design the structure in a way it has also a use for the user, if he has no internet connection.
I also don't know how good your expirience is with Webservices and the communication with them. If you send the data, you should also encrypt the sent data, because they are the credentials of the user. So it's not save to send them as GET Values for examples in a PHP script...
I hope my answer did help a little bit. If you have specific questions on this type of webservice, just ask. I did this a few times before. ;-)
Sandro Meier