ibrain-auth 0.3.1 → 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: 3eef3dff3e7584c32ba66d772c82c8d615e3b454fdb7c089a36ebf8d09a05da6
4
- data.tar.gz: d29178758eeab2e1b1ec0109c85adcafe26b010bce2a04b158852b4acaf836e5
3
+ metadata.gz: 206a4714c39ab84c1250cf3468ab4337548dc77691ae0a2d080e4ab6cbe5037d
4
+ data.tar.gz: 0aa8cbb121f80422c166cc8f3a6374b2f7b7c669d5b5bfc008de0aa47b5f2650
5
5
  SHA512:
6
- metadata.gz: 33ebefd5bad10bf4b79487eec0676ebebdd2bb065271a9030008cec3512aa60af43a909d4feed11e0a4264f0b1d1a712d082f254a1fb407cfecf0c7c5a2ee2bc
7
- data.tar.gz: b0780e05a9ce934d792e1422c3c4ba9dd9a8b590015569b7689ec07b18dc7750b4130994d4ab9c77a57ed60fe953109745aae01649f0cbda3319c93daee6e3e7
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
@@ -13,6 +13,10 @@ module Ibrain
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
@@ -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!
@@ -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)
@@ -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.3.1'
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.3.0'
14
+ '0.3.1'
15
15
  end
16
16
 
17
17
  def self.ibrain_auth_gem_version
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.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tai Nguyen Van
@@ -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