title: How to validate android billing receipt server side
body: <p>I'd like to make server side validation of a purchase receipt made in an android application. I'm using a node.js backend.</p>
  
  <p>I'm currently trying to do it using google-play-purchase-validator node module (<a href="https://www.npmjs.org/package/google-play-purchase-validator" rel="noreferrer">https://www.npmjs.org/package/google-play-purchase-validator</a>) which seems the most up-to-date module to do it (performing a real-time request to google purchase api).</p>
  
  <p>In the Google developper console, i created a Google Service Accounts, and then obtained an email and key to be used in the module, I also connect this Services Accounts with my application as explained in this post <a href="https://stackoverflow.com/questions/24323207/use-service-account-to-verify-google-inapppurchase">Use service account to verify Google InAppPurchase</a>). Unfortunatly it doesn't work. It seems that the jwt token generated by the node module isn't correctly signed (I get the following error : failed to sign JWT, the key is probably invalid).</p>
  
  <p>Here's some code :</p>
  
  <pre><code>var Verifier = require('google-play-purchase-validator');
  var options = {
    email:'myemail@developer.gserviceaccount.com',
    key: 'myprivatekey',
  };
  var verifier = new Verifier(options);
  verifier.verify(item.Receipt, function cb(err, response) {
  if (err) {
      console.log("there was an error validating the receipt");
      console.log(err);
  }
  else{
      console.log("sucessfully validated the receipt");
      console.log(response);
  }
  </code></pre>
  
  <p>The private key comes from a .pem file i was able to generate from a .p12 file provided by google using the following command :</p>
  
  <pre><code>openssl pkcs12 -in downloaded-key-file.p12 -out your-key-file.pem -nodes
  </code></pre>
  
  <p>The google-play-purchase-validator module is based on some others modules (google-oauth-jwt, request, crypto). I tried to debug a little, everything seems to be done correctly.</p>
  
  <p>Any idea where i may be wrong ?</p>
  
  <p>Paul</p>