From 0cc8c0ed402f880da86947b49dd43a060229462b Mon Sep 17 00:00:00 2001 From: Andrew Buzzell Date: Wed, 24 Nov 2021 12:27:47 -0400 Subject: [PATCH 1/3] adding method to delete account --- lib/firebase_token_auth/admin_client.rb | 6 ++++++ lib/firebase_token_auth/client.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/firebase_token_auth/admin_client.rb b/lib/firebase_token_auth/admin_client.rb index 879f5d8..f0f42bd 100644 --- a/lib/firebase_token_auth/admin_client.rb +++ b/lib/firebase_token_auth/admin_client.rb @@ -20,6 +20,12 @@ def update_existing_account(uid, attributes) service.set_account_info(request) end + def delete_existing_account(uid) + update_params = { local_id: uid } + request = Google::Apis::IdentitytoolkitV3::DeleteAccountRequest.new(**update_params) + service.delete_account(request) + end + private def permit_attributes(attr_hash) diff --git a/lib/firebase_token_auth/client.rb b/lib/firebase_token_auth/client.rb index 4f9b330..2f87bd5 100644 --- a/lib/firebase_token_auth/client.rb +++ b/lib/firebase_token_auth/client.rb @@ -63,6 +63,10 @@ def update_user(uid, attribute_hash) admin_client.update_existing_account(uid, attribute_hash).to_h end + def delete_user(uid) + admin_client.delete_existing_account(uid).to_h + end + private def admin_client From 133ffbfe8c6e1e13a5e357392ee24ebbac34bfcd Mon Sep 17 00:00:00 2001 From: Andrew Buzzell Date: Thu, 25 Nov 2021 10:01:24 -0400 Subject: [PATCH 2/3] add method to create user --- lib/firebase_token_auth/admin_client.rb | 6 ++++++ lib/firebase_token_auth/client.rb | 4 ++++ lib/firebase_token_auth/version.rb | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/firebase_token_auth/admin_client.rb b/lib/firebase_token_auth/admin_client.rb index f0f42bd..740babd 100644 --- a/lib/firebase_token_auth/admin_client.rb +++ b/lib/firebase_token_auth/admin_client.rb @@ -20,6 +20,12 @@ def update_existing_account(uid, attributes) service.set_account_info(request) end + def create_account(email, password, attributes) + params = { email: email, password: password}.merge!(permit_attributes(attributes)) + request = Google::Apis::IdentitytoolkitV3::SignupNewUserRequest.new(**params) + service.signup_new_user(request) + end + def delete_existing_account(uid) update_params = { local_id: uid } request = Google::Apis::IdentitytoolkitV3::DeleteAccountRequest.new(**update_params) diff --git a/lib/firebase_token_auth/client.rb b/lib/firebase_token_auth/client.rb index 2f87bd5..1c93bb6 100644 --- a/lib/firebase_token_auth/client.rb +++ b/lib/firebase_token_auth/client.rb @@ -55,6 +55,10 @@ def user_search_by_email(email) admin_client.get_account_info({ email: [email] })&.users&.map(&:to_h) end + def signup_user(email, password, attribute_hash) + admin_client.create_account(email, password, attribute_hash).to_h + end + def user_search_by_uid(uid) admin_client.get_account_info({ local_id: [uid] })&.users&.map(&:to_h) end diff --git a/lib/firebase_token_auth/version.rb b/lib/firebase_token_auth/version.rb index 593ebcb..58cc52b 100644 --- a/lib/firebase_token_auth/version.rb +++ b/lib/firebase_token_auth/version.rb @@ -1,3 +1,3 @@ module FirebaseTokenAuth - VERSION = '1.3.0'.freeze + VERSION = '1.3.1'.freeze end From 2ee8afb1ff5a6240de7e4bc876f5fa0f149e1df4 Mon Sep 17 00:00:00 2001 From: abuzzell Date: Tue, 30 Nov 2021 15:42:45 +0000 Subject: [PATCH 3/3] attribute hash should be optional --- lib/firebase_token_auth/client.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/firebase_token_auth/client.rb b/lib/firebase_token_auth/client.rb index 1c93bb6..b999349 100644 --- a/lib/firebase_token_auth/client.rb +++ b/lib/firebase_token_auth/client.rb @@ -55,7 +55,7 @@ def user_search_by_email(email) admin_client.get_account_info({ email: [email] })&.users&.map(&:to_h) end - def signup_user(email, password, attribute_hash) + def signup_user(email, password, attribute_hash = {}) admin_client.create_account(email, password, attribute_hash).to_h end