22
33namespace Drupal \graphql \Routing ;
44
5+ use Drupal \Core \Authentication \AuthenticationCollectorInterface ;
56use Drupal \Core \Routing \RouteSubscriberBase ;
67use Drupal \graphql \Plugin \SchemaPluginManager ;
78use Symfony \Component \Routing \Route ;
@@ -19,14 +20,24 @@ class QueryRoutes extends RouteSubscriberBase {
1920 */
2021 protected $ schemaManager ;
2122
23+ /**
24+ * The authentication collector.
25+ *
26+ * @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
27+ */
28+ protected $ authenticationCollector ;
29+
2230 /**
2331 * QueryRoutes constructor.
2432 *
2533 * @param \Drupal\graphql\Plugin\SchemaPluginManager $schemaManager
2634 * The graphql schema plugin manager.
35+ * @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
36+ * The authentication collector.
2737 */
28- public function __construct (SchemaPluginManager $ schemaManager ) {
38+ public function __construct (SchemaPluginManager $ schemaManager, AuthenticationCollectorInterface $ authenticationCollector ) {
2939 $ this ->schemaManager = $ schemaManager ;
40+ $ this ->authenticationCollector = $ authenticationCollector ;
3041 }
3142
3243 /**
@@ -37,6 +48,8 @@ public function __construct(SchemaPluginManager $schemaManager) {
3748 */
3849 protected function alterRoutes (RouteCollection $ collection ) {
3950 $ routes = new RouteCollection ();
51+ $ providers = $ this ->authenticationCollector ->getSortedProviders ();
52+ $ providerIds = array_keys ($ providers );
4053
4154 foreach ($ this ->schemaManager ->getDefinitions () as $ key => $ definition ) {
4255 $ routes ->add ("graphql.query. $ key " , new Route ($ definition ['path ' ], [
@@ -47,7 +60,7 @@ protected function alterRoutes(RouteCollection $collection) {
4760 ], [
4861 '_graphql_query_access ' => 'TRUE ' ,
4962 ], [
50- '_auth ' => [ ' basic_auth ' , ' cookie ' ] ,
63+ '_auth ' => $ providerIds ,
5164 ]));
5265 }
5366
0 commit comments