我正在尝试使用 Lighthouse 验证订阅(文档)
const pusher = new Pusher('blabla', {
cluster: 'eu',
forceTLS: true,
authEndpoint: 'https://app.test/graphql/subscriptions/auth',
auth: {
headers: {
Authorization: `Bearer blabla`
}
}
})
但是当我运行订阅查询时,我得到了这个
Unable to retrieve auth string from auth endpoint.
Received status 403 from https://app.test/graphql/subscriptions/auth.
Clients must be authenticated to join private or presence channels.
See: https://pusher.com/docs/authenticating_users
所以我决定顺其自然。
这是失败的地方:
//
// Nuwave\Lighthouse\Subscriptions > class Authorizer
//
public function authorize(Request $request): bool
$subscriber = $this->storage->subscriberByRequest(
$request->input(),
$request->headers->all()
);
// "$subscriber" is empty here. ==> return false
if (! $subscriber) {
return false;
}
...
}
走进$this->storage->subscriberByRequest()
去,我得到
//
// Nuwave\Lighthouse\Subscriptions > class StorageManager
//
public function subscriberByRequest(array $input, array $headers): ?Subscriber
{
$channel = Arr::get($input, 'channel_name');
return $channel
? $this->subscriberByChannel($channel)
: null;
}
public function subscriberByChannel(string $channel): ?Subscriber
{
$key = self::SUBSCRIBER_KEY.".{$channel}";
// At this point, "$key" equals "graphql.subscriber.private-lighthouse-blablabla"
return $this->cache->get($key); // This returns NULL
}
有人可以帮忙吗?
我错过了什么?
我的配置:
# composer.json
"php": "^7.4",
"laravel/framework": "^7.0",
"nuwave/lighthouse": "^4.11",
"pusher/pusher-php-server": "^4.1"
# .env
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
LIGHTHOUSE_SUBSCRIPTION_STORAGE=file
LIGHTHOUSE_BROADCASTER=pusher
# config/lighthouse.php
'subscriptions' => [
'storage' => env('LIGHTHOUSE_SUBSCRIPTION_STORAGE', 'file'),
'broadcaster' => env('LIGHTHOUSE_BROADCASTER', 'pusher')
],