Hi,
When trying to secure any custom Views Rest Export (API) with other authentication methods than Basic Auth, the following error occurs:
User:
Notice: Undefined index: user in Drupal\rest\Plugin\views\display\RestExport->Drupal\rest\Plugin\views\display\{closure}() (line 460 of core/modules/rest/src/Plugin/views/display/RestExport.php).
Drupal\rest\Plugin\views\display\RestExport->Drupal\rest\Plugin\views\display\{closure}('user')
array_map(Object, Array) (Line: 461)
Drupal\rest\Plugin\views\display\RestExport->calculateDependencies() (Line: 47)
Simple OAuth:
Notice: Undefined index: simple_oauth in Drupal\rest\Plugin\views\display\RestExport->Drupal\rest\Plugin\views\display\{closure}() (line 460 of core/modules/rest/src/Plugin/views/display/RestExport.php).
Drupal\rest\Plugin\views\display\RestExport->Drupal\rest\Plugin\views\display\{closure}('simple_oauth')
array_map(Object, Array) (Line: 461)
Drupal\rest\Plugin\views\display\RestExport->calculateDependencies() (Line: 47)
This happens when you select the authentication method and save the view. I have attached to simple API-attachementsfor the Views Module.
It looks like the function calculateDependencies() in the RestExport.php is using the array values since array_map is used instead of the array_keys:
public function calculateDependencies() {
$dependencies = parent::calculateDependencies();
$dependencies += ['module' => []];
$modules = array_map(function ($authentication_provider) {
// @TODO: Remove - Search in the authenticationProviders for the key of the selected options
// @TODO: Remove - Uncomment Below to use the keys instead of the values
// $authentication_provider = array_search($authentication_provider, $this->authenticationProviders);
return $this->authenticationProviders[$authentication_provider];
}, $this->getOption('auth'));
$dependencies['module'] = array_merge($dependencies['module'], $modules);
return $dependencies;
}
When applying the fix above to use the array keys instead of the array values, unfortunately the API-route is still not accessible. The response from the API is:
{ "message": "The used authentication method is not allowed on this route."}
Am I missing something to activate the authentication on a custom route? Via Rest-UI I cannot grant access to this API