ibrain-auth 0.1.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcdfb62a4e32fec1df4cf5e882f89f3d730d13173aed46ffef0b64b5159bca73
4
- data.tar.gz: 378ee6aeffa8fab93a6bff8ad971b598a55225f622cca251698b06a3662682e7
3
+ metadata.gz: 32b449c2e6da655c6a1370d8a959e445b7033a0796412eaf1d56c262cf631208
4
+ data.tar.gz: 608b6cf7576707a109fe770135fc21c9fc68ec8c1cbef033fa8ac56ea8b11829
5
5
  SHA512:
6
- metadata.gz: 786e29e47ed31f9560cfe07bfc2ef8d8dd712e33eef3b7c2845605209796b8ed0aedd6f946fa9cab4518c3bd9850330ada1f8854cf3e7a6d2d6fe84d08ae2d59
7
- data.tar.gz: 3125c892362bd7286f7353b3976a6729a0f58866c30cb74a5ac4dbe67e8d851130dd1225457c66569937b6b780ef1bb890f4d05ceb278757fde9504889564a5a
6
+ metadata.gz: 4eabe8a892723ca998cb1b7af56e2392d2e37c8cc87f0871b9317d34075e855a8ec4c1c0e880aaf6debe76b0c793d67905d940ac93cce34bea382c33eb8082d1
7
+ data.tar.gz: 8a1fbed38a64e8a09705d32c69bd8ee71406d43ddc063c239b1ccfa85583333ac17e83e650bc8a5cf1dcef5063e17eb0e01b724a6c34f5e22aa53e6116a3b165
@@ -14,16 +14,18 @@ module Ibrain::Auth::Mutations
14
14
  repo = ::AuthRepository.new(nil, normalize_params(args))
15
15
  user = repo.sign_in
16
16
 
17
- if user.present?
18
- sign_in(resource_name, user)
19
- @current_user = warden.authenticate!(auth_options)
17
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.account.incorrect') if user.blank?
20
18
 
21
- warden.set_user(current_user)
22
- current_user.jwt_token, jti = auth_headers(request, user)
19
+ sign_in(resource_name, user)
20
+ @current_user = warden.authenticate!(auth_options)
23
21
 
24
- current_user.jti = jti
25
- current_user.save!
26
- end
22
+ warden.set_user(current_user)
23
+ current_user.jwt_token, jti = auth_headers(request, user)
24
+
25
+ current_user.jti = jti
26
+ current_user.save!
27
+
28
+ context[:current_user] = current_user
27
29
 
28
30
  OpenStruct.new(
29
31
  user: user_signed_in? ? current_user : nil,
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibrain::Auth::Mutations
4
+ class SsoSiginInMutation < 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
+
11
+ def resolve(args)
12
+ # TODO: define logic inside repository
13
+ repo = ::AuthRepository.new(nil, normalize_params(args))
14
+ user = repo.sign_in
15
+
16
+ raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.account.incorrect') if user.blank?
17
+
18
+ sign_in(resource_name, user)
19
+ @current_user = warden.authenticate!(auth_options)
20
+
21
+ warden.set_user(current_user)
22
+ current_user.jwt_token, jti = auth_headers(request, user)
23
+
24
+ current_user.jti = jti
25
+ current_user.save!
26
+
27
+ context[:current_user] = current_user
28
+
29
+ OpenStruct.new(
30
+ user: user_signed_in? ? current_user : nil,
31
+ token: current_user.try(:jwt_token),
32
+ result: user_signed_in?
33
+ )
34
+ end
35
+
36
+ private
37
+
38
+ def normalize_params(args)
39
+ ActionController::Parameters.new({ auth: args })
40
+ end
41
+
42
+ def auth_options
43
+ { scope: resource_name }
44
+ end
45
+ end
46
+ end
@@ -9,4 +9,5 @@ en:
9
9
  invalid_session: Invalid login session. Please try again!
10
10
  expired_session: The login session has expired.
11
11
  account:
12
- not_found: Account not found
12
+ not_found: Account not found
13
+ incorrect: Username or Password is incorrect!
@@ -9,4 +9,5 @@ jp:
9
9
  invalid_session: 無効なログインセッション。 もう一度やり直してください!
10
10
  expired_session: ログインセッションが期限切れになりました。
11
11
  account:
12
- not_found: アカウントが見つかりません
12
+ not_found: アカウントが見つかりません
13
+ incorrect: ユーザー名またはパスワードが正しくありません!
@@ -9,4 +9,5 @@ vi:
9
9
  invalid_session: Phiên đăng nhập không hợp lệ. Vui lòng thử lại!
10
10
  expired_session: Phiên đăng nhập đã hết hạn.
11
11
  account:
12
- not_found: Không tìm thấy tài khoản
12
+ not_found: Không tìm thấy tài khoản
13
+ incorrect: Tài khoản hoặc mật khẩu không chính xác!
@@ -1,5 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ibrain/auth/failure_app'
4
+
1
5
  # ==> Configuration for jwt
2
6
  Devise.jwt do |jwt|
3
7
  jwt.secret = ENV.fetch('JWT_SECRET_KEY', Ibrain::Auth::Config.jwt_secret_key) # Rails.application.credentials.secret_key_base
4
8
  jwt.expiration_time = 3600 * 24 * 30 # 30day
9
+ end
10
+
11
+ Devise.warden do |manager|
12
+ manager.failure_app = Ibrain::Auth::FailureApp
5
13
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ibrain::Auth::FailureApp < Devise::FailureApp
4
+ include ActionController::Helpers
5
+
6
+ def respond
7
+ json_error_response
8
+ end
9
+
10
+ def json_error_response
11
+ self.status = 401
12
+ self.content_type = "application/json"
13
+ self.response_body = {
14
+ errors: [{
15
+ message: i18n_message,
16
+ extensions: {
17
+ code: 401,
18
+ exception: {
19
+ stacktrace: []
20
+ }
21
+ }
22
+ }],
23
+ message: i18n_message,
24
+ data: nil
25
+ }.to_json
26
+ end
27
+ end
@@ -4,14 +4,14 @@ module Ibrain
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module Auth
7
- VERSION = '0.1.2'
7
+ VERSION = '0.1.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.1.1'
14
+ '0.1.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.1.2
4
+ version: 0.1.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-01-04 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.8
75
+ version: 0.2.4
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.8
82
+ version: 0.2.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +132,7 @@ files:
132
132
  - app/graphql/ibrain/auth/mutations/base_mutation.rb
133
133
  - app/graphql/ibrain/auth/mutations/sign_in_mutation.rb
134
134
  - app/graphql/ibrain/auth/mutations/sign_out_mutation.rb
135
+ - app/graphql/ibrain/auth/mutations/sso_sign_in_mutation.rb
135
136
  - app/models/ibrain/auth/user.rb
136
137
  - app/repositories/auth_repository.rb
137
138
  - config/initializers/devise.rb
@@ -148,6 +149,7 @@ files:
148
149
  - lib/ibrain/auth.rb
149
150
  - lib/ibrain/auth/devise.rb
150
151
  - lib/ibrain/auth/engine.rb
152
+ - lib/ibrain/auth/failure_app.rb
151
153
  - lib/ibrain/auth/version.rb
152
154
  - lib/ibrain/auth_configuration.rb
153
155
  - lib/ibrain/authentication_helpers.rb