dpwo36915 2018-01-09 18:54
浏览 46

如何在Laravel的一个频道中验证多个警卫?

I'm building a real time application in Laravel with custom guards using JWT: person-api for Person and worker-api for Worker. They represent different models, not the same one with roles.

A Person may request a certain Job and a Worker is able to accept that job. I have a dedicated table for each model, jobs being the intermediary table between a Person and a Worker, with a person_id and worker_id. When a Job is requested, the worker_id column is set to null until a Worker takes it.

When a Person requests a Job an event is fired and broadcasted in a private channel called Jobs. I'm able to authorize the person in that channel by checking the person_id of the job in the event. At this moment, the job is available to any Worker until one takes it, and then only the Worker who took it is able to perform actions on that Job.

My question is, how do I achieve multiple authentication with two different guards in one same channel where the authorization method may vary depending on the state of the Job?

For example:

  • When a Job is requested, I can authorize the Person with the person_id of the job, but the worker_id is null, so it's open to any Worker
  • When a Worker takes the job, the authorization for the Person stays the same, but now only the Worker who took it is authorized in the channel
  • When a Worker drops the job, it becomes available again to any Worker

This is the code in my channels routes for broadcasting:

Broadcast::channel('job.{job}', function ($user, \App\Job $job) {
    // authorization condition goes here
});

Where $user might be a Person or a Worker, and the authorization condition might change depending on the event of the job in the same channel.

EDIT: My question was marked as a possible duplicate of this question and I disagree. I'm not just talking about authenticating users with JWT, that's implemented already. I'm talking about authenticating multiple users with different guards in one same broadcast channel and changing the authorization condition according to the type of user and status of the job.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答