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

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

问题描述

我正在 laravel 5.3 中创建一个 RESTApi 以及我的 API 我还创建了一个供管理员使用的 Web 应用程序.在这个网络应用程序中,我使用了 laravel 的简单身份验证(php artisan make:auth),它工作得很好,但在启动我的网络应用程序之前,我将 JWT 身份验证用于我的 RESTApi.现在,当我尝试通过此调用从 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/admin 应用程序.有没有办法可以将这两种身份验证分开,以便我对管理员"使用简单的身份验证,对用户"使用 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 中使用多个身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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