Edit
I found a method that works for me.
<?php
namespace Drupal\modulename\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
* https://www.drupal.org/docs/8/api/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones
*/
class ModuleNameRouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
//issue is this only works for JUST /rahapi and not anything else
//if ( $route = $collection->get('jsonapi.resource_list') ) {
// $route->setRequirement('_user_is_logged_in', 'TRUE');
//}
foreach ($collection->all() as $route) {
if (strpos($route->getPath(), '/jsonapi') === 0 ) {
$route->setRequirement('_user_is_logged_in', 'TRUE');
}
}
}
}
That goes in modulename/src/Routing/ModuleNameRouteSubscriber.php
Then this goes in modulename/modulename.services.yml
services:
route_subscriber:
class: Drupal\modulename\Routing\ModuleNameRouteSubscriber
arguments: []
tags:
- { name: event_subscriber }
So I found it by going here:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Routing%21RouteSubscriberBase.php/class/RouteSubscriberBase/8.2.x
So I'm extending that... and I see there are many other things that extend it. Like this one for /admin. So I did monkey-see-monkey-do and generated the code above. I hope my sample code works for you.
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21EventSubscriber%21AdminRouteSubscriber.php/function/AdminRouteSubscriber%3A%3AalterRoutes/8.2.x
Thank you zaporylie for pointing me in the initial direction.
Token no longer valid
coming from either one of two modules you've mentioned. Not even from underlaying composer dependencies. Can you verify that there is no custom code that subscribes to the kernel request and returns 200 withToken no longer valid
message?200 ok
, and it's only visible in the meta data that there is a problem./jsonapi/user/user
) you get emptydata
array andmeta
full of errors? And if it's not a collection which gives you the unexpected outcome, can you specify which resource provides invalid status code?/jsonapi/user/user
(for example) I receive an emptydata
andmeta
full of errors while the status is200 ok
. I've tested this with postman and our front-end colleagues had the same while testing in their application.