@@ -16,38 +16,44 @@ module Auth
1616 # @param headers [Hash] The request headers.
1717 # @param endpoint_config [Hash] The endpoint configuration, must include :auth key.
1818 # @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).
1920 # @raise [StandardError] Raises error if authentication fails or is misconfigured.
2021 # @return [void]
2122 # @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 = { } )
2324 auth_config = endpoint_config [ :auth ]
25+ request_id = request_context &.dig ( :request_id )
2426
2527 # Ensure auth type is present and valid
2628 auth_type = auth_config &.dig ( :type )
2729 unless auth_type &.is_a? ( String ) && !auth_type . strip . empty?
30+ log . error ( "authentication configuration missing or invalid - request_id: #{ request_id } " )
2831 error! ( {
2932 error : "authentication_configuration_error" ,
30- message : "authentication configuration missing or invalid"
33+ message : "authentication configuration missing or invalid" ,
34+ request_id :
3135 } , 500 )
3236 end
3337
3438 # Get auth plugin from loaded plugins registry (boot-time loaded only)
3539 begin
3640 auth_class = Core ::PluginLoader . get_auth_plugin ( auth_type )
3741 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 } " )
3943 error! ( {
4044 error : "authentication_plugin_error" ,
41- message : "unsupported auth type '#{ auth_type } '"
45+ message : "unsupported auth type '#{ auth_type } '" ,
46+ request_id :
4247 } , 400 )
4348 end
4449
4550 log . debug ( "validating auth for request with auth_class: #{ auth_class . name } " )
4651 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 } " )
4853 error! ( {
4954 error : "authentication_failed" ,
50- message : "authentication failed"
55+ message : "authentication failed" ,
56+ request_id :
5157 } , 401 )
5258 end
5359 end
0 commit comments