firebase-authentication 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52f63a09db5325c16fef42a13e248799767c1b9378af29a029e4ed5e7532b004
4
- data.tar.gz: da4d219fc4d98dabf25e86ec4944188dc8e45f00bb9182fb2dabd03866db797a
3
+ metadata.gz: 4546fc49b1646e864b9aeed627ed6aa659a276853691dd0e79a2d77300e2cb8c
4
+ data.tar.gz: de8b4059a5eaf651a9f44ae0a655579d72c6aec5c0feff28842883d40350a9ed
5
5
  SHA512:
6
- metadata.gz: 7051a16c7a466845d33617a9cf0b9ea1f9413d66fa0da1eb57d8a574e9d4360838ad4e976484862f9f377fcfdb761047a657236e7e66badc4545ba7b1fbc6c88
7
- data.tar.gz: b4f2ba99ba8758e6e056df2f42787e211e230d25aedde1a76548b852e2ba336416c74bd9ae42e26c0eb92e73243d6b301c5c8fb2d478139e11e68243fc95d3e0
6
+ metadata.gz: fa8e18c14288c4e7c523ff75b86be762444d3f3d59c34704d9c172695d7f2fa4ac7c40c95edda180ff80dacbf3579fcb7a21dab89ed6861cd2bcb3c4e31e686f
7
+ data.tar.gz: 191da01e5bf01b5a2e989603097a9738480f171c96bf823a38503f09cd80d7646b312833153ab82f2083f0c2af7db5627a8b8b044eaae8a8d1fb9505fecb77b6
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Firebase::Authentication
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/firebase/authentication`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A Ruby wrapper for [Firebase Auth REST API](https://firebase.google.com/docs/reference/rest/auth)
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,25 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ First, initialize service client with your Web API Key.<br>
24
+
25
+ ```ruby
26
+ require "firebase/authentication"
27
+ service = Firebase::Authentication::Service.new(ENV['API_KEY'])
28
+ ```
29
+
30
+ Then, call the [method](https://github.com/shuntagami/firebase-authentication/blob/main/lib/firebase/authentication/service.rb) you need like below.<br>
31
+
32
+ ```ruby
33
+ service.sign_up(email, password)
34
+ ```
35
+
36
+ You can use the response like below.<br>
37
+
38
+ ```ruby
39
+ response = service.sign_up(email, password)
40
+ uid = JSON.parse(response.body)['localId'] # The uid of the newly created user.
41
+ ```
26
42
 
27
43
  ## Development
28
44
 
@@ -32,12 +48,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
48
 
33
49
  ## Contributing
34
50
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/firebase-authentication. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/firebase-authentication/blob/main/CODE_OF_CONDUCT.md).
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shuntagami/firebase-authentication. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/shuntagami/firebase-authentication/blob/main/CODE_OF_CONDUCT.md).
36
52
 
37
53
  ## License
38
54
 
39
55
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the Firebase::Authentication project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/firebase-authentication/blob/main/CODE_OF_CONDUCT.md).
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.email = ["shuntagami23@gmail.com"]
8
8
 
9
9
  spec.summary = "Firebase Authentication for Ruby client"
10
- spec.homepage = "https://github.com/shuntagami/firebase_auth_for_ruby"
10
+ spec.homepage = "https://github.com/shuntagami/firebase-authentication"
11
11
  spec.license = "MIT"
12
12
  spec.required_ruby_version = ">= 3.0.0"
13
13
 
@@ -13,6 +13,7 @@ module Firebase
13
13
  SIGN_IN_OAUTH = "signInWithIdp?key="
14
14
  SIGN_UP_EMAIL = "signUp?key="
15
15
  UPDATE_ACCOUNT_INFO = "update?key="
16
+ VERIFY_CUSTOM_TOKEN = "signInWithCustomToken?key="
16
17
  end
17
18
  end
18
19
  end
@@ -6,48 +6,161 @@ require_relative "config"
6
6
 
7
7
  module Firebase
8
8
  module Authentication
9
+ # A Ruby wrapper for Firebase REST API
10
+ #
11
+ # Query the Firebase Auth backend through a REST API
12
+ #
13
+ # @example
14
+ # require "firebase/authentication"
15
+ #
16
+ # service = Firebase::Authentication::Service.new(ENV['API_KEY'])
17
+ # service.sign_up(email, password)
18
+ #
19
+ # @see https://firebase.google.com/docs/reference/rest/auth
9
20
  class Service
10
21
  def initialize(api_key, logger = Rails.logger)
11
22
  @logger = logger
12
23
  @api_key = api_key
13
24
  end
14
25
 
26
+ # Change a user's email.
27
+ # @param [String] token
28
+ # A Firebase Auth ID token for the user.
29
+ # @param [String] email
30
+ # The user's new email.
31
+ #
32
+ # @return [Net::HTTPOK]
33
+ #
34
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
35
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
36
+ # @raise [Net::HTTPFatalError] An internal server error occurred
37
+ #
38
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-change-email
15
39
  def change_email(token, email)
16
40
  res = fetch(:post, Config::UPDATE_ACCOUNT_INFO, { idToken: token, email: email, returnSecureToken: true })
17
41
  res.value
18
42
  res
19
43
  end
20
44
 
45
+ # Change a user's password.
46
+ # @param [String] token
47
+ # A Firebase Auth ID token for the user.
48
+ # @param [String] password
49
+ # The user's new password.
50
+ #
51
+ # @return [Net::HTTPOK]
52
+ #
53
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
54
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
55
+ # @raise [Net::HTTPFatalError] An internal server error occurred
56
+ #
57
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-change-password
21
58
  def change_password(token, password)
22
59
  res = fetch(:post, Config::UPDATE_ACCOUNT_INFO, { idToken: token, passsord: password, returnSecureToken: true })
23
60
  res.value
24
61
  res
25
62
  end
26
63
 
64
+ # Delete a user.
65
+ # @param [String] token
66
+ # The Firebase ID token of the user to delete.
67
+ #
68
+ # @return [Net::HTTPOK]
69
+ #
70
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
71
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
72
+ # @raise [Net::HTTPFatalError] An internal server error occurred
73
+ #
74
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-delete-account
27
75
  def delete_account(token)
28
76
  res = fetch(:post, Config::DELETE_ACCOUNT, { idToken: token })
29
77
  res.value
30
78
  res
31
79
  end
32
80
 
81
+ # Exchange a custom Auth token for an ID and refresh token
82
+ # @param [String] token
83
+ # A Firebase Auth custom token from which to create an ID and refresh token pair.
84
+ #
85
+ # @return [Net::HTTPOK]
86
+ #
87
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
88
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
89
+ # @raise [Net::HTTPFatalError] An internal server error occurred
90
+ #
91
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-verify-custom-token
92
+ def exchange_custom_token(token)
93
+ res = fetch(:post, Config::VERIFY_CUSTOM_TOKEN, { idToken: token, returnSecureToken: true })
94
+ res.value
95
+ res
96
+ end
97
+
98
+ # Get a user's data
99
+ # @param [String] token
100
+ # The Firebase ID token of the account.
101
+ #
102
+ # @return [Net::HTTPOK]
103
+ #
104
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
105
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
106
+ # @raise [Net::HTTPFatalError] An internal server error occurred
107
+ #
108
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-get-account-info
33
109
  def get_account_info(token)
34
110
  res = fetch(:post, Config::GET_ACCOUNT_INFO, { idToken: token })
35
111
  res.value
36
112
  res
37
113
  end
38
114
 
115
+ # Send a password reset email.
116
+ # @param [String] email
117
+ # User's email address.
118
+ #
119
+ # @return [Net::HTTPOK]
120
+ #
121
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
122
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
123
+ # @raise [Net::HTTPFatalError] An internal server error occurred
124
+ #
125
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-send-password-reset-email
39
126
  def send_password_reset_email(email)
40
127
  res = fetch(:post, Config::RESET_PASSWORD, { requestType: "PASSWORD_RESET", email: email })
41
128
  res.value
42
129
  res
43
130
  end
44
131
 
132
+ # Signin a user.
133
+ # @param [String] email
134
+ # The email the user is signing in with.
135
+ # @param [String] password
136
+ # The password for the account.
137
+ #
138
+ # @return [Net::HTTPOK]
139
+ #
140
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
141
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
142
+ # @raise [Net::HTTPFatalError] An internal server error occurred
143
+ #
144
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-sign-in-email-password
45
145
  def sign_in_email(email, password)
46
146
  res = fetch(:post, Config::SIGN_IN_EMAIL, { email: email, passsord: password, returnSecureToken: true })
47
147
  res.value
48
148
  res
49
149
  end
50
150
 
151
+ # Signup new user.
152
+ # @param [String] email
153
+ # The email for the user to create.
154
+ # @param [String] password
155
+ # The password for the user to create.
156
+ #
157
+ # @return [Net::HTTPOK]
158
+ #
159
+ # @raise [Net::HTTPRetriableError] An error occurred on the server and the request can be retried
160
+ # @raise [Net::HTTPServerException] The request is invalid and should not be retried without modification
161
+ # @raise [Net::HTTPFatalError] An internal server error occurred
162
+ #
163
+ # @see https://firebase.google.com/docs/reference/rest/auth#section-create-email-password
51
164
  def sign_up(email, password)
52
165
  res = fetch(:post, Config::SIGN_UP_EMAIL, { email: email, password: password, returnSecureToken: true })
53
166
  res.value
@@ -1,5 +1,5 @@
1
1
  module Firebase
2
2
  module Authentication
3
- VERSION = "0.3.0".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  end
5
5
  end
@@ -34,7 +34,7 @@ module Firebase
34
34
  end
35
35
 
36
36
  def create_custom_token(uid, claims = {})
37
- private_key = OpenSSL::PKey::RSA.new Global.firebase.private_key.gsub('\\n', "\n")
37
+ private_key = OpenSSL::PKey::RSA.new Global.firebase.private_key.gsub("\\n", "\n")
38
38
  service_account_email = Global.firebase.client_email
39
39
  now_seconds = Time.now.to_i
40
40
  payload = { iss: service_account_email,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shuntagami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-07 00:00:00.000000000 Z
11
+ date: 2021-10-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -22,7 +22,6 @@ files:
22
22
  - CHANGELOG.md
23
23
  - CODE_OF_CONDUCT.md
24
24
  - Gemfile
25
- - Gemfile.lock
26
25
  - LICENSE.txt
27
26
  - README.md
28
27
  - Rakefile
@@ -33,7 +32,7 @@ files:
33
32
  - lib/firebase/authentication/config.rb
34
33
  - lib/firebase/authentication/service.rb
35
34
  - lib/firebase/authentication/version.rb
36
- homepage: https://github.com/shuntagami/firebase_auth_for_ruby
35
+ homepage: https://github.com/shuntagami/firebase-authentication
37
36
  licenses:
38
37
  - MIT
39
38
  metadata: {}
data/Gemfile.lock DELETED
@@ -1,188 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- firebase-authentication (0.2.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- actioncable (6.1.4.1)
10
- actionpack (= 6.1.4.1)
11
- activesupport (= 6.1.4.1)
12
- nio4r (~> 2.0)
13
- websocket-driver (>= 0.6.1)
14
- actionmailbox (6.1.4.1)
15
- actionpack (= 6.1.4.1)
16
- activejob (= 6.1.4.1)
17
- activerecord (= 6.1.4.1)
18
- activestorage (= 6.1.4.1)
19
- activesupport (= 6.1.4.1)
20
- mail (>= 2.7.1)
21
- actionmailer (6.1.4.1)
22
- actionpack (= 6.1.4.1)
23
- actionview (= 6.1.4.1)
24
- activejob (= 6.1.4.1)
25
- activesupport (= 6.1.4.1)
26
- mail (~> 2.5, >= 2.5.4)
27
- rails-dom-testing (~> 2.0)
28
- actionpack (6.1.4.1)
29
- actionview (= 6.1.4.1)
30
- activesupport (= 6.1.4.1)
31
- rack (~> 2.0, >= 2.0.9)
32
- rack-test (>= 0.6.3)
33
- rails-dom-testing (~> 2.0)
34
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
- actiontext (6.1.4.1)
36
- actionpack (= 6.1.4.1)
37
- activerecord (= 6.1.4.1)
38
- activestorage (= 6.1.4.1)
39
- activesupport (= 6.1.4.1)
40
- nokogiri (>= 1.8.5)
41
- actionview (6.1.4.1)
42
- activesupport (= 6.1.4.1)
43
- builder (~> 3.1)
44
- erubi (~> 1.4)
45
- rails-dom-testing (~> 2.0)
46
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
- activejob (6.1.4.1)
48
- activesupport (= 6.1.4.1)
49
- globalid (>= 0.3.6)
50
- activemodel (6.1.4.1)
51
- activesupport (= 6.1.4.1)
52
- activerecord (6.1.4.1)
53
- activemodel (= 6.1.4.1)
54
- activesupport (= 6.1.4.1)
55
- activestorage (6.1.4.1)
56
- actionpack (= 6.1.4.1)
57
- activejob (= 6.1.4.1)
58
- activerecord (= 6.1.4.1)
59
- activesupport (= 6.1.4.1)
60
- marcel (~> 1.0.0)
61
- mini_mime (>= 1.1.0)
62
- activesupport (6.1.4.1)
63
- concurrent-ruby (~> 1.0, >= 1.0.2)
64
- i18n (>= 1.6, < 2)
65
- minitest (>= 5.1)
66
- tzinfo (~> 2.0)
67
- zeitwerk (~> 2.3)
68
- ast (2.4.2)
69
- builder (3.2.4)
70
- concurrent-ruby (1.1.9)
71
- crass (1.0.6)
72
- diff-lcs (1.4.4)
73
- dotenv (2.7.6)
74
- dotenv-rails (2.7.6)
75
- dotenv (= 2.7.6)
76
- railties (>= 3.2)
77
- erubi (1.10.0)
78
- globalid (0.5.2)
79
- activesupport (>= 5.0)
80
- i18n (1.8.10)
81
- concurrent-ruby (~> 1.0)
82
- jwt (2.2.3)
83
- loofah (2.12.0)
84
- crass (~> 1.0.2)
85
- nokogiri (>= 1.5.9)
86
- mail (2.7.1)
87
- mini_mime (>= 0.1.1)
88
- marcel (1.0.2)
89
- method_source (1.0.0)
90
- mini_mime (1.1.1)
91
- mini_portile2 (2.6.1)
92
- minitest (5.14.4)
93
- nio4r (2.5.8)
94
- nokogiri (1.12.5)
95
- mini_portile2 (~> 2.6.1)
96
- racc (~> 1.4)
97
- parallel (1.21.0)
98
- parser (3.0.2.0)
99
- ast (~> 2.4.1)
100
- racc (1.5.2)
101
- rack (2.2.3)
102
- rack-test (1.1.0)
103
- rack (>= 1.0, < 3)
104
- rails (6.1.4.1)
105
- actioncable (= 6.1.4.1)
106
- actionmailbox (= 6.1.4.1)
107
- actionmailer (= 6.1.4.1)
108
- actionpack (= 6.1.4.1)
109
- actiontext (= 6.1.4.1)
110
- actionview (= 6.1.4.1)
111
- activejob (= 6.1.4.1)
112
- activemodel (= 6.1.4.1)
113
- activerecord (= 6.1.4.1)
114
- activestorage (= 6.1.4.1)
115
- activesupport (= 6.1.4.1)
116
- bundler (>= 1.15.0)
117
- railties (= 6.1.4.1)
118
- sprockets-rails (>= 2.0.0)
119
- rails-dom-testing (2.0.3)
120
- activesupport (>= 4.2.0)
121
- nokogiri (>= 1.6)
122
- rails-html-sanitizer (1.4.2)
123
- loofah (~> 2.3)
124
- railties (6.1.4.1)
125
- actionpack (= 6.1.4.1)
126
- activesupport (= 6.1.4.1)
127
- method_source
128
- rake (>= 0.13)
129
- thor (~> 1.0)
130
- rainbow (3.0.0)
131
- rake (13.0.6)
132
- regexp_parser (2.1.1)
133
- rexml (3.2.5)
134
- rspec (3.10.0)
135
- rspec-core (~> 3.10.0)
136
- rspec-expectations (~> 3.10.0)
137
- rspec-mocks (~> 3.10.0)
138
- rspec-core (3.10.1)
139
- rspec-support (~> 3.10.0)
140
- rspec-expectations (3.10.1)
141
- diff-lcs (>= 1.2.0, < 2.0)
142
- rspec-support (~> 3.10.0)
143
- rspec-mocks (3.10.2)
144
- diff-lcs (>= 1.2.0, < 2.0)
145
- rspec-support (~> 3.10.0)
146
- rspec-support (3.10.2)
147
- rubocop (1.22.0)
148
- parallel (~> 1.10)
149
- parser (>= 3.0.0.0)
150
- rainbow (>= 2.2.2, < 4.0)
151
- regexp_parser (>= 1.8, < 3.0)
152
- rexml
153
- rubocop-ast (>= 1.12.0, < 2.0)
154
- ruby-progressbar (~> 1.7)
155
- unicode-display_width (>= 1.4.0, < 3.0)
156
- rubocop-ast (1.12.0)
157
- parser (>= 3.0.1.1)
158
- ruby-progressbar (1.11.0)
159
- sprockets (4.0.2)
160
- concurrent-ruby (~> 1.0)
161
- rack (> 1, < 3)
162
- sprockets-rails (3.2.2)
163
- actionpack (>= 4.0)
164
- activesupport (>= 4.0)
165
- sprockets (>= 3.0.0)
166
- thor (1.1.0)
167
- tzinfo (2.0.4)
168
- concurrent-ruby (~> 1.0)
169
- unicode-display_width (2.1.0)
170
- websocket-driver (0.7.5)
171
- websocket-extensions (>= 0.1.0)
172
- websocket-extensions (0.1.5)
173
- zeitwerk (2.4.2)
174
-
175
- PLATFORMS
176
- ruby
177
-
178
- DEPENDENCIES
179
- dotenv-rails
180
- firebase-authentication!
181
- jwt
182
- rails (~> 6.1.4)
183
- rake
184
- rspec
185
- rubocop
186
-
187
- BUNDLED WITH
188
- 2.2.28