ibrain-auth 0.2.9 → 0.3.2

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: f763692f6d5b704c1b30c50a104d61283df33633e4009f6cb39ec4d25113f893
4
- data.tar.gz: 475275e8117238e9ff17b84917a8611a55d58e2da974d49d9dee0f24316a2d2c
3
+ metadata.gz: 206a4714c39ab84c1250cf3468ab4337548dc77691ae0a2d080e4ab6cbe5037d
4
+ data.tar.gz: 0aa8cbb121f80422c166cc8f3a6374b2f7b7c669d5b5bfc008de0aa47b5f2650
5
5
  SHA512:
6
- metadata.gz: df00d71b19ba24ad523dbb7af3c29b63ac634376892b2ae3f098fbc1cd5b3924d6efcd8e992f91c5c83c7ce555e69ad3e54fba698360f5d0aaf38d522a744049
7
- data.tar.gz: 19f4f1662d54348a57d9525cd3d03a757e82f467b2556e59cb7752df81e88a48fb638872f4b0a1dbff6579546b6e13f300e0e9619fb37854acd824a4787a417c
6
+ metadata.gz: c7aecfa2c1f02b07d341b16ce230816515be57bc0f542ace841c3df0719a29824de51854f205f229903b7a4bf0e49a9e1ad940fbd5f41cc63ace4d05ba2e099f
7
+ data.tar.gz: 923f20470aab2a1291d727d7d7dea26de9f78d494e1e72f516dfdc4593fd9affcac15f8559501bb8ce92fe795a6c5e7fcd28694062da0e8e0baf425b087106c1
@@ -14,6 +14,12 @@ class Ibrain::Auth::SessionsController < Devise::SessionsController
14
14
  super { |resource| @resource = resource }
15
15
  end
16
16
 
17
+ def callback
18
+ user = line_repo.find_or_initialize!
19
+
20
+ render_json_ok(user, nil)
21
+ end
22
+
17
23
  # GET /resource/sign_in
18
24
  # def new
19
25
  # super
@@ -42,14 +48,6 @@ class Ibrain::Auth::SessionsController < Devise::SessionsController
42
48
  AuthRepository.new(resource, params)
43
49
  end
44
50
 
45
- def twitter_repo
46
- TwitterRepository.new(resource, request.env['omniauth.auth'])
47
- end
48
-
49
- def apple_repo
50
- AppleRepository.new(resource, request.env['omniauth.auth'])
51
- end
52
-
53
51
  def line_repo
54
52
  LineRepository.new(resource, request.env['omniauth.auth'])
55
53
  end
@@ -32,4 +32,4 @@ module Ibrain::Auth::Mutations
32
32
  )
33
33
  end
34
34
  end
35
- end
35
+ end
@@ -10,4 +10,4 @@ module Ibrain
10
10
  end
11
11
  end
12
12
  end
13
- end
13
+ end
@@ -11,6 +11,7 @@ module Ibrain
11
11
  argument :phone, String, required: false
12
12
  argument :job_id, ID, required: false
13
13
  argument :address, String, required: false
14
+ argument :password, String, required: false
14
15
  end
15
16
  end
16
17
  end
@@ -9,10 +9,14 @@ module Ibrain
9
9
 
10
10
  self.table_name = Ibrain::Auth::Config.user_table_name
11
11
 
12
- devise :database_authenticatable, :registerable,
12
+ devise :database_authenticatable, :registerable, :confirmable,
13
13
  :recoverable, :validatable, :timeoutable,
14
14
  :jwt_authenticatable, jwt_revocation_strategy: self
15
15
 
16
+ scope :find_by_line, ->(uid) {
17
+ find_by(uid: uid, provider: 'line')
18
+ }
19
+
16
20
  def jwt_payload
17
21
  # for hasura
18
22
  hasura_keys = {
@@ -47,6 +51,14 @@ module Ibrain
47
51
 
48
52
  create!(params)
49
53
  end
54
+
55
+ def create_with_line!(params)
56
+ created!({
57
+ uid: params['uid'],
58
+ provider: 'line',
59
+ remote_avatar_url: params['info']['image']
60
+ })
61
+ end
50
62
  end
51
63
  end
52
64
  end
@@ -11,9 +11,9 @@ class AuthRepository < Ibrain::BaseRepository
11
11
  end
12
12
 
13
13
  def create
14
- user = is_social? ? firebase_verify : collection.ibrain_find(manual_params, available_columns)
14
+ user = collection.new(provider: 'manual')
15
15
  user.assign_attributes(normalize_params.except(:id_token))
16
- user.save
16
+ user.save!
17
17
 
18
18
  user
19
19
  end
@@ -86,7 +86,7 @@ class AuthRepository < Ibrain::BaseRepository
86
86
  end
87
87
 
88
88
  def permitted_attributes
89
- Ibrain.user_class.permitted_attributes.reject { |k| permintted_columns.include?(k) }.map(&:to_sym).concat([:id_token])
89
+ Ibrain.user_class.permitted_attributes.reject { |k| permintted_columns.include?(k) }.map(&:to_sym).concat([:id_token]).concat([:password])
90
90
  end
91
91
 
92
92
  def permintted_columns
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FirebaseRepository < Ibrain::BaseRepository
4
- def initialize(record, _params)
4
+ def initialize(record, params)
5
5
  super(nil, record)
6
6
 
7
7
  @private_key_json = File.open(Ibrain::Auth::Config.firebase_private_key_path).read
8
8
  @firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
9
+ @params = params
9
10
  end
10
11
 
11
12
  def generate_custom_token!
@@ -14,7 +15,7 @@ class FirebaseRepository < Ibrain::BaseRepository
14
15
  payload = {
15
16
  iss: firebase_owner_email,
16
17
  sub: firebase_owner_email,
17
- aud: Ibrain::Auth::Config.firebase_aud_url,
18
+ aud: Ibrain::Auth::Config.firebase_auth_url,
18
19
  iat: now,
19
20
  exp: now + 3600,
20
21
  uid: params[:uid],
@@ -26,10 +27,7 @@ class FirebaseRepository < Ibrain::BaseRepository
26
27
 
27
28
  private
28
29
 
29
- attr_reader :private_key_json, :firebase_owner_email
30
-
31
- def method_name
32
- end
30
+ attr_reader :private_key_json, :firebase_owner_email, :params
33
31
 
34
32
  def json_firebase
35
33
  JSON.parse(private_key_json, symbolize_names: true)
@@ -38,4 +36,4 @@ class FirebaseRepository < Ibrain::BaseRepository
38
36
  def private_key
39
37
  OpenSSL::PKey::RSA.new json_firebase[:private_key]
40
38
  end
41
- end
39
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ class LineRepository < Ibrain::BaseRepository
4
+ def initialize(record, params)
5
+ super(nil, record)
6
+
7
+ @params = params
8
+ @collection = Ibrain.user_class
9
+ end
10
+
11
+ def find_or_initialize!
12
+ user = @collection.find_by_line(uid: params['uid'])
13
+
14
+ return user if user.present?
15
+
16
+ @collection.create_with_line!
17
+ end
18
+ end
@@ -4,14 +4,14 @@ module Ibrain
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Auth
7
- VERSION = '0.2.9'
7
+ VERSION = '0.3.2'
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.8'
14
+ '0.3.1'
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.9
4
+ version: 0.3.2
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-10-11 00:00:00.000000000 Z
11
+ date: 2022-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise-encryptable
@@ -203,10 +203,9 @@ files:
203
203
  - app/graphql/ibrain/auth/types/input/sign_in_input.rb
204
204
  - app/graphql/ibrain/auth/types/input/sign_up_input.rb
205
205
  - app/models/ibrain/auth/user.rb
206
- - app/repositories/apple_repository.rb
207
206
  - app/repositories/auth_repository.rb
208
207
  - app/repositories/firebase_repository.rb
209
- - app/repositories/twitter_repository.rb
208
+ - app/repositories/line_repository.rb
210
209
  - config/initializers/devise.rb
211
210
  - config/locales/en.yml
212
211
  - config/locales/jp.yml
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AppleRepository < Ibrain::BaseRepository
4
- def initialize(record, params)
5
- super(nil, record)
6
-
7
- @params = params
8
- @collection = Ibrain.user_class
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class TwitterRepository < Ibrain::BaseRepository
4
- def initialize(record, params)
5
- super(nil, record)
6
-
7
- @params = params
8
- @collection = Ibrain.user_class
9
- end
10
- end