ibrain-auth 0.2.8 → 0.2.9

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: 9d95d7f9c6c700644ad0e46cf5cabe23f2c41e3892272de755ffda41b13d0c8a
4
- data.tar.gz: c75cb28a6655d0320ab3a3a0988817afdf7fda37bc37174ef291cd4d5437d6ad
3
+ metadata.gz: f763692f6d5b704c1b30c50a104d61283df33633e4009f6cb39ec4d25113f893
4
+ data.tar.gz: 475275e8117238e9ff17b84917a8611a55d58e2da974d49d9dee0f24316a2d2c
5
5
  SHA512:
6
- metadata.gz: e24aa639225bed4349fd89989fda23cbc80096b5f9b691b3733e45c9c2ba7160eeb7996a0adb27a27a3f5305c4634ce8a77c904e0d814d30830a3754299cbb47
7
- data.tar.gz: 1d3d0ac22092f3d436803230a8a9d49b166349a774746112017b6f91bbc976ae77c5b10dbeca7bd687c70ab15550ba2c418584dc00d12cf5fb90ff088e56ffba
6
+ metadata.gz: df00d71b19ba24ad523dbb7af3c29b63ac634376892b2ae3f098fbc1cd5b3924d6efcd8e992f91c5c83c7ce555e69ad3e54fba698360f5d0aaf38d522a744049
7
+ data.tar.gz: 19f4f1662d54348a57d9525cd3d03a757e82f467b2556e59cb7752df81e88a48fb638872f4b0a1dbff6579546b6e13f300e0e9619fb37854acd824a4787a417c
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain::Auth::Mutations
4
+ class GenerateFirebaseTokenMutation < BaseMutation
5
+ field :result, Boolean, null: true
6
+ field :token, String, null: true
7
+
8
+ argument :attributes, ::Ibrain::Auth::Types::Input::GenerateFirebaseTokenInput, required: true
9
+
10
+ def resolve(_args)
11
+ token = repo.generate_custom_token!
12
+
13
+ graphql_returning(token)
14
+ end
15
+
16
+ private
17
+
18
+ def normalize_parameters
19
+ attribute_params.permit(:uid)
20
+ rescue StandardError
21
+ ActionController::Parameters.new({})
22
+ end
23
+
24
+ def repo
25
+ ::FirebaseRepository.new(nil, normalize_parameters)
26
+ end
27
+
28
+ def graphql_returning(token)
29
+ OpenStruct.new(
30
+ token: token,
31
+ result: true
32
+ )
33
+ end
34
+ end
35
+ end
@@ -2,8 +2,7 @@
2
2
 
3
3
  module Ibrain::Auth::Mutations
4
4
  class SignUpMutation < BaseMutation
5
- field :user, Types::Objects::UserType, null: true
6
- field :token, String, null: true
5
+ field :is_verified, Boolean, null: true
7
6
  field :result, Boolean, null: true
8
7
 
9
8
  argument :attributes, Ibrain::Auth::Config.sign_up_input, required: true
@@ -29,13 +28,7 @@ module Ibrain::Auth::Mutations
29
28
  end
30
29
 
31
30
  context[:current_user] = current_user
32
-
33
- graphql_returning(
34
- user_signed_in?,
35
- true,
36
- user_signed_in? ? current_user : nil,
37
- current_user.try(:jwt_token),
38
- )
31
+ graphql_returning
39
32
  end
40
33
 
41
34
  private
@@ -58,12 +51,10 @@ module Ibrain::Auth::Mutations
58
51
  { scope: resource_name }
59
52
  end
60
53
 
61
- def graphql_returning(result, is_verified, user = nil, token = nil)
54
+ def graphql_returning
62
55
  OpenStruct.new(
63
- user: user,
64
- token: token,
65
- result: result,
66
- is_verified: is_verified
56
+ result: current_user.present?,
57
+ is_verified: false
67
58
  )
68
59
  end
69
60
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Auth
5
+ module Types
6
+ module Input
7
+ class GenerateFirebaseTokenInput < Ibrain::Types::BaseInputObject
8
+ argument :uid, String, required: true
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FirebaseRepository < Ibrain::BaseRepository
4
+ def initialize(record, _params)
5
+ super(nil, record)
6
+
7
+ @private_key_json = File.open(Ibrain::Auth::Config.firebase_private_key_path).read
8
+ @firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
9
+ end
10
+
11
+ def generate_custom_token!
12
+ now = Time.now.to_i
13
+
14
+ payload = {
15
+ iss: firebase_owner_email,
16
+ sub: firebase_owner_email,
17
+ aud: Ibrain::Auth::Config.firebase_aud_url,
18
+ iat: now,
19
+ exp: now + 3600,
20
+ uid: params[:uid],
21
+ claims: {}
22
+ }
23
+
24
+ JWT.encode payload, private_key, "RS256"
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :private_key_json, :firebase_owner_email
30
+
31
+ def method_name
32
+ end
33
+
34
+ def json_firebase
35
+ JSON.parse(private_key_json, symbolize_names: true)
36
+ end
37
+
38
+ def private_key
39
+ OpenSSL::PKey::RSA.new json_firebase[:private_key]
40
+ end
41
+ end
@@ -16,4 +16,13 @@ Ibrain::Auth.config do |config|
16
16
 
17
17
  # sign_in graphql input
18
18
  config.sign_up_input = Ibrain::Auth::Types::Input::SignInInput
19
+
20
+ # firebase private json path
21
+ config.firebase_private_key_path = Rails.root.join('static/firebase.json')
22
+
23
+ # firebase aud url
24
+ config.firebase_auth_url = "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
25
+
26
+ # firebase owner email
27
+ config.firebase_owner_email = nil
19
28
  end
@@ -4,14 +4,14 @@ module Ibrain
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Auth
7
- VERSION = '0.2.8'
7
+ VERSION = '0.2.9'
8
8
 
9
9
  def self.ibrain_auth_version
10
10
  VERSION
11
11
  end
12
12
 
13
13
  def self.previous_ibrain_auth_minor_version
14
- '0.2.7'
14
+ '0.2.8'
15
15
  end
16
16
 
17
17
  def self.ibrain_auth_gem_version
@@ -17,5 +17,14 @@ module Ibrain
17
17
 
18
18
  # sign_in input
19
19
  preference :sign_in_input, :class, default: Ibrain::Auth::Types::Input::SignInInput
20
+
21
+ # firebase private json path
22
+ preference :firebase_private_key_path, :string, default: Rails.root.join('static/firebase.json')
23
+
24
+ # firebase aud url
25
+ preference :firebase_auth_url, :string, default: "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit"
26
+
27
+ # firebase owner email
28
+ preference :firebase_owner_email, :string, default: nil
20
29
  end
21
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibrain-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
@@ -194,15 +194,18 @@ files:
194
194
  - app/controllers/ibrain/auth/sessions_controller.rb
195
195
  - app/controllers/ibrain/auth/unlocks_controller.rb
196
196
  - app/graphql/ibrain/auth/mutations/base_mutation.rb
197
+ - app/graphql/ibrain/auth/mutations/generate_firebase_token_mutation.rb
197
198
  - app/graphql/ibrain/auth/mutations/sign_in_mutation.rb
198
199
  - app/graphql/ibrain/auth/mutations/sign_out_mutation.rb
199
200
  - app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
200
201
  - app/graphql/ibrain/auth/mutations/social_sign_in_mutation.rb
202
+ - app/graphql/ibrain/auth/types/input/generate_firebase_token_input.rb
201
203
  - app/graphql/ibrain/auth/types/input/sign_in_input.rb
202
204
  - app/graphql/ibrain/auth/types/input/sign_up_input.rb
203
205
  - app/models/ibrain/auth/user.rb
204
206
  - app/repositories/apple_repository.rb
205
207
  - app/repositories/auth_repository.rb
208
+ - app/repositories/firebase_repository.rb
206
209
  - app/repositories/twitter_repository.rb
207
210
  - config/initializers/devise.rb
208
211
  - config/locales/en.yml