model_driven_api 3.13.2 → 3.14.0
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/README.md +2 -0
- data/app/commands/authenticate_user.rb +3 -1
- data/app/commands/authorize_api_request.rb +2 -1
- data/app/controllers/api/v2/application_controller.rb +23 -2
- data/app/controllers/api/v2/auth/oauth_controller.rb +3 -2
- data/app/controllers/api/v3/application_controller.rb +6 -0
- data/lib/model_driven_api/version.rb +1 -1
- data/lib/model_driven_api.rb +3 -0
- metadata +22 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5052641c8f3fa980a3c9915cf68a648a01ac0ad4ef1408f9443a75548fdd97ea
|
|
4
|
+
data.tar.gz: 055bcd8c2c8a12f4d759872e7f773d696376de7b3807f78e2f7dd460566b2f77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63ec03f80e8edf607afd307872d6f341aff0e0fa0ed20e73d96bb7f60bcde09a7c00a8f8cae8c8eb9a50a71a9fbda6d249481414d73c0acdf25e181fbc003b9c
|
|
7
|
+
data.tar.gz: d254e5ea911993a3e677ce0ea8de5bb1621d0c890949fae6cb3a38cc76315addbd03580790ff8043e72e07cfb0a367078a973e02c4c3f78e3eaa34ada817cf4c
|
data/README.md
CHANGED
|
@@ -82,6 +82,8 @@ Every subsequent authenticated request returns a fresh `Token` header (sliding e
|
|
|
82
82
|
|
|
83
83
|
Token expiry is controlled by the `SESSION_TIMEOUT_IN_MINUTES` env var (default: 31 minutes).
|
|
84
84
|
|
|
85
|
+
A locked user (`users.locked`) gets the same answer as a wrong password, and a token issued before the lock answers `401` and is not renewed.
|
|
86
|
+
|
|
85
87
|
When `ALLOW_MULTISESSIONS=false`, each login invalidates all previous tokens for the user (stored in the `used_tokens` table).
|
|
86
88
|
|
|
87
89
|
### Bearer token usage (v2 and v3)
|
|
@@ -40,7 +40,9 @@ class AuthenticateUser
|
|
|
40
40
|
#Try to authenticate the user against LDAP if user is not present at this point
|
|
41
41
|
user = Ldap::Authenticator.new(email: email, password: password).authenticate if user.blank?
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
# A locked user is refused like a wrong password, whichever way they authenticated
|
|
44
|
+
# (User#active_for_authentication?, thecore_auth_commons; Odoo #6051).
|
|
45
|
+
raise AccessDenied unless user.present? && user.active_for_authentication?
|
|
44
46
|
|
|
45
47
|
return user
|
|
46
48
|
end
|
|
@@ -16,7 +16,8 @@ class AuthorizeApiRequest
|
|
|
16
16
|
def api_user
|
|
17
17
|
Rails.logger.debug "AuthorizeApiRequest: api_user -> #{decoded_auth_token}"
|
|
18
18
|
@api_user ||= (decoded_auth_token.blank? ? nil : User.find(decoded_auth_token[:user_id]))
|
|
19
|
-
|
|
19
|
+
# A JWT still valid from before a lock gets no answer and no renewed token (Odoo #6051).
|
|
20
|
+
if @api_user.present? && @api_user.active_for_authentication?
|
|
20
21
|
return @api_user
|
|
21
22
|
else
|
|
22
23
|
errors.add(:token, "Invalid or Expired token")
|
|
@@ -9,6 +9,9 @@ class Api::V2::ApplicationController < ActionController::API
|
|
|
9
9
|
|
|
10
10
|
before_action :authenticate_request
|
|
11
11
|
before_action :extract_model
|
|
12
|
+
# Before anything is saved: create, update and custom actions read json_attrs only after
|
|
13
|
+
# their side effects.
|
|
14
|
+
before_action :reject_non_hash_json_attrs, if: :reads_json_attrs?
|
|
12
15
|
before_action :find_record, only: [:show, :destroy, :update, :patch]
|
|
13
16
|
|
|
14
17
|
# GET :controller/
|
|
@@ -249,11 +252,29 @@ class Api::V2::ApplicationController < ActionController::API
|
|
|
249
252
|
render json: existing.to_json(json_attrs), status: 200
|
|
250
253
|
end
|
|
251
254
|
|
|
255
|
+
# The request parameters json_attrs reads its options from: `a` is the short alias.
|
|
256
|
+
JSON_ATTRS_PARAMS = %i[a json_attrs].freeze
|
|
257
|
+
|
|
258
|
+
# The actions that serialize through json_attrs: every custom action, and the CRUD ones that
|
|
259
|
+
# render the record(s). A new action calling json_attrs belongs here, or a scalar `a` 500s it.
|
|
260
|
+
def reads_json_attrs?
|
|
261
|
+
custom_action? || %w[index show create update patch].include?(action_name)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# `a` and `json_attrs` carry serialization options as a hash (?a[only][]=id); a scalar or an
|
|
265
|
+
# array answers 400 naming the parameter, in every environment (the ApiExceptionManagement
|
|
266
|
+
# handlers are production-only).
|
|
267
|
+
def reject_non_hash_json_attrs
|
|
268
|
+
name = JSON_ATTRS_PARAMS.find { |key| params[key].present? && !params[key].is_a?(Hash) }
|
|
269
|
+
api_error(status: 400, errors: "The #{name} parameter must be a hash, e.g. #{name}[only][]=id") if name
|
|
270
|
+
end
|
|
271
|
+
|
|
252
272
|
def json_attrs
|
|
253
273
|
# In order of importance: if you send the configuration via querystring you are ok
|
|
254
274
|
# has precedence over if you have setup the json_attrs in the model concern
|
|
255
|
-
|
|
256
|
-
from_params =
|
|
275
|
+
# (JSON_ATTRS_PARAMS order: json_attrs wins over a; reject_non_hash_json_attrs ran first).
|
|
276
|
+
from_params = nil
|
|
277
|
+
JSON_ATTRS_PARAMS.each { |key| from_params = params[key].deep_symbolize_keys if params[key].present? }
|
|
257
278
|
from_params.presence || @json_attrs.presence || @model.json_attrs.presence || {} rescue {}
|
|
258
279
|
end
|
|
259
280
|
|
|
@@ -11,7 +11,8 @@ module Api::V2::Auth
|
|
|
11
11
|
info.last_name,
|
|
12
12
|
auth.provider)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# A locked user gets the same answer as an unknown one (Odoo #6051).
|
|
15
|
+
unless user&.active_for_authentication?
|
|
15
16
|
render json: { error: "User not registered" }, status: :unauthorized
|
|
16
17
|
return
|
|
17
18
|
end
|
|
@@ -61,7 +62,7 @@ module Api::V2::Auth
|
|
|
61
62
|
email = user_info["mail"] || user_info["email"] || user_info["userPrincipalName"]
|
|
62
63
|
user = User.find_by(email: email)
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
unless user&.active_for_authentication?
|
|
65
66
|
return render json: { error: "User not registered" }, status: :unauthorized
|
|
66
67
|
end
|
|
67
68
|
|
|
@@ -65,6 +65,12 @@ class Api::V3::ApplicationController < Api::V2::ApplicationController
|
|
|
65
65
|
|
|
66
66
|
private
|
|
67
67
|
|
|
68
|
+
# v3 serializes through SerializerFactory and never reads `a`/`json_attrs`; only its custom
|
|
69
|
+
# actions (plain JSON, via check_for_custom_action) do.
|
|
70
|
+
def reads_json_attrs?
|
|
71
|
+
custom_action?
|
|
72
|
+
end
|
|
73
|
+
|
|
68
74
|
# v2's read check, with a JSON:API envelope.
|
|
69
75
|
def render_existing(existing)
|
|
70
76
|
authorize! :show, existing
|
data/lib/model_driven_api.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
require 'endpoint_validation_error'
|
|
2
2
|
require 'non_crud_endpoints'
|
|
3
|
+
# Its own runtime dependency (User#active_for_authentication?, check_user, Ldap::Authenticator):
|
|
4
|
+
# required here rather than trusted to come through thecore_backend_commons.
|
|
5
|
+
require 'thecore_auth_commons'
|
|
3
6
|
require 'thecore_backend_commons'
|
|
4
7
|
require 'rack/cors'
|
|
5
8
|
require 'ransack'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: model_driven_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriele Tassoni
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thecore_backend_commons
|
|
@@ -24,6 +24,26 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '3.8'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: thecore_auth_commons
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 3.7.0
|
|
34
|
+
- - "<"
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '4'
|
|
37
|
+
type: :runtime
|
|
38
|
+
prerelease: false
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 3.7.0
|
|
44
|
+
- - "<"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '4'
|
|
27
47
|
- !ruby/object:Gem::Dependency
|
|
28
48
|
name: jwt
|
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|