Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
828 stars 229 forks source link

Private Key Signing vs Signing from Service Account file #310

Closed deepanshug closed 9 months ago

deepanshug commented 9 months ago

What's your question?

Invalid Signature when using RSA 256 sign

Additional Context

Hi, I used your library for a particular use case to generate JWT token for google APIs. To access google APIs, I am using service account which gives me key.json file with private key in it.

I tried to use this private key mentioned in key.json file and used as below ".sign(jwt::algorithm::rs256("", rsa_priv_key, "", ""));" where rsa_priv_key contains value from key.json file.

My question is: is there any way that I can pass this key.json file to sign?

deepanshug commented 9 months ago

In short, signing by openssl throws Invalid JWT SIgnature error while signing bu google.auth.crypt package (in python) generates a valid one that gives me access token

deepanshug commented 9 months ago

Please help

prince-chrismc commented 9 months ago

Please refer to Google's documentation about how to use their JWT. Looking at https://googleapis.dev/python/google-auth/latest/reference/google.auth.crypt.html you'll need to implment whatever logic that is doing under the hood.

There are old issues around this, you should do some research on this topic https://github.com/Thalhammer/jwt-cpp/issues/282 https://github.com/Thalhammer/jwt-cpp/issues/271#issuecomment-1336502752 you are probably going to need #146 :)

prince-chrismc commented 9 months ago

I am going to mark this as closed since it's related to how to using Google not the library, please feel free to open a new issue with any specific technical questions about the library :)

deepanshug commented 9 months ago

I agree, thanks for closing.