Skip to content

Commit 0f7d859

Browse files
acha5066fubhy
authored andcommitted
Fix broken authentication (#774)
1 parent 53f63ca commit 0f7d859

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

graphql.services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ services:
6767

6868
graphql.query_routes:
6969
class: Drupal\graphql\Routing\QueryRoutes
70-
arguments: ['@plugin.manager.graphql.schema']
70+
arguments: ['@plugin.manager.graphql.schema', '@authentication_collector']
7171
tags:
7272
- { name: 'event_subscriber' }
7373

src/Routing/QueryRoutes.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\graphql\Routing;
44

5+
use Drupal\Core\Authentication\AuthenticationCollectorInterface;
56
use Drupal\Core\Routing\RouteSubscriberBase;
67
use Drupal\graphql\Plugin\SchemaPluginManager;
78
use 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

Comments
 (0)