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 +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +26 -0
- data/lib/firebase_token_auth/admin_client.rb +14 -1
- data/lib/firebase_token_auth/client.rb +4 -0
- data/lib/firebase_token_auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0df8895c93fb21c8dfc899c0b626057b41becbf3b4af70a9dbf286938644ee44
|
4
|
+
data.tar.gz: d8dbb7afac6ffad4e028e00f7981b5f2408690b23dcf2c64be838cc2fb4828cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 432891f9eef84e16d0c8f1d8736f8cd44a0732b87b623bb6e2e0064e7c23aa69ac25a8f6031697360d6b60b99a3545caaee0ea55a29161dc2a0f8ce8024f89c7
|
7
|
+
data.tar.gz: 868b4f40be681e90beabee2ccc86eb213623ef8b0f0ac2136d3e6adb546d30814f1d30ba53f0b231cc1d75795726430160a20ff7a5bcb8ac390f6d16e523e40c
|
data/.rubocop.yml
CHANGED
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
|
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.
|
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-
|
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
|