简体   繁体   English

API和普通认证可以用一张user表吗?

[英]Can one user table be used for both API and regular authentication?

I have multiple front end apps using one database.我有多个使用一个数据库的前端应用程序。 I wanted to use a single user table to authenticate users for all apps.我想使用单个用户表来验证所有应用程序的用户。 The problem is some apps access tables in the database through regular authentication while some are isolated reacts apps accessing the database through API authentication.问题是一些应用程序通过常规身份验证访问数据库中的表,而一些孤立的反应应用程序通过 API 身份验证访问数据库。

My question is, can I use the same user table to authenticate users from different apps using both regular and API authentication.我的问题是,我可以使用相同的用户表来使用常规身份验证和 API 身份验证来对来自不同应用程序的用户进行身份验证。 For your info, I am using Laravel as a backend.为了您的信息,我使用 Laravel 作为后端。 Thank you for your help:).谢谢您的帮助:)。

I guess with regular authentication you mean session and the answer is yes.我想对于常规身份验证,您的意思是 session,答案是肯定的。

Because authentication data and logic are always separated from the authenticatable table (when using jwt you get another table for tokens and with session authentication you use cache or database).因为身份验证数据和逻辑始终与可验证表分开(使用 jwt 时,您会得到另一个令牌表,而使用 session 身份验证时,您会使用缓存或数据库)。

so yes you will use as many guards as you wish with the same table it will look like this in your config/auth.php file:所以是的,你将使用同一张表使用尽可能多的守卫,它在你的 config/auth.php 文件中看起来像这样:

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'jwt',
            'provider' => 'users',
        ],
    ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM