model_driven_api 2.3.16 → 2.3.17
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa5e1a3c1035f1a2c765dfc5969845af3c80d70a2e0063e2f42b140b636b751a
|
4
|
+
data.tar.gz: 461d22a194727f614e60227f2ed886b0f8fe92e27a984ed13e8b33f5e73db2e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a401038c58d3bf9386e5020b4552040a013c5c6867c2df16ae831ebaf90ae7c22a0ed75187bd2f09fcadf00d48958ec314e288fe74767471d2432eaef6f95e39
|
7
|
+
data.tar.gz: 4b03ebfbc44d9158198f1a455a5a294a5436e31af3488714b0a0fd153771aa38f2907d613a4b76a552dcbf463a6c6969821bac3a79a77e4777fd0be5b86dc745
|
@@ -7,20 +7,22 @@ class AuthenticateUser
|
|
7
7
|
prepend SimpleCommand
|
8
8
|
|
9
9
|
def initialize(*args)
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
10
|
+
first_arg = args.first
|
11
|
+
if !first_arg[:email].blank? && !first_arg[:password].blank?
|
12
|
+
@email = first_arg[:email]
|
13
|
+
@password = first_arg[:password]
|
14
|
+
elsif !first_arg[:access_token].blank?
|
15
|
+
@access_token = first_arg[:access_token]
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def call
|
19
|
-
|
20
|
+
current_u = api_user
|
21
|
+
if !current_u.blank? && result = JsonWebToken.encode(user_id: current_u.id)
|
20
22
|
# The token is created and the api_user exists => Invalidating all the previous tokens
|
21
23
|
# Since this is a new login and I don't care from where it comes, new logins always
|
22
24
|
# Invalidate older tokens
|
23
|
-
UsedToken.where(user_id: api_user.id).update(
|
25
|
+
UsedToken.where(user_id: api_user.id).update(is_valid: false) if ENV["ALLOW_MULTISESSIONS"] == "false"
|
24
26
|
return result
|
25
27
|
end
|
26
28
|
nil
|
@@ -33,8 +35,7 @@ class AuthenticateUser
|
|
33
35
|
def api_user
|
34
36
|
if !email.blank? && !password.blank?
|
35
37
|
user = User.find_by(email: email)
|
36
|
-
|
37
|
-
# Verify the password. You can create a blank method for now.
|
38
|
+
# Verify the password.
|
38
39
|
raise AccessDenied if user.blank? && user.authenticate(password).blank?
|
39
40
|
elsif !access_token.blank?
|
40
41
|
user = User.find_by(access_token: access_token)
|
data/app/models/used_token.rb
CHANGED
data/config/routes.rb
CHANGED
data/lib/json_web_token.rb
CHANGED
@@ -9,7 +9,7 @@ class JsonWebToken
|
|
9
9
|
|
10
10
|
def decode(token)
|
11
11
|
# Check if the passed token is present and valid into the UsedToken
|
12
|
-
raise "Token is invalidated by new login" unless UsedToken.exists?(token: token,
|
12
|
+
raise "Token is invalidated by new login" unless UsedToken.exists?(token: token, is_valid: true)
|
13
13
|
body = ::JWT.decode(token, ::Rails.application.credentials.dig(:secret_key_base).presence||ENV["SECRET_KEY_BASE"])[0]
|
14
14
|
::HashWithIndifferentAccess.new body
|
15
15
|
rescue
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_driven_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- config/initializers/wrap_parameters.rb
|
148
148
|
- config/routes.rb
|
149
149
|
- db/migrate/20210519145438_create_used_tokens.rb
|
150
|
+
- db/migrate/20210528111450_rename_valid_to_is_valid_in_used_token.rb
|
150
151
|
- lib/concerns/api_exception_management.rb
|
151
152
|
- lib/concerns/model_driven_api_role.rb
|
152
153
|
- lib/concerns/model_driven_api_user.rb
|