mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.97k stars 214 forks source link

Invalid verify, using generated token with firebase createCustomToken #69

Closed jmtovarf closed 8 years ago

jmtovarf commented 8 years ago

Hi, I'm using the new version from firebase to generate a custon token using jwt, it's using the private key of the google service account to sign the token, but when I'm using JwtStrategy to verify the token it is returning Error: PEM_read_bio_PUBKEY failed.

the structure of the key is:

-----BEGIN PRIVATE KEY-----\n ...... ..... .... -----END PRIVATE KEY-----\n

mikenicholson commented 8 years ago

This library doesn't actually contain the code to do the verification of the JWT. passport-jwt depends on jsonwebtoken to do the verification. This module is really a lot of glue logic to handle parsing of the JWT from the request and integrate with passport.

To first start debugging this I would run your data through the verify method of jsonwebtoken (see that modules readme for documentation). If its passing verification directly through jsonwebtoken but not through passport-jwt then that would indicate that there might be a problem with the way passport-jwt is handling the interaction. Let me know what you find.

mikenicholson commented 8 years ago

Since I haven't heard anything on this I'm going to go ahead and close. Let me know if you have any further info from debugging.

mhuebert commented 8 years ago

I ran into this problem myself this afternoon. The google service account key needs to be converted to the public PEM format, for which you can use node-rsa. Detailed instructions: http://stackoverflow.com/a/38187086/3421050

mikenicholson commented 8 years ago

@mhuebert Thanks for the solution. Closing.