firebase_token_auth 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dff32ef2301d4eb08f46ac3bd840f4c3e9adf5cd7f37c59c79d53b0dfbccdf1b
4
- data.tar.gz: 5102df68ce6e5f516d044c4af295c92030a50fa226fd510cac996e72a36553f8
3
+ metadata.gz: 0df8895c93fb21c8dfc899c0b626057b41becbf3b4af70a9dbf286938644ee44
4
+ data.tar.gz: d8dbb7afac6ffad4e028e00f7981b5f2408690b23dcf2c64be838cc2fb4828cb
5
5
  SHA512:
6
- metadata.gz: f659ddb2edf477b495a2be519cef6c96b5c083737521c60016a80bfa28264a67b4a8a054d12b1be929d1e0dc56ab033a504451efb36887bbb2770a2be0700707
7
- data.tar.gz: 6d15331ff417a6fc5d1c45ebfbb44e830ea95aebf3535b6930bb61f045322fc55c79be42975ae8003c0f264985ba0506d00b981c89a395a16a50f1c2333318fb
6
+ metadata.gz: 432891f9eef84e16d0c8f1d8736f8cd44a0732b87b623bb6e2e0064e7c23aa69ac25a8f6031697360d6b60b99a3545caaee0ea55a29161dc2a0f8ce8024f89c7
7
+ data.tar.gz: 868b4f40be681e90beabee2ccc86eb213623ef8b0f0ac2136d3e6adb546d30814f1d30ba53f0b231cc1d75795726430160a20ff7a5bcb8ac390f6d16e523e40c
@@ -9,3 +9,6 @@ Style/Documentation:
9
9
 
10
10
  Layout/IndentationConsistency:
11
11
  EnforcedStyle: indented_internal_methods
12
+
13
+ Style/BracesAroundHashParameters:
14
+ EnforcedStyle: braces
data/README.md CHANGED
@@ -4,6 +4,7 @@ FirebaseTokenAuth is an Firebase Auth Client. It supports below.
4
4
  - verify id_token method
5
5
  - create custom token
6
6
  - fetch user info by uid/email
7
+ - update user info
7
8
 
8
9
  ## Installation
9
10
 
@@ -120,6 +121,31 @@ puts result
120
121
  # :valid_since=>1594132097}]
121
122
  ```
122
123
 
124
+ ### update user info
125
+ ```ruby
126
+ require 'firebase_token_auth'
127
+
128
+ FirebaseTokenAuth.configure do |config|
129
+ config.project_id = 'your_project_id'
130
+ config.json_key_io = "#{Rails.root}/path/to/service_account_credentials.json"
131
+ end
132
+
133
+ client = FirebaseTokenAuth.new
134
+ # NOTE: parameter_name is snake_case
135
+ update_params = { # ref. https://firebase.google.com/docs/reference/rest/auth#section-update-profile
136
+ display_name: 'updated_name',
137
+ }
138
+ result = client.update_user(test_uid, update_params)
139
+ puts result
140
+ # => {:display_name=>"updated_name",
141
+ # :email=>"<your_user_email>",
142
+ # :email_verified=>false,
143
+ # :kind=>"identitytoolkit#SetAccountInfoResponse",
144
+ # :local_id=>"hMPHt8RyDpOsHi1oH5XaVirSYyq2",
145
+ # :password_hash=>"REDACTED",
146
+ # :provider_user_info=>[{:display_name=>"updated_name", :federated_id=>"<your_user_email>", :provider_id=>"password"}]}
147
+ ```
148
+
123
149
  ## Contributing
124
150
 
125
151
  Bug reports and pull requests are welcome on GitHub at https://github.com/miyataka/firebase_token_auth.
@@ -10,8 +10,21 @@ module FirebaseTokenAuth
10
10
  end
11
11
 
12
12
  def get_account_info(params)
13
- request = Google::Apis::IdentitytoolkitV3::GetAccountInfoRequest.new(**params)
13
+ request = Google::Apis::IdentitytoolkitV3::GetAccountInfoRequest.new({ **params })
14
14
  service.get_account_info(request)
15
15
  end
16
+
17
+ def update_existing_account(uid, attributes)
18
+ update_params = { local_id: uid }.merge!(permit_attributes(attributes))
19
+ request = Google::Apis::IdentitytoolkitV3::SetAccountInfoRequest.new(update_params)
20
+ service.set_account_info(request)
21
+ end
22
+
23
+ private
24
+
25
+ def permit_attributes(attr_hash)
26
+ permit_keys = %i[disabled display_name email email_verified password phone_number photo_url multi_factor]
27
+ attr_hash.filter { |k, _v| permit_keys.include?(k) }
28
+ end
16
29
  end
17
30
  end
@@ -58,6 +58,10 @@ module FirebaseTokenAuth
58
58
  admin_client.get_account_info({ local_id: [uid] })&.users&.map(&:to_h)
59
59
  end
60
60
 
61
+ def update_user(uid, attribute_hash)
62
+ admin_client.update_existing_account(uid, attribute_hash).to_h
63
+ end
64
+
61
65
  private
62
66
 
63
67
  def admin_client
@@ -1,3 +1,3 @@
1
1
  module FirebaseTokenAuth
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase_token_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - miyataka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client