Yahoo Games Canvas APP – Authentication using PHP

Last Month, I was working on Yahoo Canvas Game. I have coded as per Docs for Authentication Users but HASH matching was failed every-time. After so many debug I figured it out that Documentation itself wrong in Yahoo Gamesnet.

Doc is saying we have to generate auth using

var auth = hmacSha256(getUtf8Bytes(gameSecret), jsonBytes) 

above code will give wrong hash. Instead we just have to switch parameters on hash generation like below

var auth = hmacSha256(jsonBytes, getUtf8Bytes(gameSecret))

Example Code using PHP

$usertoken = filter_input(INPUT_GET,'usertoken', FILTER_SANITIZE_STRING);
$exploded_token = explode(".",$usertoken);
if(count($exploded_token) == 2) {
  $json_string 	= utf8_decode(base64_decode(strtr($exploded_token[0], '+/=', '-_,')));	
  $userinfo 	= json_decode($json_string,true);	 
  if (!empty($userinfo['expires']) && $userinfo['expires'] > time()) {
    if ($userinfo['version'] == "V1_HMACSHA256") {		
      $secret 		=  'GAME_SECRET';
      $auth_token 	= hash_hmac('sha256', $json_string, $secret, true);
      $sign_token	= base64_decode(strtr($exploded_token[1], '+/=', '-_,'));
      if ($sign_token === $auth_token) {
	    echo "User Token Match";
      } else {
        echo "invalid usertoken auth";
    } else {		
      echo "unknown usertoken version: " + $userinfo['version'];
  } else {	
    echo "the token has expired";

Get Current Location Details using Google GeoLocation

We can easily get current location using HTML5 Navigator object. Please follow below steps to get city/country details

Including jQuery Lib
</p> <p><script src="//"></script>

jQuery(function() {
  //call navigator object to get latitude and logtitute
  if(navigator.geolocation) {
	//getting current latitude and longtitude
	navigator.geolocation.getCurrentPosition(function(position) {
	   //get location details based on latitude and longtitude from Google
	   var jsonUrl = ""+position.coords.latitude+","+position.coords.longitude
	   jQuery.getJSON(jsonUrl , function( data ) {
	      var results = data.results[0];
    ; //check firebug
	      alert(results.address_components[5].long_name); //City
	      alert(results.address_components[6].long_name); //State
	      alert(results.address_components[7].long_name); //Country
	      alert('Failed to get Location Details...');
	return false;


Ember JS – Use of RESTAdapter and FixtureAdapter

In Ember JS default store uses RESTAdaptor . Its hard to user another store with FixtureAdaptor but we can assign adapter to particular Model like below.

App.Store = DS.Store.extend({ revision: 4, adapter: DS.RESTAdapter.create({'url':HOST, namespace:NSPACE}), });

Above code is for Store and We can’t create App.Store2 in current version of Ember JS to use FixtureAdapter. Instead we can assign new adapter for that particular Model like below.

App.StudentAdapter = DS.FixtureAdapter.extend();