Deishelon / google-play-billing-validator

Npm module for Node.js to validate In-app purchases and Subscriptions on your backend
https://medium.com/androidhub/how-to-validate-in-app-purchase-subscription-on-your-node-js-backend-a2b823470034
90 stars 32 forks source link

TypeError: Cannot read property 'error_description' of undefined #2

Closed skilFullGH closed 5 years ago

Deishelon commented 5 years ago

Steps to reproduce? In-app purchases or Subscription?

Thanks

skilFullGH commented 5 years ago

In-app purchase. My code works on local, but not does on my backend. What is a problem i did not find yet, but faced with this

Deishelon commented 5 years ago

Well, make sure your backend runs same npm versions as your testing machine. Run npm install to update dependencies. Another thing I'd suggest to do is to add a console.log(err) to the node_modules/google-play-billing-validator/index.js line: 40 And post output here, thanks

skilFullGH commented 5 years ago

Auth error:

{ Error: failed to sign JWT, the key is probably invalid
    at /usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:117:18
    at obtainKey (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:134:11)
    at Object.exports.encodeJWT (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:108:2)
    at exports.authenticate (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:19:10)
    at TokenRequest.TokenRequest.get (/usr/src/app/node_modules/google-oauth-jwt/lib/token-cache.js:75:4)
    at TokenCache.get (/usr/src/app/node_modules/google-oauth-jwt/lib/token-cache.js:30:19)
    at /usr/src/app/node_modules/google-oauth-jwt/lib/request-jwt.js:41:19
    at /usr/src/app/node_modules/google-play-billing-validator/index.js:36:5
    at new Promise (<anonymous>)
    at Verifier.verify (/usr/src/app/node_modules/google-play-billing-validator/index.js:35:10)
    at Verifier.verifyINAPP (/usr/src/app/node_modules/google-play-billing-validator/index.js:14:15)
    at ValidationInAppGoogle.validatePurchase (/usr/src/app/dist/src/services/validationInAppGoogle.js:23:51)
    at Purchase.verify (/usr/src/app/dist/src/services/purchase.js:200:14)
    at Purchase.create (/usr/src/app/dist/src/services/purchase.js:33:37)
  inner:
   Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
       at Sign.sign (internal/crypto/sig.js:83:26)
       at /usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:113:76
       at obtainKey (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:134:11)
       at Object.exports.encodeJWT (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:108:2)
       at exports.authenticate (/usr/src/app/node_modules/google-oauth-jwt/lib/auth.js:19:10)
       at TokenRequest.TokenRequest.get (/usr/src/app/node_modules/google-oauth-jwt/lib/token-cache.js:75:4)
       at TokenCache.get (/usr/src/app/node_modules/google-oauth-jwt/lib/token-cache.js:30:19)
       at /usr/src/app/node_modules/google-oauth-jwt/lib/request-jwt.js:41:19
       at /usr/src/app/node_modules/google-play-billing-validator/index.js:36:5
       at new Promise (<anonymous>)
       at Verifier.verify (/usr/src/app/node_modules/google-play-billing-validator/index.js:35:10)
       at Verifier.verifyINAPP (/usr/src/app/node_modules/google-play-billing-validator/index.js:14:15)
       at ValidationInAppGoogle.validatePurchase (/usr/src/app/dist/src/services/validationInAppGoogle.js:23:51)
       at Purchase.verify (/usr/src/app/dist/src/services/purchase.js:200:14)
       at Purchase.create (/usr/src/app/dist/src/services/purchase.js:33:37) }

"err.body" can be undefined

Deishelon commented 5 years ago

failed to sign JWT, the key is probably invalid your key for the service account is incorrent. Check your key

Deishelon commented 5 years ago

Although I tested with the invalid key and the body existed. I will check and update it repo

skilFullGH commented 5 years ago

Ok, thanks!

Deishelon commented 5 years ago

Was able to reproduce the same error, make sure your private key is the same as in the file you downloaded from Google API Console. ie. Don't delete any \n or -----BEGIN PRIVATE KEY----- or somehow modify the key.

The fix is in 2.0.2. Please update

skilFullGH commented 5 years ago

I tried pass key via environment variable. Now i take key direct from *.json and it works

Deishelon commented 5 years ago

Probably will be a good idea add some documentation how to add key as an environment variable, also if you don't wanna hard code the key into your code, you can pass keyFile as an option to the Verifier.