I have a Rails App where I need to authenticate firebase users on the server-side, not just in JavaScript.
I found these instructions from google: https://firebase.google.com/docs/auth/admin/verify-id-tokens
Unfortunately, it appears Google does not have support for Ruby. So, I made my own auth file!
gem install firebase-token-verify
Add gem 'firebase-token-verify'
to your Gemfile and run bundle install
- Lookup your firebase id and add it to your Ruby code, for example:
PROJECT_ID = <your_firebase_project_id>
- Obtain a user token. You will need to be connected with JavaScript, or a mobile app, to obtain the user token. I usually obtain a user token using a JavaScript method similar to the one below:
user.getIdToken(true).then(token => {
// Send this token to your Ruby application
})
- Setup some Ruby code to process the token
require 'firebase_ruby_auth'
PROJECT_ID = ENV['<your_firebase_project_id>']
FirebaseRubyAuth.new(PROJECT_ID).decode_token(token)