在Laravel 5.3中使用多个Auth? [英] Using multiple Auth in Laravel 5.3?

查看:83
本文介绍了在Laravel 5.3中使用多个Auth?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在laravel 5.3中创建一个RESTApi以及我的API,我也制作了一个供管理员使用的Web应用程序.在此Web应用程序中,我使用的是laravel的简单auth(php artisan make:auth),它工作正常,但是在启动我的Web应用程序之前,我对RESTApi使用JWT auth.现在,当我尝试通过此调用从JWToken获取用户时

I'm creating a RESTApi in laravel 5.3 along with my API I also make a web application for admin use. In this web app I'm using laravel's easy auth (php artisan make:auth) which work just fine, but before starting up my web app I use JWT auth for my RESTApi. Now when I try to get a user from a JWToken with this call

 Auth:user() 

它没有返回正确的用户,而是以我的管理员"模型返回了该用户.我有两种模型:User和Admin,其中User用于我的API,而Admin用于我的Web/管理应用程序.有没有办法将这两种身份验证分开,以便对管理员"使用简单身份验证,对用户"使用JWT?

It does not return the right user, it returns the user in my 'Admin' model. I have two model, User and Admin, where User is used for my API and Admin is for my web/admin app. Is there a way I can separate these two authentication so that I use easy auth for 'Admin' and JWT for 'User'?

在每个我的API控制器中,我在构造函数中都有此中间件:

In each my API controller I have this middleware in the constructor:

public function __construct()
{

    $this->middleware('jwt.auth');
}

推荐答案

您可以在laravel 5.3中尝试使用我的软件包进行多重身份验证. https://github.com/Hesto/multi-auth

You can try my package for multi auth in laravel 5.3. https://github.com/Hesto/multi-auth

这篇关于在Laravel 5.3中使用多个Auth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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