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: 6f42b6fcf4138560f8e183c7f02e10854836f7e04247bbe8bb96cdf3b3299324
4
- data.tar.gz: 1ea8b0e0819840b9f443c06d77f5b175c510085ea435aed509968bf87f2cf2ef
3
+ metadata.gz: aa5e1a3c1035f1a2c765dfc5969845af3c80d70a2e0063e2f42b140b636b751a
4
+ data.tar.gz: 461d22a194727f614e60227f2ed886b0f8fe92e27a984ed13e8b33f5e73db2e8
5
5
  SHA512:
6
- metadata.gz: dcb26da2904c349a2749d30ec86011b2712847c0fbfd7577bbc02bcb549e1d2bc05425c5beb609c62784dae0ae3f25a2272a240707ec9647d5e8f3a97c59034a
7
- data.tar.gz: e4f5477ef79bfe582465ba72a25b984b248d9a2f0b28bf35ad16e4dca4ad104eaa96bd1487df95b0ad7476593544a0fef8c010418b99d6bffc7f8b2012972baa
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
- if !args.email.blank? && !args.password.blank?
11
- @email = args.email
12
- @password = args.password
13
- elsif !args.access_token.blank?
14
- @access_token = args.access_token
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
- if !api_user.blank? && result = JsonWebToken.encode(user_id: api_user.id)
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(valid: false)
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)
@@ -1,7 +1,3 @@
1
1
  class UsedToken < ApplicationRecord
2
2
  belongs_to :user, inverse_of: :used_tokens
3
-
4
- rails_admin do
5
- visible false
6
- end
7
3
  end
data/config/routes.rb CHANGED
@@ -12,6 +12,7 @@ Rails.application.routes.draw do
12
12
  get :translations
13
13
  get :schema
14
14
  get :dsl
15
+ get :heartbeat
15
16
  end
16
17
 
17
18
  post "authenticate" => "authentication#authenticate"
@@ -0,0 +1,7 @@
1
+ class RenameValidToIsValidInUsedToken < ActiveRecord::Migration[6.0]
2
+ def change
3
+ change_table :used_tokens do |t|
4
+ t.rename :valid, :is_valid
5
+ end
6
+ end
7
+ end
@@ -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, valid: true)
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.16
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