Skip to content

Commit 9663a46

Browse files
authored
Adding all authentication providers by default. (#837)
1 parent 16c5984 commit 9663a46

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

graphql.routing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ entity.graphql_server.delete_form:
6565
_admin_route: TRUE
6666

6767
route_callbacks:
68-
- '\Drupal\graphql\Routing\QueryRoutes::routes'
68+
- 'graphql.route_provider::routes'

graphql.services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ services:
6767
tags:
6868
- { name: route_enhancer }
6969

70+
# Handles the dynamic creation of routes (see graphql.routing.yml).
71+
graphql.route_provider:
72+
class: Drupal\graphql\Routing\QueryRouteProvider
73+
arguments: ['@authentication_collector']
74+
7075
# Schema introspection service.
7176
graphql.introspection:
7277
class: Drupal\graphql\GraphQL\Utility\Introspection
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,28 @@
22

33
namespace Drupal\graphql\Routing;
44

5+
use Drupal\Core\Authentication\AuthenticationCollectorInterface;
56
use Drupal\graphql\Entity\Server;
67
use Symfony\Component\Routing\Route;
78

8-
class QueryRoutes {
9+
class QueryRouteProvider {
10+
11+
/**
12+
* The authentication collector service.
13+
*
14+
* @var \Drupal\Core\Authentication\AuthenticationCollectorInterface
15+
*/
16+
protected $authenticationCollector;
17+
18+
/**
19+
* QueryRouteProvider constructor.
20+
*
21+
* @param \Drupal\Core\Authentication\AuthenticationCollectorInterface $authenticationCollector
22+
* The authentication collector service.
23+
*/
24+
public function __construct(AuthenticationCollectorInterface $authenticationCollector) {
25+
$this->authenticationCollector = $authenticationCollector;
26+
}
927

1028
/**
1129
* Collects routes for the server endpoints.
@@ -15,6 +33,9 @@ public function routes() {
1533
$servers = Server::loadMultiple();
1634
$routes = [];
1735

36+
// Allow all authentication providers by default.
37+
$auth = array_keys($this->authenticationCollector->getSortedProviders());
38+
1839
foreach ($servers as $id => $server) {
1940
$path = $server->get('endpoint');
2041

@@ -30,6 +51,7 @@ public function routes() {
3051
'_format' => 'json',
3152
])
3253
->addOptions([
54+
'_auth' => $auth,
3355
'no_cache' => TRUE,
3456
'default_url_options' => ['path_processing' => FALSE],
3557
'parameters' => ['server' => ['type' => 'entity:graphql_server']]

0 commit comments

Comments
 (0)