ibrain-auth 0.2.5 → 0.2.6
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 +4 -4
- data/app/graphql/ibrain/auth/mutations/{sso_sign_in_mutation.rb → social_sign_in_mutation.rb} +2 -2
- data/app/models/ibrain/auth/user.rb +7 -0
- data/app/repositories/auth_repository.rb +15 -5
- data/lib/ibrain/auth/version.rb +2 -2
- metadata +4 -5
- data/app/graphql/ibrain/auth/mutations/sso_sign_up_mutation.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f6effd595af545581f20acbc9fd7c50c8758fdf471075a001c96cc2d6741490
|
4
|
+
data.tar.gz: 7171e0aa32520f98085c44baad66941dc5a74efecf28275dc52be6aadb2c8b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 838a3e121f20c914e33118a04e68017f4927a4107d7863d7b9b69e817bab43352742ccc98ed4fb22e0ee72a5282ae38243c4349aa986e11ad0bb62f33cc8394a
|
7
|
+
data.tar.gz: 39e411cf62805c44c6376bcc8152ec26121a03601e94ac444f4370059e77f7a4213965c1d3c754e83a7c9b69617b1b83030f6c269ae57350f7c0698a038483e2
|
data/app/graphql/ibrain/auth/mutations/{sso_sign_in_mutation.rb → social_sign_in_mutation.rb}
RENAMED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Ibrain::Auth::Mutations
|
4
|
-
class
|
4
|
+
class SocialSignInMutation < BaseMutation
|
5
5
|
field :user, Types::Objects::UserType, null: true
|
6
6
|
field :token, String, null: true
|
7
7
|
field :result, Boolean, null: true
|
8
8
|
field :is_verified, Boolean, null: true
|
9
9
|
|
10
|
-
argument :id_token, String, description: 'Id Token from
|
10
|
+
argument :id_token, String, description: 'Id Token from firebase', required: true
|
11
11
|
argument :device_token, String, description: 'Device token for notificaiton', required: false
|
12
12
|
|
13
13
|
def resolve(args)
|
@@ -11,7 +11,7 @@ class AuthRepository < Ibrain::BaseRepository
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create
|
14
|
-
user =
|
14
|
+
user = is_social? ? firebase_verify : collection.ibrain_find(manual_params, available_columns)
|
15
15
|
user.assign_attributes(normalize_params.except(:id_token))
|
16
16
|
user.save
|
17
17
|
|
@@ -19,7 +19,7 @@ class AuthRepository < Ibrain::BaseRepository
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def sign_in
|
22
|
-
return
|
22
|
+
return firebase_verify if is_social?
|
23
23
|
|
24
24
|
user = collection.ibrain_find(manual_params, available_columns)
|
25
25
|
return unless user.try(:valid_password?, manual_params[:password])
|
@@ -57,21 +57,31 @@ class AuthRepository < Ibrain::BaseRepository
|
|
57
57
|
params.permit(:username, :password)
|
58
58
|
end
|
59
59
|
|
60
|
-
def
|
60
|
+
def firebase_verify
|
61
61
|
response = HTTParty.post(firebase_url, headers: base_headers, body: { 'idToken' => normalize_params[:id_token] }.to_json )
|
62
62
|
user_information = response.try(:fetch, 'users', []).try(:at, 0)
|
63
63
|
|
64
64
|
uid = user_information.try(:fetch, 'localId', nil)
|
65
|
+
provider = user_information.
|
66
|
+
try(:fetch, 'providerUserInfo', []).
|
67
|
+
try(:at, 0).try(:fetch, 'providerId', '').
|
68
|
+
try(:gsub, '.com', '')
|
65
69
|
raise ActiveRecord::RecordNotFound, I18n.t('ibrain.errors.account.not_found') if uid.blank?
|
66
70
|
|
67
|
-
collection.
|
71
|
+
collection.social_find_or_initialize({
|
72
|
+
uid: uid,
|
73
|
+
provider: provider,
|
74
|
+
remote_avatar_url: user_information.try(:fetch, 'photoUrl', nil),
|
75
|
+
email: user_information.try(:fetch, 'email', nil),
|
76
|
+
password: 'Eco@123456'
|
77
|
+
})
|
68
78
|
end
|
69
79
|
|
70
80
|
def available_columns
|
71
81
|
collection.column_names.select { |f| ACCOUNT_COUMNS.include?(f) }
|
72
82
|
end
|
73
83
|
|
74
|
-
def
|
84
|
+
def is_social?
|
75
85
|
normalize_params[:id_token].present?
|
76
86
|
end
|
77
87
|
|
data/lib/ibrain/auth/version.rb
CHANGED
@@ -4,14 +4,14 @@ module Ibrain
|
|
4
4
|
# frozen_string_literal: true
|
5
5
|
|
6
6
|
module Auth
|
7
|
-
VERSION = '0.2.
|
7
|
+
VERSION = '0.2.6'
|
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.
|
14
|
+
'0.2.5'
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.ibrain_auth_gem_version
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibrain-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tai Nguyen Van
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise-encryptable
|
@@ -197,8 +197,7 @@ files:
|
|
197
197
|
- app/graphql/ibrain/auth/mutations/sign_in_mutation.rb
|
198
198
|
- app/graphql/ibrain/auth/mutations/sign_out_mutation.rb
|
199
199
|
- app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
|
200
|
-
- app/graphql/ibrain/auth/mutations/
|
201
|
-
- app/graphql/ibrain/auth/mutations/sso_sign_up_mutation.rb
|
200
|
+
- app/graphql/ibrain/auth/mutations/social_sign_in_mutation.rb
|
202
201
|
- app/graphql/ibrain/auth/types/input/sign_in_input.rb
|
203
202
|
- app/graphql/ibrain/auth/types/input/sign_up_input.rb
|
204
203
|
- app/models/ibrain/auth/user.rb
|
@@ -246,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
245
|
- !ruby/object:Gem::Version
|
247
246
|
version: '0'
|
248
247
|
requirements: []
|
249
|
-
rubygems_version: 3.3.
|
248
|
+
rubygems_version: 3.3.7
|
250
249
|
signing_key:
|
251
250
|
specification_version: 4
|
252
251
|
summary: Its Auth is an sso authen gem for Ruby on Rails.
|
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Ibrain::Auth::Mutations
|
4
|
-
class SsoSignUpMutation < BaseMutation
|
5
|
-
field :user, Types::Objects::UserType, null: true
|
6
|
-
field :token, String, null: true
|
7
|
-
field :result, Boolean, null: true
|
8
|
-
|
9
|
-
argument :id_token, String, description: 'Id Token from SSO', required: true
|
10
|
-
argument :user, Ibrain::Auth::Config.sign_up_input, required: true
|
11
|
-
argument :device_token, String, description: 'Device token for notificaiton', required: false
|
12
|
-
|
13
|
-
def resolve(args)
|
14
|
-
# TODO: define logic inside repository
|
15
|
-
repo = ::AuthRepository.new(nil, normalize_params(args))
|
16
|
-
user = repo.sign_up
|
17
|
-
|
18
|
-
return OpenStruct.new({ user: nil, token: nil, result: false, is_verified: false }) if user.blank?
|
19
|
-
|
20
|
-
sign_in(resource_name, user)
|
21
|
-
@current_user = warden.authenticate!(auth_options)
|
22
|
-
|
23
|
-
warden.set_user(current_user)
|
24
|
-
current_user.jwt_token, jti = auth_headers(request, user)
|
25
|
-
|
26
|
-
current_user.jti = jti
|
27
|
-
current_user.save!
|
28
|
-
|
29
|
-
if args[:device_token].present?
|
30
|
-
device_token = current_user.device_tokens.find_by(token: args[:device_token])
|
31
|
-
|
32
|
-
current_user.device_tokens.create!({ token: args[:device_token] }) if device_token.blank?
|
33
|
-
end
|
34
|
-
|
35
|
-
context[:current_user] = current_user
|
36
|
-
|
37
|
-
OpenStruct.new(
|
38
|
-
user: user_signed_in? ? current_user : nil,
|
39
|
-
token: current_user.try(:jwt_token),
|
40
|
-
result: user_signed_in?,
|
41
|
-
is_verified: true
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def normalize_params(args)
|
48
|
-
ActionController::Parameters.new(args.as_json)
|
49
|
-
rescue StandardError
|
50
|
-
ActionController::Parameters.new({})
|
51
|
-
end
|
52
|
-
|
53
|
-
def auth_options
|
54
|
-
{ scope: resource_name }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|