model_driven_api 3.2.6 → 3.2.8

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: b97e79e1bc34847a05fd1c9ac004c0f64d15203b2a803d176559bfdcc2b3cf4e
4
- data.tar.gz: 6c48764ef66785db7b5793bd0bde4526233f39ae10650ec76c98799f0ac5efef
3
+ metadata.gz: 66f79849229a707224dc7cfdb61e3cb53995e2ba6e4b01c7485f9b1115791dfb
4
+ data.tar.gz: d5ba4ba9e7e4c0d750683c230e63d3f3d9f7785c64e4fee8da96f06ea52dc1b5
5
5
  SHA512:
6
- metadata.gz: 925b9065f28afcfa64652a4262eccf1ad59f829c153f8b9950653331857c9020649633be0590e18c7acfe29aafa06118c839cbbce3e993085c77f98d4d7c4e59
7
- data.tar.gz: 2ae0d12d73b4c23113d0f98d1829adf4e35ea8a29fa0370d7d7fdd0f8fae5fe3dfcbfab33a7bbd6e0b6a97b9e5a9c431bdcdef403114b2f1846d06a50f701fc9
6
+ metadata.gz: '0578ec016dc2dd7fcee4eef1fed2fcd765ed13a9a1391383911fbeb336b2a8654efee5d043a3a803dd2af83440a83048315b9034873bd19f155bd3326f4d51ae'
7
+ data.tar.gz: 484370bc4395eeb5782180875f470784ca02dcf1b3431da82e491b21545aef86f2d254744fbbe5be5675f09dd2e30ed85ceb77051c9d78cd7b40dfe731015c3a
@@ -14,17 +14,28 @@ class AuthorizeApiRequest
14
14
  attr_reader :headers
15
15
 
16
16
  def api_user
17
+ Rails.logger.debug "AuthorizeApiRequest: api_user -> #{decoded_auth_token}"
17
18
  @api_user ||= User.find(decoded_auth_token[:user_id]) if decoded_auth_token
18
- @api_user || errors.add(:token, "Invalid token") && nil
19
+ if @api_user
20
+ return @api_user
21
+ else
22
+ errors.add(:token, "Invalid token")
23
+ return nil
24
+ end
19
25
  end
20
26
 
21
27
  def decoded_auth_token
28
+ Rails.logger.debug "AuthorizeApiRequest: http_auth_header -> #{http_auth_header}"
22
29
  @decoded_auth_token ||= JsonWebToken.decode(http_auth_header)
30
+ @decoded_auth_token
23
31
  end
24
32
 
25
33
  def http_auth_header
34
+ Rails.logger.debug "AuthorizeApiRequest: Authorization -> #{headers['Authorization']}"
26
35
  if headers['Authorization'].present?
27
- return headers['Authorization'].split(' ').last
36
+ token = headers['Authorization'].split(' ').last
37
+ Rails.logger.debug "AuthorizeApiRequest: token -> #{token}"
38
+ return token
28
39
  else
29
40
  errors.add(:token, "Missing token")
30
41
  end
@@ -195,9 +195,11 @@ class Api::V2::ApplicationController < ActionController::API
195
195
  @current_user = nil
196
196
  Settings.ns(:security).allowed_authorization_headers.split(",").each do |header|
197
197
  # puts "Found header #{header}: #{request.headers[header]}"
198
- check_authorization("Authorize#{header}".constantize.call(request))
198
+ check_authorization("Authorize#{header}".constantize.call(request)) unless @current_user
199
199
  end
200
200
 
201
+ Rails.logger.debug("Checking for authorization with AuthorizeApiRequest if current_user not already present -> current_user: #{@current_user}")
202
+
201
203
  check_authorization AuthorizeApiRequest.call(request) unless @current_user
202
204
  return unauthenticated!(OpenStruct.new({ message: @auth_errors })) unless @current_user
203
205
 
@@ -240,6 +242,7 @@ class Api::V2::ApplicationController < ActionController::API
240
242
  end
241
243
 
242
244
  def check_authorization(cmd)
245
+ Rails.logger.debug("Checking authorization: #{cmd.inspect}")
243
246
  if cmd.success?
244
247
  @current_user = cmd.result
245
248
  else
data/config/routes.rb CHANGED
@@ -2,53 +2,56 @@
2
2
 
3
3
  Rails.application.routes.draw do
4
4
  # REST API (Stateless)
5
- namespace :api, constraints: { format: :json } do
6
- namespace :v2 do
7
- resources :users
8
5
 
9
- namespace :info do
10
- get :version
11
- get :roles
12
- get :translations
13
- get :schema
14
- get :dsl
15
- get :heartbeat
16
- get :settings
17
- get :swagger
18
- get :openapi
19
- end
6
+ scope ENV.fetch("RAILS_RELATIVE_URL_ROOT", "/") do
7
+ namespace :api, constraints: { format: :json } do
8
+ namespace :v2 do
9
+ resources :users
20
10
 
21
- namespace :raw do
22
- post :sql
23
- end
11
+ namespace :info do
12
+ get :version
13
+ get :roles
14
+ get :translations
15
+ get :schema
16
+ get :dsl
17
+ get :heartbeat
18
+ get :settings
19
+ get :swagger
20
+ get :openapi
21
+ end
24
22
 
25
- post "authenticate" => "authentication#authenticate"
26
- post ":ctrl/search" => 'application#index'
23
+ namespace :raw do
24
+ post :sql
25
+ end
27
26
 
28
- # Add a route with placeholders for custom actions, the custom actions routes have a form like: :ctrl/custom_action/:action_name or :ctrl/custom_action/:action_name/:id
29
- # Can have all the verbs, but the most common are: get, post, put, delete
30
- get ":ctrl/custom_action/:action_name", to: 'application#index'
31
- get ":ctrl/custom_action/:action_name/:id", to: 'application#show'
32
- post ":ctrl/custom_action/:action_name", to: 'application#create'
33
- put ":ctrl/custom_action/:action_name/:id", to: 'application#update'
34
- patch ":ctrl/custom_action/:action_name/:id", to: 'application#update'
35
- delete ":ctrl/custom_action/:action_name/:id", to: 'application#destroy'
36
- # Catchall routes
37
- # # CRUD Show
38
- get '*path/:id', to: 'application#show'
39
- # # CRUD Index
40
- get '*path', to: 'application#index'
41
- # # CRUD Create
42
- post '*path', to: 'application#create'
43
- # CRUD Update
44
- put '*path/:id/multi', to: 'application#update_multi'
45
- patch '*path/:id/multi', to: 'application#update_multi'
46
- put '*path/:id', to: 'application#update'
47
- patch '*path/:id', to: 'application#patch'
27
+ post "authenticate" => "authentication#authenticate"
28
+ post ":ctrl/search" => 'application#index'
48
29
 
49
- # # CRUD Delete
50
- delete '*path/:id/multi', to: 'application#destroy_multi'
51
- delete '*path/:id', to: 'application#destroy'
30
+ # Add a route with placeholders for custom actions, the custom actions routes have a form like: :ctrl/custom_action/:action_name or :ctrl/custom_action/:action_name/:id
31
+ # Can have all the verbs, but the most common are: get, post, put, delete
32
+ get ":ctrl/custom_action/:action_name", to: 'application#index'
33
+ get ":ctrl/custom_action/:action_name/:id", to: 'application#show'
34
+ post ":ctrl/custom_action/:action_name", to: 'application#create'
35
+ put ":ctrl/custom_action/:action_name/:id", to: 'application#update'
36
+ patch ":ctrl/custom_action/:action_name/:id", to: 'application#update'
37
+ delete ":ctrl/custom_action/:action_name/:id", to: 'application#destroy'
38
+ # Catchall routes
39
+ # # CRUD Show
40
+ get '*path/:id', to: 'application#show'
41
+ # # CRUD Index
42
+ get '*path', to: 'application#index'
43
+ # # CRUD Create
44
+ post '*path', to: 'application#create'
45
+ # CRUD Update
46
+ put '*path/:id/multi', to: 'application#update_multi'
47
+ patch '*path/:id/multi', to: 'application#update_multi'
48
+ put '*path/:id', to: 'application#update'
49
+ patch '*path/:id', to: 'application#patch'
50
+
51
+ # # CRUD Delete
52
+ delete '*path/:id/multi', to: 'application#destroy_multi'
53
+ delete '*path/:id', to: 'application#destroy'
54
+ end
52
55
  end
53
56
  end
54
57
  end
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.2.6".freeze
2
+ VERSION = "3.2.8".freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-14 00:00:00.000000000 Z
10
+ date: 2025-02-12 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thecore_backend_commons