Ruby Firebase ID Token verifier (pre-release)

Alt text Code Climate Issue Count Test Coverage Inline docs

A Ruby gem to verify the signature of Firebase ID Tokens. It uses Redis to store Google's x509 certificates and manage their expiration time, so you don't need to request Google's API in every execution and can access it as fast as reading from memory.

It also checks the JWT payload parameters as recommended here by Firebase official documentation.

Pre-release Notes

This gem was developed recently and needs real world feedback.

If you are going to use it in a production environment, please note that I am still testing it. It has realistic RSpec examples that use real X509 certificates and signed JWT to perform tests and I can say it's working great. But using it implies in security risks, you should be aware.

Feel free to open any issue or to contact me regarding its performance.



  • Redis


gem install firebase_id_token

or in your Gemfile

gem 'firebase_id_token', '~> 1.3.0'


bundle install


It's needed to set up your Firebase Project ID.

If you are using Rails, this should probably go into config/initializers/firebase_id_token.rb.

FirebaseIdToken.configure do |config|
  config.project_ids = ['your-firebase-project-id']

project_ids must be a Array.

If you want to verify signatures from more than one Firebase project, just add more Project IDs to the list.

You can also pass a Redis instance to config if you are not using Redis defaults.
In this case, you must have the gem redis in your Gemfile.

FirebaseIdToken.configure do |config|
  config.project_ids = ['your-firebase-project-id']
  config.redis = '', port: 6380, db: 15)

Otherwise, it will use just as the instance.


You can get a glimpse of it by reading our RSpec output on your machine. It's really helpful. But here is a complete guide:

Downloading Certificates

Before verifying tokens, you need to download Google's x509 certificates.

To do it simply:


It will download the certificates and save it in Redis, but only if Redis certificates database is empty. To force download and override Redis database, use:


Google give us information about the certificates expiration time, it's used to set a Redis TTL (Time-To-Live) when saving it. By doing so, the certificates will be automatically deleted after its expiration.

Certificates Info

Checks the presence of certificates in Redis database.

=> true

How many seconds until the certificate's expiration.

=> 22352

Lists all certificates in a database.

=> [{"ec8f292sd30224afac5c55540df66d1f999d" => <OpenSSL::X509::Certificate: [...]]

Finds the respective certificate of a given Key ID.

=> <OpenSSL::X509::Certificate: subject=<OpenSSL::X509 [...]>

Downloading in Rails

If you are using Rails, it's clever to download certificates in a cron task, you can use whenever.


Read whenever's guide on how to set it up.

Create your task in lib/tasks/firebase.rake:

namespace :firebase do
  namespace :certificates do
    desc "Request Google's x509 certificates when Redis is empty"
    task request: :environment do

    desc "Request Google's x509 certificates and override Redis"
    task force_request: :environment do

And in your config/schedule.rb you might have:

every 1.hour do
  rake 'firebase:certificates:force_request'


$ whenever --update-crontab

I recommend running it once every hour or every 30 minutes, it's up to you. Normally the certificates expiration time is around 4 to 6 hours, but it's good to perform it in a small fraction of this time.

When developing, you should just run the task:

$ rake firebase:certificates:request

And remember, you need the Redis server to be running.

Verifying Tokens

Pass the Firebase ID Token to FirebaseIdToken::Signature.verify and it will return the token payload if everything is ok:

=> {"iss"=>"", "name"=>"Bob Test", [...]}

When either the signature is false or the token is invalid, it will return nil:

=> nil

=> nil

WARNING: If you try to verify a signature without any certificates in Redis database it will raise a FirebaseIdToken::Exceptions::NoCertificatesError.

Payload Structure

In case you need, here's a example of the payload structure from a Google login in JSON.

   "name":"Ugly Bob",


The gem is available as open source under the terms of the MIT License.