FirebaseTokenAuth
FirebaseTokenAuth is an Firebase Auth Client. It supports below.
- verify id_token method
- create custom token
- fetch user info by uid/email
- update user info
Installation
Add this line to your application's Gemfile:
gem 'firebase_token_auth'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install firebase_token_auth
Usage
on Rails, config/initializers/firebase_token_auth.rb
FirebaseTokenAuth.configure do |config|
config.project_id = "your_project_id"
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
end
for more detail. see here.
token verify
require 'firebase_token_auth'
FirebaseTokenAuth.configure do |config|
config.project_id = 'your_project_id'
end
client = FirebaseTokenAuth.build
result = client.verify_id_token(id_token)
puts result.uid
puts result.id_token.payload
puts result.id_token.header
custom token create
require 'firebase_token_auth'
FirebaseTokenAuth.configure do |config|
config.project_id = 'your_project_id'
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
end
client = FirebaseTokenAuth.new
c_token = client.create_custom_token(test_uid)
puts c_token
verify custom token
require 'firebase_token_auth'
FirebaseTokenAuth.configure do |config|
config.project_id = 'your_project_id'
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
end
client = FirebaseTokenAuth.build
result = client.verify_custom_token(custom_token)
puts result
fetch users info from firebase
require 'firebase_token_auth'
FirebaseTokenAuth.configure do |config|
config.project_id = 'your_project_id'
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
end
client = FirebaseTokenAuth.new
result = client.user_search_by_email(test_user_email)
puts result
update user info
require 'firebase_token_auth'
FirebaseTokenAuth.configure do |config|
config.project_id = 'your_project_id'
config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
end
client = FirebaseTokenAuth.new
update_params = {
display_name: 'updated_name',
}
result = client.update_user(test_uid, update_params)
puts result
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/miyataka/firebase_token_auth.
License
The gem is available as open source under the terms of the MIT License.