ibrain-auth 0.1.2 → 0.1.3

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: fcdfb62a4e32fec1df4cf5e882f89f3d730d13173aed46ffef0b64b5159bca73
4
- data.tar.gz: 378ee6aeffa8fab93a6bff8ad971b598a55225f622cca251698b06a3662682e7
3
+ metadata.gz: 8beb80a1714ee5b7c3ec02814d39e2ae186648b42d9a2bc825882203275f051d
4
+ data.tar.gz: d1d6c607cb8260a4d8f1fa6b36f4098ed98a19d237f48a4191f6c1a0c00d49be
5
5
  SHA512:
6
- metadata.gz: 786e29e47ed31f9560cfe07bfc2ef8d8dd712e33eef3b7c2845605209796b8ed0aedd6f946fa9cab4518c3bd9850330ada1f8854cf3e7a6d2d6fe84d08ae2d59
7
- data.tar.gz: 3125c892362bd7286f7353b3976a6729a0f58866c30cb74a5ac4dbe67e8d851130dd1225457c66569937b6b780ef1bb890f4d05ceb278757fde9504889564a5a
6
+ metadata.gz: 917de92b8fd15175a62b1e4bc5098ac6529d01e3dceb611c951c00f79bd81054f6febecb25b5b29c3b6efede2825adcbc4025f049f718ebe1d6431645e221a29
7
+ data.tar.gz: 7d7bde52fb6a18262a88fa4fe2b3b933f1f8e054ce63ee89ea1e87a99316ef832dfa40f30e74324142f5e8d3830c9997ef169176ddffed1ce97fe55d7d29ff94
@@ -14,16 +14,16 @@ 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
27
 
28
28
  OpenStruct.new(
29
29
  user: user_signed_in? ? current_user : nil,
@@ -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.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.1.1'
14
+ '0.1.2'
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.3
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-05 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.1.9
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.1.9
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +148,7 @@ files:
148
148
  - lib/ibrain/auth.rb
149
149
  - lib/ibrain/auth/devise.rb
150
150
  - lib/ibrain/auth/engine.rb
151
+ - lib/ibrain/auth/failure_app.rb
151
152
  - lib/ibrain/auth/version.rb
152
153
  - lib/ibrain/auth_configuration.rb
153
154
  - lib/ibrain/authentication_helpers.rb