From ed354dbf85d1064f18fa4a14cc393985ec86ff96 Mon Sep 17 00:00:00 2001
From: florenttorregrosa <florenttorregrosa@2388214.no-reply.drupal.org>
Date: Wed, 22 Feb 2017 15:35:35 +0100
Subject: [PATCH] Issue #2790935 by e0ipso, Wim Leers, Grimreaper:
 fix(Authentification) Create an entry point to ensure true HATEOAS

---
 jsonapi.routing.yml    | 10 +---------
 src/Routing/Routes.php | 25 +++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/jsonapi.routing.yml b/jsonapi.routing.yml
index b2441d2..f4d060c 100644
--- a/jsonapi.routing.yml
+++ b/jsonapi.routing.yml
@@ -1,11 +1,3 @@
 route_callbacks:
+  - '\Drupal\jsonapi\Routing\Routes::entryPoint'
   - '\Drupal\jsonapi\Routing\Routes::routes'
-
-jsonapi.resource_list:
-  path: '/jsonapi'
-  defaults:
-    _controller: 'Drupal\jsonapi\Controller\EntryPoint::index'
-  methods: [GET]
-  requirements:
-    _permission: 'access jsonapi resource list'
-    _format: 'api_json'
diff --git a/src/Routing/Routes.php b/src/Routing/Routes.php
index 8a8cacc..1eaad6f 100644
--- a/src/Routing/Routes.php
+++ b/src/Routing/Routes.php
@@ -75,6 +75,31 @@ class Routes implements ContainerInjectionInterface {
   }
 
   /**
+   * Provides the entry point route.
+   */
+  public function entryPoint() {
+    $collection = new RouteCollection();
+
+    $route_base_path = '/jsonapi';
+    $defaults = [
+      RouteObjectInterface::CONTROLLER_NAME => '\Drupal\jsonapi\Controller\EntryPoint::index',
+    ];
+    // Options that apply to all routes.
+    $options = [
+      '_auth' => $this->authProviderList(),
+      '_is_jsonapi' => TRUE,
+    ];
+    $route_collection = (new Route($route_base_path, $defaults))
+      ->setRequirement('_permission', 'access jsonapi resource list')
+      ->setRequirement('_format', 'api_json')
+      ->setMethods(['GET']);
+    $route_collection->addOptions($options);
+    $collection->add('jsonapi.resource_list', $route_collection);
+
+    return $collection;
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function routes() {
-- 
1.9.1

