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 +4 -4
- data/app/graphql/ibrain/auth/mutations/sign_in_mutation.rb +10 -8
- data/app/graphql/ibrain/auth/mutations/sso_sign_in_mutation.rb +46 -0
- data/config/locales/en.yml +2 -1
- data/config/locales/jp.yml +2 -1
- data/config/locales/vi.yml +2 -1
- data/lib/generators/ibrain/auth/install/templates/config/initializers/ibrain_jwt.rb.tt +8 -0
- data/lib/ibrain/auth/failure_app.rb +27 -0
- data/lib/ibrain/auth/version.rb +2 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32b449c2e6da655c6a1370d8a959e445b7033a0796412eaf1d56c262cf631208
|
4
|
+
data.tar.gz: 608b6cf7576707a109fe770135fc21c9fc68ec8c1cbef033fa8ac56ea8b11829
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
-
|
22
|
-
|
19
|
+
sign_in(resource_name, user)
|
20
|
+
@current_user = warden.authenticate!(auth_options)
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
data/config/locales/en.yml
CHANGED
data/config/locales/jp.yml
CHANGED
data/config/locales/vi.yml
CHANGED
@@ -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
|
data/lib/ibrain/auth/version.rb
CHANGED
@@ -4,14 +4,14 @@ module Ibrain
|
|
4
4
|
# frozen_string_literal: true
|
5
5
|
|
6
6
|
module Auth
|
7
|
-
VERSION = '0.1.
|
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.
|
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.
|
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-
|
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.
|
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.
|
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
|