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
| Comment | File | Size | Author |
|---|---|---|---|
| views.view_.api_test_simple_oauth.yml | 4.87 KB | niekheezemans | |
| views.view_.api_test_export_user_auth.yml | 4.88 KB | niekheezemans |
Comments
Comment #2
niekheezemans commentedUpdated to the rest.module instead of the views.module
Comment #3
wim leersThanks for reporting this! I think the steps to reproduce are clear. I'll ping the Simple OAuth module maintainer to try to reproduce this.
Comment #4
dawehnerThis sounds really similar to #2825204: REST views: authentication is broken for me
Comment #5
wim leersRiiiight! I knew it sounded familiar!
Comment #6
dongen1289 commentedHi, I'm having the exact same problem in Drupal 8.4.0 and Simple_auth. Not sure to log it here or with simple.
when trying to add 'simple_oauth' as authentication provider to the view error is:
if continuing despite error the API reports that the authentication method is not supported for the end point.
Driving me nuts. How can I fix??
Comment #7
adrianpintilie commentedWim, I am not sure is related. That issue talks about the export. The current bug is actually different. simple_oauth doesn't work with REST Views.
Comment #8
adrianpintilie commentedApplying this patch fixes the issue: https://www.drupal.org/node/2825204#comment-12306027
Comment #9
dawehnerNote: we would need an update written for simple_oauth as well ...
Comment #10
wim leersThanks, @adrianpintilie, for confirming that #2825204: REST views: authentication is broken fixes the problem.
@dawehner: why?