firebase-authentication 0.1.0 → 0.2.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: 5e0734c4d4de2a3db40acc756dc0b05d5cae84ed060574987fcbb5d05feabedb
4
- data.tar.gz: 835f0c33b6854c8876c5bcbfa6ee72ce144a951880304513ccb501c7b29c23dd
3
+ metadata.gz: 26d45db46a0e99567b9f9b67c0eb991327cc99a4dc58ff978161b8f293620885
4
+ data.tar.gz: 6396f770c206014c435df545bde268e2f9199d1fb6a3388d8496828be0cb7d7e
5
5
  SHA512:
6
- metadata.gz: 71ec9fbb54798597c9e1dcd680e65e5cdc4436da7a2b9e42a3f742eeb49ddde1315f92358a18b5651fd9ff9b9157ba8a270137c4f6eaa3be47bf134b286f65f0
7
- data.tar.gz: b914ca7a7b8f3518fbebd60edbdf1522c5aec1a903f1567c6ccae06ebe599890112d5a183b4501ed9485b2403a7218016d61627e5d39cae88168050ae61244e6
6
+ metadata.gz: 51b81400b334dbdc648bf76d3e2bb1ddbedd2d694d98b8fa7b99af2001e3c82318edb7798f0557c85bd51a82a33189432b72ddb2c56555ee7bc95402e97ddd42
7
+ data.tar.gz: '042855574e77b4a107a3fd03020502b6846e1e5d9b76052a657fbc0bf3a99b045376ff0d3bce726b2ecacd263aadd05484daa7c1129fc3b8e232ea3d7282c9a1'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Firebase
4
+ module Authentication
5
+ module Config
6
+ BASE_URI = "https://identitytoolkit.googleapis.com/v1/accounts:"
7
+
8
+ GET_ACCOUNT_INFO = "lookup?key="
9
+ DELETE_ACCOUNT = "delete?key="
10
+ FETCH_PROVIDERS_FOR_EMAIL = "createAuthUri?key="
11
+ RESET_PASSWORD = "sendOobCode?key="
12
+ SIGN_IN_EMAIL = "signInWithPassword?key="
13
+ SIGN_IN_OAUTH = "signInWithIdp?key="
14
+ SIGN_UP_EMAIL = "signUp?key="
15
+ UPDATE_ACCOUNT_INFO = "update?key="
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,75 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "rails"
4
+ require "uri"
5
+ require_relative "config"
6
+
7
+ module Firebase
8
+ module Authentication
9
+ class Service
10
+ def initialize(api_key, logger = Rails.logger)
11
+ @logger = logger
12
+ @api_key = api_key
13
+ end
14
+
15
+ def change_email(token, email)
16
+ res = fetch(:post, Config::UPDATE_ACCOUNT_INFO, { idToken: token, email: email, returnSecureToken: true })
17
+ res.value
18
+ res
19
+ end
20
+
21
+ def change_password(token, password)
22
+ res = fetch(:post, Config::UPDATE_ACCOUNT_INFO, { idToken: token, passsord: password, returnSecureToken: true })
23
+ res.value
24
+ res
25
+ end
26
+
27
+ def delete_account(token)
28
+ res = fetch(:post, Config::DELETE_ACCOUNT, { idToken: token })
29
+ res.value
30
+ res
31
+ end
32
+
33
+ def get_account_info(token)
34
+ res = fetch(:post, Config::GET_ACCOUNT_INFO, { idToken: token })
35
+ res.value
36
+ res
37
+ end
38
+
39
+ def send_password_reset_email(email)
40
+ res = fetch(:post, Config::RESET_PASSWORD, { requestType: "PASSWORD_RESET", email: email })
41
+ res.value
42
+ res
43
+ end
44
+
45
+ def sign_in_email(email, password)
46
+ res = fetch(:post, Config::SIGN_IN_EMAIL, { email: email, passsord: password, returnSecureToken: true })
47
+ res.value
48
+ res
49
+ end
50
+
51
+ def sign_up(email, password)
52
+ res = fetch(:post, Config::SIGN_UP_EMAIL, { email: email, password: password, returnSecureToken: true })
53
+ res.value
54
+ res
55
+ end
56
+
57
+ private
58
+
59
+ def fetch(verb, path, body = nil)
60
+ uri = URI.parse(Config::BASE_URI + path + @api_key)
61
+ request = case verb
62
+ when :get
63
+ Net::HTTP::Get.new(uri)
64
+ when :post
65
+ Net::HTTP::Post.new(uri)
66
+ end
67
+ request.content_type = "application/json"
68
+ request.body = JSON.dump(body)
69
+ Net::HTTP.start(uri.host, uri.port, { use_ssl: true }) do |http|
70
+ http.request(request)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
1
  module Firebase
2
2
  module Authentication
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
@@ -1,4 +1,6 @@
1
1
  require_relative "authentication/version"
2
+ require_relative "authentication/config"
3
+ require_relative "authentication/service"
2
4
 
3
5
  module Firebase
4
6
  module Authentication
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-authentication
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shuntagami
@@ -30,6 +30,8 @@ files:
30
30
  - bin/setup
31
31
  - firebase-authentication.gemspec
32
32
  - lib/firebase/authentication.rb
33
+ - lib/firebase/authentication/config.rb
34
+ - lib/firebase/authentication/service.rb
33
35
  - lib/firebase/authentication/version.rb
34
36
  homepage: https://github.com/shuntagami/firebase_auth_for_ruby
35
37
  licenses: