From a4f5f357c491273f3e7fcc4b7280256ddecbdaf7 Mon Sep 17 00:00:00 2001
From: Kyle Browning <kylebrowning@me.com>
Date: Wed, 15 Jan 2014 11:31:22 -0800
Subject: [PATCH] fixes authentication settings tests

---
 includes/services.runtime.inc               | 13 +++++++++++--
 servers/rest_server/includes/RESTServer.inc |  6 ++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/includes/services.runtime.inc b/includes/services.runtime.inc
index 9cdf864..503a43a 100644
--- a/includes/services.runtime.inc
+++ b/includes/services.runtime.inc
@@ -410,9 +410,18 @@ function _services_access_value($data, $fields) {
  */
 function _services_authenticate_user($controller, $endpoint, $args, $options) {
   if (!isset($options['skip_authentication']) || !$options['skip_authentication']) {
+  debug($endpoint->authentication);
     foreach ($endpoint->authentication as $auth_module => $auth_settings) {
-      if (!empty($auth_settings) && $auth_error = services_auth_invoke($auth_module, 'authenticate_call', $auth_settings, $controller, $args)) {
-        return services_error($auth_error, 401);
+      if (!empty($auth_settings)) {
+        // Add in the auth module's endpoint settings if present.
+        if (isset($controller['endpoint'][$auth_module])) {
+          if(is_array($auth_settings)) {
+              $auth_settings += $controller['endpoint'][$auth_module];
+          }
+        }
+        if ($auth_error = services_auth_invoke($auth_module, 'authenticate_call', $auth_settings, $controller, $args)) {
+          return services_error($auth_error, 401);
+        }
       }
     }
   }
diff --git a/servers/rest_server/includes/RESTServer.inc b/servers/rest_server/includes/RESTServer.inc
index d3d7093..62b6dd0 100755
--- a/servers/rest_server/includes/RESTServer.inc
+++ b/servers/rest_server/includes/RESTServer.inc
@@ -588,6 +588,12 @@ class RESTServer {
     }
 
     $controller = $resource[$operation_type][$operation];
+
+    if (isset($resource['endpoint']['operations'][$operation]['settings'])) {
+      // Add the endpoint's settings for the specified operation.
+      $controller['endpoint'] = $resource['endpoint']['operations'][$operation]['settings'];
+    }
+
     if (isset($resource['file']) && empty($controller['file'])) {
       $controller['file'] = $resource['file'];
     }
-- 
1.8.3.4 (Apple Git-47)

