ibrain-auth 0.3.1 → 0.3.3

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: 3eef3dff3e7584c32ba66d772c82c8d615e3b454fdb7c089a36ebf8d09a05da6
4
- data.tar.gz: d29178758eeab2e1b1ec0109c85adcafe26b010bce2a04b158852b4acaf836e5
3
+ metadata.gz: 5c08fcfe12771e9c3cdde0a63bc0250d51cd5c7f27f9b082d0d835867a8d52b6
4
+ data.tar.gz: a876783c23b3109877d3f4f9d8e88d004e053996ae3ea710910c37d00cda6b9b
5
5
  SHA512:
6
- metadata.gz: 33ebefd5bad10bf4b79487eec0676ebebdd2bb065271a9030008cec3512aa60af43a909d4feed11e0a4264f0b1d1a712d082f254a1fb407cfecf0c7c5a2ee2bc
7
- data.tar.gz: b0780e05a9ce934d792e1422c3c4ba9dd9a8b590015569b7689ec07b18dc7750b4130994d4ab9c77a57ed60fe953109745aae01649f0cbda3319c93daee6e3e7
6
+ metadata.gz: 141d5cc986c569da43a09c1621c3b17aba77d5906eb794c8edcb837f0796b7f678cd62c35dd2d87ba701808536c717949e8e313e770ca9658d1dc8d8d39d9756
7
+ data.tar.gz: 104b92ead3c2452fe1e891567712883c5832978c1dce0d931ad291b33289a579f56e9df67172d410c58a91799d0bb551d1d83032b0fbfc7842e598460fd203c6
@@ -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
data/config/routes.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Ibrain::Core::Engine.routes.draw do
3
+ Ibrain::Auth::Engine.routes.draw do
4
4
  devise_for :users, controllers: {
5
5
  sessions: "ibrain/auth/sessions",
6
6
  registrations: "ibrain/auth/registrations",
7
- callback: "ibrain/auth/sessions/callback"
8
7
  },
9
8
  path: "api/#{Ibrain::Config.api_version}/users",
10
9
  defaults: { format: :json }
10
+
11
+ get "api/#{Ibrain::Config.api_version}/users/callback" => 'sessions#callback'
11
12
  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.3'
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.2'
15
15
  end
16
16
 
17
17
  def self.ibrain_auth_gem_version
data/lib/ibrain/auth.rb CHANGED
@@ -4,6 +4,10 @@ require 'devise'
4
4
  require 'devise-encryptable'
5
5
  require 'devise/jwt'
6
6
  require 'omniauth'
7
+ require 'omniauth-facebook'
8
+ require 'omniauth-google-oauth2'
9
+ require 'omniauth-line'
10
+ require 'omniauth-apple'
7
11
  require 'omniauth-twitter'
8
12
  require 'ibrain_core'
9
13
 
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.3
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