@@ -16,38 +16,44 @@ module Auth
16
16
# @param headers [Hash] The request headers.
17
17
# @param endpoint_config [Hash] The endpoint configuration, must include :auth key.
18
18
# @param global_config [Hash] The global configuration (optional, for compatibility).
19
+ # @param request_context [Hash] Context for the request, e.g. request ID, path, handler (optional).
19
20
# @raise [StandardError] Raises error if authentication fails or is misconfigured.
20
21
# @return [void]
21
22
# @note This method will halt execution with an error if authentication fails.
22
- def validate_auth! ( payload , headers , endpoint_config , global_config = { } )
23
+ def validate_auth! ( payload , headers , endpoint_config , global_config = { } , request_context = { } )
23
24
auth_config = endpoint_config [ :auth ]
25
+ request_id = request_context &.dig ( :request_id )
24
26
25
27
# Ensure auth type is present and valid
26
28
auth_type = auth_config &.dig ( :type )
27
29
unless auth_type &.is_a? ( String ) && !auth_type . strip . empty?
30
+ log . error ( "authentication configuration missing or invalid - request_id: #{ request_id } " )
28
31
error! ( {
29
32
error : "authentication_configuration_error" ,
30
- message : "authentication configuration missing or invalid"
33
+ message : "authentication configuration missing or invalid" ,
34
+ request_id :
31
35
} , 500 )
32
36
end
33
37
34
38
# Get auth plugin from loaded plugins registry (boot-time loaded only)
35
39
begin
36
40
auth_class = Core ::PluginLoader . get_auth_plugin ( auth_type )
37
41
rescue => e
38
- log . error ( "failed to load auth plugin '#{ auth_type } ': #{ e . message } " )
42
+ log . error ( "failed to load auth plugin '#{ auth_type } ': #{ e . message } - request_id: #{ request_id } " )
39
43
error! ( {
40
44
error : "authentication_plugin_error" ,
41
- message : "unsupported auth type '#{ auth_type } '"
45
+ message : "unsupported auth type '#{ auth_type } '" ,
46
+ request_id :
42
47
} , 400 )
43
48
end
44
49
45
50
log . debug ( "validating auth for request with auth_class: #{ auth_class . name } " )
46
51
unless auth_class . valid? ( payload :, headers :, config : endpoint_config )
47
- log . warn ( "authentication failed for request with auth_class: #{ auth_class . name } " )
52
+ log . warn ( "authentication failed for request with auth_class: #{ auth_class . name } - request_id: #{ request_id } " )
48
53
error! ( {
49
54
error : "authentication_failed" ,
50
- message : "authentication failed"
55
+ message : "authentication failed" ,
56
+ request_id :
51
57
} , 401 )
52
58
end
53
59
end
0 commit comments