ibrain-auth 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ibrain/social_callbacks_controller.rb +58 -0
  3. data/app/graphql/ibrain/{auth/mutations/base_mutation.rb → mutations/auth_mutation.rb} +2 -2
  4. data/app/graphql/ibrain/{auth/mutations → mutations}/generate_firebase_token_mutation.rb +3 -3
  5. data/app/graphql/ibrain/{auth/mutations → mutations}/sign_in_mutation.rb +2 -2
  6. data/app/graphql/ibrain/{auth/mutations → mutations}/sign_out_mutation.rb +2 -2
  7. data/app/graphql/ibrain/{auth/mutations → mutations}/sign_up_mutation.rb +2 -2
  8. data/app/graphql/ibrain/{auth/mutations → mutations}/social_sign_in_mutation.rb +23 -17
  9. data/app/graphql/ibrain/types/input/generate_firebase_token_input.rb +11 -0
  10. data/app/graphql/ibrain/types/input/sign_in_input.rb +12 -0
  11. data/app/graphql/ibrain/types/input/sign_up_input.rb +17 -0
  12. data/app/graphql/ibrain/types/input/social_login_input.rb +11 -0
  13. data/app/graphql/ibrain/types/input/social_sign_in_input.rb +11 -0
  14. data/app/models/ibrain/user.rb +76 -0
  15. data/app/repositories/apple_repository.rb +17 -0
  16. data/app/repositories/auth_repository.rb +1 -1
  17. data/config/routes.rb +11 -7
  18. data/{app/controllers/ibrain/auth/confirmations_controller.rb → lib/controllers/ibrain/user_confirmations_controller.rb} +1 -1
  19. data/{app/controllers/ibrain/auth/passwords_controller.rb → lib/controllers/ibrain/user_passwords_controller.rb} +1 -1
  20. data/{app/controllers/ibrain/auth/registrations_controller.rb → lib/controllers/ibrain/user_registrations_controller.rb} +1 -1
  21. data/{app/controllers/ibrain/auth/sessions_controller.rb → lib/controllers/ibrain/user_sessions_controller.rb} +5 -1
  22. data/{app/controllers/ibrain/auth/unlocks_controller.rb → lib/controllers/ibrain/user_unlocks_controller.rb} +1 -1
  23. data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_auth.rb.tt +3 -3
  24. data/lib/generators/ibrain/auth/install/templates/config/initializers/omniauth.rb.tt +14 -1
  25. data/lib/ibrain/auth/version.rb +1 -1
  26. data/lib/ibrain/auth_configuration.rb +3 -3
  27. data/lib/ibrain_auth.rb +7 -1
  28. metadata +35 -18
  29. data/app/graphql/ibrain/auth/types/input/generate_firebase_token_input.rb +0 -13
  30. data/app/graphql/ibrain/auth/types/input/sign_in_input.rb +0 -14
  31. data/app/graphql/ibrain/auth/types/input/sign_up_input.rb +0 -19
  32. data/app/graphql/ibrain/auth/types/input/social_sign_in_input.rb +0 -13
  33. data/app/models/ibrain/auth/user.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b5a9480e0e869679bf664237ce962ef17ff56ef7087251211bcd0d4ae28aee9
4
- data.tar.gz: 43503cd8684a83261e76c7cbfd998edf29fb28f94afd13a7025c97e027012b9f
3
+ metadata.gz: e53c7a067d83daed1106f84e91ef43c2bfa2bf9c0dd93f28975bea0797cd03c1
4
+ data.tar.gz: b53fc7d477909ea0f0b77929e3cfd611e96ef5acbb6520185d284f98a0f3de4f
5
5
  SHA512:
6
- metadata.gz: 478b379d0d48a0e166301146009c1e167205f30cc40007df80f88d26357887866fd25be95c5b534e287acc7e899cce8380fd6a2130ec0671230ef4e9526f113d
7
- data.tar.gz: d90a560cdab976bae3615509d29b77d958aeaec107b748b20157db953407cd241417acf1915a30fd001055b60e28602161fb62f75c80db2dd51c7f85357c7f75
6
+ metadata.gz: 4f8dd526a1cabb900427a717807e284f01d6252846938a8462f3eee694619d519380f657f75903e0943919acdacaf307176dc5b808d1578154e1f7aadbaebd27
7
+ data.tar.gz: 8b38d0ce05fae155ea22e05429670b5446105d4faa36a500159833f579a2402e9d9cc243c8aadbedc38f3a684af5ef9c10c2a6b201e1e2f500ea1f60d23560c9
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ibrain::SocialCallbacksController < Devise::OmniauthCallbacksController
4
+ include ActionController::Helpers
5
+ include Ibrain::Core::ControllerHelpers::Response
6
+ include ActionController::MimeResponds
7
+
8
+ def instagram
9
+ generic_callback( 'instagram' )
10
+ end
11
+
12
+ def facebook
13
+ generic_callback( 'facebook' )
14
+ end
15
+
16
+ def twitter
17
+ generic_callback( 'twitter' )
18
+ end
19
+
20
+ def google_oauth2
21
+ generic_callback( 'google_oauth2' )
22
+ end
23
+
24
+ def apple
25
+ generic_callback( 'apple' )
26
+ end
27
+
28
+ def line
29
+ generic_callback( 'line' )
30
+ end
31
+
32
+ def create
33
+ user = line_repo.find_or_initialize!
34
+
35
+ render_json_ok(user, nil)
36
+ end
37
+
38
+ def new_user_session(*args)
39
+ new_session(*args)
40
+ end
41
+
42
+ private
43
+
44
+ def repo
45
+ AuthRepository.new(resource, params)
46
+ end
47
+
48
+ def line_repo
49
+ LineRepository.new(resource, request.env['omniauth.auth'])
50
+ end
51
+
52
+ def apple_repo
53
+ AppleRepository.new(resource, request.env['omniauth.auth'])
54
+ end
55
+
56
+ def generic_callback( provider )
57
+ end
58
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class BaseMutation < Ibrain::Mutations::BaseMutation
3
+ module Ibrain::Mutations
4
+ class AuthMutation < Ibrain::Mutations::BaseMutation
5
5
  include ActionController::Helpers
6
6
  include Devise::Controllers::ScopedViews
7
7
  include Devise::Controllers::Helpers
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class GenerateFirebaseTokenMutation < BaseMutation
3
+ module Ibrain::Mutations
4
+ class GenerateFirebaseTokenMutation < AuthMutation
5
5
  field :result, Boolean, null: true
6
6
  field :token, String, null: true
7
7
 
8
- argument :attributes, ::Ibrain::Auth::Types::Input::GenerateFirebaseTokenInput, required: true
8
+ argument :attributes, ::Ibrain::Types::Input::GenerateFirebaseTokenInput, required: true
9
9
 
10
10
  def resolve(_args)
11
11
  token = repo.generate_custom_token!
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class SignInMutation < BaseMutation
3
+ module Ibrain::Mutations
4
+ class SignInMutation < AuthMutation
5
5
  field :user, Types::Objects::UserType, null: true
6
6
  field :token, String, null: true
7
7
  field :result, Boolean, null: true
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class SignOutMutation < BaseMutation
3
+ module Ibrain::Mutations
4
+ class SignOutMutation < AuthMutation
5
5
  field :result, Boolean, null: true
6
6
 
7
7
  def resolve
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class SignUpMutation < BaseMutation
3
+ module Ibrain::Mutations
4
+ class SignUpMutation < AuthMutation
5
5
  field :is_verified, Boolean, null: true
6
6
  field :result, Boolean, null: true
7
7
 
@@ -1,17 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Auth::Mutations
4
- class SocialSignInMutation < BaseMutation
3
+ module Ibrain::Mutations
4
+ class SocialSignInMutation < AuthMutation
5
5
  field :user, Types::Objects::UserType, null: true
6
6
  field :token, String, null: true
7
7
  field :result, Boolean, null: true
8
- field :is_verified, Boolean, null: true
9
8
 
10
9
  argument :attributes, Ibrain::Auth::Config.social_sign_in_input, required: true
11
- argument :device_token, String, description: 'Device token for notificaiton', required: false
10
+ argument :device_token, String, description: 'Device token for notification', required: false
12
11
 
13
- def resolve(args)
14
- return OpenStruct.new({ user: nil, token: nil, result: false, is_verified: false }) if auth_resource.blank?
12
+ def resolve(_args)
13
+ return graphql_returning(false) if auth_resource.blank?
15
14
 
16
15
  auth_resource.skip_confirmation! unless auth_resource.try(:confirmed?)
17
16
  sign_in(resource_name, auth_resource)
@@ -30,16 +29,23 @@ module Ibrain::Auth::Mutations
30
29
 
31
30
  context[:current_user] = current_user
32
31
 
33
- OpenStruct.new(
34
- user: user_signed_in? ? current_user : nil,
35
- token: current_user.try(:jwt_token),
36
- result: user_signed_in?,
37
- is_verified: true
32
+ graphql_returning(
33
+ user_signed_in?,
34
+ user_signed_in? ? current_user : nil,
35
+ current_user.try(:jwt_token)
38
36
  )
39
37
  end
40
38
 
41
39
  private
42
40
 
41
+ def load_resource
42
+ repo.sign_in
43
+ end
44
+
45
+ def repo
46
+ ::AuthRepository.new(nil, normalize_parameters)
47
+ end
48
+
43
49
  def normalize_parameters
44
50
  attribute_params
45
51
  rescue StandardError
@@ -50,12 +56,12 @@ module Ibrain::Auth::Mutations
50
56
  { scope: resource_name }
51
57
  end
52
58
 
53
- def repo
54
- ::AuthRepository.new(nil, normalize_parameters)
55
- end
56
-
57
- def load_resource
58
- repo.sign_in
59
+ def graphql_returning(result, user = nil, token = nil)
60
+ OpenStruct.new(
61
+ user: user,
62
+ token: token,
63
+ result: result
64
+ )
59
65
  end
60
66
  end
61
67
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ module Input
6
+ class GenerateFirebaseTokenInput < Ibrain::Types::BaseInputObject
7
+ argument :uid, String, required: true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ module Input
6
+ class SignInInput < Ibrain::Types::BaseInputObject
7
+ argument :username, String, required: true
8
+ argument :password, String, required: true
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ module Input
6
+ class SignUpInput < Ibrain::Types::BaseInputObject
7
+ argument :first_name, String, required: false
8
+ argument :last_name, String, required: false
9
+ argument :email, String, required: false
10
+ argument :phone, String, required: false
11
+ argument :job_id, ID, required: false
12
+ argument :address, String, required: false
13
+ argument :password, String, required: false
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ module Input
6
+ class SocialLoginInput < Ibrain::Types::BaseInputObject
7
+ argument :id_token, String, required: true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ module Types
5
+ module Input
6
+ class SocialSignInInput < Ibrain::Types::BaseInputObject
7
+ argument :id_token, String, description: 'Id Token from firebase', required: true
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain
4
+ class User < Ibrain::Base
5
+ attr_accessor :jwt_token
6
+
7
+ include Devise::JWT::RevocationStrategies::JTIMatcher
8
+
9
+ self.abstract_class = true
10
+ self.table_name = Ibrain::Auth::Config.user_table_name
11
+
12
+ devise :database_authenticatable, :registerable, :confirmable,
13
+ :recoverable, :validatable, :timeoutable, :omniauthable,
14
+ :jwt_authenticatable, jwt_revocation_strategy: self,
15
+ omniauth_providers: %i[apple facebook twitter line]
16
+
17
+ scope :find_by_line, ->(uid) {
18
+ find_by(uid: uid, provider: 'line')
19
+ }
20
+
21
+ scope :find_by_apple, ->(uid) {
22
+ find_by(uid: uid, provider: 'apple')
23
+ }
24
+
25
+ def jwt_payload
26
+ # for hasura
27
+ hasura_keys = {
28
+ 'https://hasura.io/jwt/claims': {
29
+ 'x-hasura-allowed-roles': Ibrain.user_class.roles.keys,
30
+ 'x-hasura-default-role': role,
31
+ 'x-hasura-user-id': id.to_s
32
+ }
33
+ }
34
+
35
+ super.merge({ 'role' => role }, hasura_keys)
36
+ end
37
+
38
+ def can_skip_confirmation?
39
+ try(:is_admin?) || email.blank?
40
+ end
41
+
42
+ class << self
43
+ def ibrain_find(params, available_columns)
44
+ matched_value = params[:username] || params[:email]
45
+
46
+ if matched_value.present?
47
+ query = available_columns.map do |column_name|
48
+ <<~RUBY
49
+ #{column_name} = '#{matched_value}'
50
+ RUBY
51
+ end.join(' OR ')
52
+
53
+ where(query).first
54
+ end
55
+ end
56
+
57
+ def social_find_or_initialize(params)
58
+ user = find_by(provider: params[:provider], uid: params[:uid])
59
+ return user if user.present?
60
+
61
+ create!(params)
62
+ end
63
+
64
+ def create_with_line!(params)
65
+ user = created!({
66
+ uid: params['uid'],
67
+ provider: 'line',
68
+ remote_avatar_url: params['info']['image']
69
+ })
70
+
71
+ user.skip_confirmation! unless user&.confirmed?
72
+ user
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,17 @@
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
+
11
+ def find_or_initialize!
12
+ user = @collection.find_by_apple(uid: params['uid'])
13
+ return user if user.present?
14
+
15
+ @collection.create_with_line!
16
+ end
17
+ end
@@ -66,7 +66,7 @@ class AuthRepository < Ibrain::BaseRepository
66
66
  try(:fetch, 'providerUserInfo', []).
67
67
  try(:at, 0).try(:fetch, 'providerId', '').
68
68
  try(:gsub, '.com', '')
69
- raise ActiveRecord::RecordNotFound, I18n.t('ibrain.errors.account.not_found') if uid.blank?
69
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.account.not_found') if uid.blank?
70
70
 
71
71
  collection.social_find_or_initialize({
72
72
  uid: uid,
data/config/routes.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Ibrain::Auth::Engine.routes.draw do
4
- devise_for :users, controllers: {
5
- sessions: "ibrain/auth/sessions",
6
- registrations: "ibrain/auth/registrations",
4
+ devise_for(:users, {
5
+ class_name: 'Ibrain::User',
6
+ controllers: {
7
+ sessions: 'ibrain/user_sessions',
8
+ registrations: 'ibrain/user_registrations',
9
+ passwords: 'ibrain/user_passwords',
10
+ confirmations: 'ibrain/user_confirmations',
11
+ omniauth_callbacks: 'ibrain/social_callbacks'
7
12
  },
8
- path: "api/#{Ibrain::Config.api_version}/users",
9
- defaults: { format: :json }
10
-
11
- get "api/#{Ibrain::Config.api_version}/users/callback" => 'sessions#callback'
13
+ skip: [:unlocks],
14
+ path_prefix: "api/#{Ibrain::Config.api_version}"
15
+ })
12
16
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Auth::ConfirmationsController < Devise::ConfirmationsController
3
+ class Ibrain::UserConfirmationsController < Devise::ConfirmationsController
4
4
  # GET /resource/confirmation/new
5
5
  # def new
6
6
  # super
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Auth::PasswordsController < Devise::PasswordsController
3
+ class Ibrain::UserPasswordsController < Devise::PasswordsController
4
4
  # GET /resource/password/new
5
5
  # def new
6
6
  # super
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Auth::RegistrationsController < Devise::RegistrationsController
3
+ class Ibrain::UserRegistrationsController < Devise::RegistrationsController
4
4
  # before_action :configure_sign_up_params, only: [:create]
5
5
  # before_action :configure_account_update_params, only: [:update]
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Auth::SessionsController < Devise::SessionsController
3
+ class Ibrain::UserSessionsController < Devise::SessionsController
4
4
  include ActionController::Helpers
5
5
  include Ibrain::Core::ControllerHelpers::Response
6
6
  include ActionController::MimeResponds
@@ -51,4 +51,8 @@ class Ibrain::Auth::SessionsController < Devise::SessionsController
51
51
  def line_repo
52
52
  LineRepository.new(resource, request.env['omniauth.auth'])
53
53
  end
54
+
55
+ def apple_repo
56
+ AppleRepository.new(resource, request.env['omniauth.auth'])
57
+ end
54
58
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Auth::UnlocksController < Devise::UnlocksController
3
+ class Ibrain::UserUnlocksController < Devise::UnlocksController
4
4
  # GET /resource/unlock/new
5
5
  # def new
6
6
  # super
@@ -12,10 +12,10 @@ Ibrain::Auth.config do |config|
12
12
  config.user_table_name = 'ibrain_users'
13
13
 
14
14
  # sign_up graphql input
15
- config.sign_up_input = Ibrain::Auth::Types::Input::SignUpInput
15
+ config.sign_up_input = Ibrain::Types::Input::SignUpInput
16
16
 
17
17
  # sign_in graphql input
18
- config.sign_up_input = Ibrain::Auth::Types::Input::SignInInput
18
+ config.sign_up_input = Ibrain::Types::Input::SignInInput
19
19
 
20
20
  # firebase private json path
21
21
  config.firebase_private_key_path = Rails.root.join('static/firebase.json')
@@ -27,5 +27,5 @@ Ibrain::Auth.config do |config|
27
27
  config.firebase_owner_email = nil
28
28
 
29
29
  # social sign_in input
30
- config.social_sign_in_input = Ibrain::Auth::Types::Input::SocialSignInInput
30
+ config.social_sign_in_input = Ibrain::Types::Input::SocialSignInInput
31
31
  end
@@ -8,5 +8,18 @@ Rails.application.config.middleware.use OmniAuth::Builder do
8
8
  # provider :line, ENV['LINE_CLIENT_ID'], ENV['LINE_CLIENT_SECRET']
9
9
 
10
10
  # For apple authenticate
11
- # provider :apple, ENV['APPLE_CLIENT_ID'], ENV['APPLE_CLIENT_SECRET']
11
+ # provider :apple, ENV['APPLE_CLIENT_ID'], '',
12
+ # {
13
+ # scope: 'email name',
14
+ # team_id: ENV['APPLE_TEAM_ID'],
15
+ # key_id: ENV['APPLE_KEY_ID'],
16
+ # pem: ENV['APPLE_PRIVATE_KEY']
17
+ # }
18
+
19
+ # For facebook
20
+ # provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'] scope: 'public_profile,email',
21
+ info_fields: 'email,first_name,last_name,gender,birthday,location,picture',
22
+
23
+ # For google
24
+ # provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET']
12
25
  end
@@ -4,7 +4,7 @@ module Ibrain
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Auth
7
- VERSION = '0.3.7'
7
+ VERSION = '0.3.8'
8
8
 
9
9
  def self.ibrain_auth_version
10
10
  VERSION
@@ -13,10 +13,10 @@ module Ibrain
13
13
  preference :user_table_name, :string, default: 'ibrain_users'
14
14
 
15
15
  # sign_up input
16
- preference :sign_up_input, :class, default: Ibrain::Auth::Types::Input::SignUpInput
16
+ preference :sign_up_input, :class, default: Ibrain::Types::Input::SignUpInput
17
17
 
18
18
  # sign_in input
19
- preference :sign_in_input, :class, default: Ibrain::Auth::Types::Input::SignInInput
19
+ preference :sign_in_input, :class, default: Ibrain::Types::Input::SignInInput
20
20
 
21
21
  # firebase private json path
22
22
  preference :firebase_private_key_path, :string, default: Rails.root.join('static/firebase.json')
@@ -27,6 +27,6 @@ module Ibrain
27
27
  # firebase owner email
28
28
  preference :firebase_owner_email, :string, default: nil
29
29
 
30
- preference :social_sign_in_input, :class, default: Ibrain::Auth::Types::Input::SocialSignInInput
30
+ preference :social_sign_in_input, :class, default: Ibrain::Types::Input::SocialSignInInput
31
31
  end
32
32
  end
data/lib/ibrain_auth.rb CHANGED
@@ -1,3 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ibrain/auth'
3
+ require "zeitwerk"
4
+ loader = Zeitwerk::Loader.new
5
+ loader.tag = File.basename(__FILE__, ".rb")
6
+ loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
7
+ loader.enable_reloading
8
+ loader.setup
9
+ loader.reload
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.3.7
4
+ version: 0.3.8
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-12-02 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: omniauth-rails_csrf_protection
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: omniauth-twitter
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -202,22 +216,20 @@ files:
202
216
  - MIT-LICENSE
203
217
  - README.md
204
218
  - Rakefile
205
- - app/controllers/ibrain/auth/confirmations_controller.rb
206
- - app/controllers/ibrain/auth/passwords_controller.rb
207
- - app/controllers/ibrain/auth/registrations_controller.rb
208
- - app/controllers/ibrain/auth/sessions_controller.rb
209
- - app/controllers/ibrain/auth/unlocks_controller.rb
210
- - app/graphql/ibrain/auth/mutations/base_mutation.rb
211
- - app/graphql/ibrain/auth/mutations/generate_firebase_token_mutation.rb
212
- - app/graphql/ibrain/auth/mutations/sign_in_mutation.rb
213
- - app/graphql/ibrain/auth/mutations/sign_out_mutation.rb
214
- - app/graphql/ibrain/auth/mutations/sign_up_mutation.rb
215
- - app/graphql/ibrain/auth/mutations/social_sign_in_mutation.rb
216
- - app/graphql/ibrain/auth/types/input/generate_firebase_token_input.rb
217
- - app/graphql/ibrain/auth/types/input/sign_in_input.rb
218
- - app/graphql/ibrain/auth/types/input/sign_up_input.rb
219
- - app/graphql/ibrain/auth/types/input/social_sign_in_input.rb
220
- - app/models/ibrain/auth/user.rb
219
+ - app/controllers/ibrain/social_callbacks_controller.rb
220
+ - app/graphql/ibrain/mutations/auth_mutation.rb
221
+ - app/graphql/ibrain/mutations/generate_firebase_token_mutation.rb
222
+ - app/graphql/ibrain/mutations/sign_in_mutation.rb
223
+ - app/graphql/ibrain/mutations/sign_out_mutation.rb
224
+ - app/graphql/ibrain/mutations/sign_up_mutation.rb
225
+ - app/graphql/ibrain/mutations/social_sign_in_mutation.rb
226
+ - app/graphql/ibrain/types/input/generate_firebase_token_input.rb
227
+ - app/graphql/ibrain/types/input/sign_in_input.rb
228
+ - app/graphql/ibrain/types/input/sign_up_input.rb
229
+ - app/graphql/ibrain/types/input/social_login_input.rb
230
+ - app/graphql/ibrain/types/input/social_sign_in_input.rb
231
+ - app/models/ibrain/user.rb
232
+ - app/repositories/apple_repository.rb
221
233
  - app/repositories/auth_repository.rb
222
234
  - app/repositories/firebase_repository.rb
223
235
  - app/repositories/line_repository.rb
@@ -226,6 +238,11 @@ files:
226
238
  - config/locales/ja.yml
227
239
  - config/locales/vi.yml
228
240
  - config/routes.rb
241
+ - lib/controllers/ibrain/user_confirmations_controller.rb
242
+ - lib/controllers/ibrain/user_passwords_controller.rb
243
+ - lib/controllers/ibrain/user_registrations_controller.rb
244
+ - lib/controllers/ibrain/user_sessions_controller.rb
245
+ - lib/controllers/ibrain/user_unlocks_controller.rb
229
246
  - lib/generators/ibrain/auth/install/install_generator.rb
230
247
  - lib/generators/ibrain/auth/install/templates/config/initializers/devise.rb.tt
231
248
  - lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_auth.rb.tt
@@ -1,13 +0,0 @@
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
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Auth
5
- module Types
6
- module Input
7
- class SignInInput < Ibrain::Types::BaseInputObject
8
- argument :username, String, required: true
9
- argument :password, String, required: true
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Auth
5
- module Types
6
- module Input
7
- class SignUpInput < Ibrain::Types::BaseInputObject
8
- argument :first_name, String, required: false
9
- argument :last_name, String, required: false
10
- argument :email, String, required: false
11
- argument :phone, String, required: false
12
- argument :job_id, ID, required: false
13
- argument :address, String, required: false
14
- argument :password, String, required: false
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Auth
5
- module Types
6
- module Input
7
- class SocialSignInInput < Ibrain::Types::BaseInputObject
8
- argument :id_token, String, description: 'Id Token from firebase', required: true
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,73 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ibrain
4
- module Auth
5
- class User < Ibrain::Base
6
- attr_accessor :jwt_token
7
-
8
- include Devise::JWT::RevocationStrategies::JTIMatcher
9
-
10
- self.abstract_class = true
11
- self.table_name = Ibrain::Auth::Config.user_table_name
12
-
13
- devise :database_authenticatable, :registerable, :confirmable,
14
- :recoverable, :validatable, :timeoutable,
15
- :jwt_authenticatable, jwt_revocation_strategy: self
16
-
17
- scope :find_by_line, ->(uid) {
18
- find_by(uid: uid, provider: 'line')
19
- }
20
-
21
- def jwt_payload
22
- # for hasura
23
- hasura_keys = {
24
- 'https://hasura.io/jwt/claims': {
25
- 'x-hasura-allowed-roles': Ibrain.user_class.roles.keys,
26
- 'x-hasura-default-role': role,
27
- 'x-hasura-user-id': id.to_s
28
- }
29
- }
30
-
31
- super.merge({ 'role' => role }, hasura_keys)
32
- end
33
-
34
- def can_skip_confirmation?
35
- try(:is_admin?) || email.blank?
36
- end
37
-
38
- class << self
39
- def ibrain_find(params, available_columns)
40
- matched_value = params[:username] || params[:email]
41
-
42
- if matched_value.present?
43
- query = available_columns.map do |column_name|
44
- <<~RUBY
45
- #{column_name} = '#{matched_value}'
46
- RUBY
47
- end.join(' OR ')
48
-
49
- where(query).first
50
- end
51
- end
52
-
53
- def social_find_or_initialize(params)
54
- user = find_by(provider: params[:provider], uid: params[:uid])
55
- return user if user.present?
56
-
57
- create!(params)
58
- end
59
-
60
- def create_with_line!(params)
61
- user = created!({
62
- uid: params['uid'],
63
- provider: 'line',
64
- remote_avatar_url: params['info']['image']
65
- })
66
-
67
- user.skip_confirmation! unless user&.confirmed?
68
- user
69
- end
70
- end
71
- end
72
- end
73
- end