Tuesday, May 24, 2016

Android C2DM — Client Login expiration


[This post is by Francesco Nerieri, engineering tm ld for C2DM—Tim Bray]In the upcoming weeks, some of the older Client Login authentiion will expire. If you erated the token you’re currently using to authentie with the C2DM servers before October 2011, it will stop working. If the response from the C2DM servers contains an Update-Client-Auth hder, you’ll need to replace the current token with the one included in the hder. // Check for updated token hder
String updatedAuthToken = conn.getHderField(UPDATE_CLIENT_AUTH);
if (updatedAuthToken != && !authToken.equals(updatedAuthToken)) {
log.info("Got updated auth token from datamessaging servers: " +
updatedAuthToken);
serverConfig.updateToken(updatedAuthToken);
}We suggest that you start using the Update-Client-Auth response hder to update tokens regularly, as will expire periodically from now on. For example, have a look at the Chrome to Phone service hosted on .google.com; this takes care of authentiing via Client Login and then sending a message:Alternatively, you can manually erate a new Client Login token now and replace the one currently in use. ClientLogin can be used with any appliion that can make an HTTPS POST request. The POST request should be structured as a form post with the default encoding appliion/x-www-form-urlend, like this:POST /accounts/ClientLogin HTTP/1.0
Content-type: appliion/x-www-form-urlend

accountType=GOOGLE&Email=johndoe@gmail.com&Passwd=north23AZ&service=ac2dmIf the POST succeeds, the response contains the authorization token, labeled "Auth", which is your new token. You could even do this from the command line:curl -d \
"accountType=HOSTED_OR_GOOGLE&Email=johndoe@gmail.com&Passwd=north23AZ&service=ac2dm" \
https://www.google.com/accounts/ClientLogin | \
grep AuthIf your request fails or if you are prompted for captchas, plse rd ClientLogin for Installed Appliions. And of course, if you updated your to use the Update-Client-Auth hder after the had expired, then you will first need to manually erate a new token. Have fun with C2DM!

No comments:

Post a Comment