如何使用广播身份验证修复419错误 [英] How to fix 419 error with broadcasting auth

查看:100
本文介绍了如何使用广播身份验证修复419错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Laravel Framework 5.7/Vuejs 2.6中,我使用jwt.auth并安装推送器

In my Laravel Framework 5.7 / Vuejs 2.6 I use jwt.auth and installing pusher

我为页面 https://imgur.com/a/CveJ6jh 检查xsfr令牌,但是我在 http://local/broadcasting/auth 请求中收到419错误,并打开了该网址的响应页面邮件已过期.
在app/Events/NewMessage.php中:

I check xsfr token for my page https://imgur.com/a/CveJ6jh but I got 419 error in http://local/broadcasting/auth request and open responce of this url I see page expired message.
In app/Events/NewMessage.php :

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Message;

class NewMessage
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct(Message $message)
    {
        $this->message= $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('messages.'.$this->message->to);
    }
    public function broadcastWith()
    {
        return ['messages' => $this->message];
    }

}

在routes/channels.php中:

In routes/channels.php :

Broadcast::channel('messages.{id}', function ($user, $id) {
    dd($user->id, $id);
    return (int) $user->id === (int) $id;
});

但是我没有从上面看到任何调试信息.

But I do not see any debugging info from above.

我使用了先前应用程序中的pusher参数.我认为他们一定没事.否则我会有其他错误?

I used pusher parameters from my prior app. I think they must be ok. Otherwise I would have different error ?

和in vue组件:

mounted() {
    Echo.private(`messages.${this.customerRow.id}`)
        .listen('NewMessage', (e) => {
            this.hanleIncoming(e.message);
        });

我想念什么?

谢谢!

推荐答案

此错误的原因是Laravel期望一个CSRF令牌.

The reason for this error is that Laravel expects a CSRF token.

您有两个选择:

  1. 包含CSRF令牌(为安全起见)
  2. 为此网址禁用CSRF
  1. Include the CSRF token (better for security)
  2. Disable CSRF for this URL

这篇关于如何使用广播身份验证修复419错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆