Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FirebaseIdToken::Signature.verify(token) returns nil, however the certificate does exist #29

Closed
omartorresrios opened this issue Aug 24, 2020 · 3 comments

Comments

@omartorresrios
Copy link

omartorresrios commented Aug 24, 2020

Hi, this is a great gem.

I want to know if anyone could help me with this issue. When I try to verify a token I get nil, but the certificate does exist.

Screen Shot 2020-08-24 at 11 02 40

From my Firebase SDK file I am putting the private_key field because with the others it does not work.

Screen Shot 2020-08-24 at 12 56 36

Screen Shot 2020-08-24 at 11 16 28

Thanks!

@pierrea
Copy link

pierrea commented Oct 27, 2020

I'm not sure if the private_key issue is relevant to the first issue of receiving nil when attempting to verify a token. What exactly are you doing when verifying the token?

@cfanpnk
Copy link

cfanpnk commented Dec 25, 2020

I spent almost a week on this issue. It turns out this is caused by the expired token. If the token is expired, the kid from the JWT header somehow will return a value that doesn't exist in the public keys (https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com).

The only reason I can figure this out is by looking at how firebase admin sdk is implemented in other languages: https://github.com/firebase/firebase-admin-node/blob/5d72c1b40ef9383060d500e4f08678cb37ab8c0e/src/auth/token-verifier.ts#L237
Notice that if kid doesn't exist in public keys, the error message will say something like Most likely the token is expired

So here is my solution:

  1. Use verify! to raise an exception
  2. Rescue FirebaseIdToken::Exceptions::CertificateNotFound and return 401
  3. The client app will refresh the token if expired

Hope this can help other people who ran into this issue. Firebase really needs to document this well.

@fschuindt
Copy link
Owner

I've added explanations about this on the README. Thank you, folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants