在Laravel 5.6中如何在没有数据库的情况下进行身份验证? [英] How to do auth without database in Laravel 5.6?

查看:78
本文介绍了在Laravel 5.6中如何在没有数据库的情况下进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用以下命令在Laravel中进行默认登录:php artisan make:auth,我想再添加1个使用API​​的身份验证.在此身份验证API中,我不需要数据库即可登录.

I have to make default login in Laravel with: php artisan make:auth and I want to add 1 more authentication with API. In this auth API I don't need database for login.

这种情况有解决方案吗?

Is there any solution for this case?

我想创建自定义提供程序并加以保护,但是我被困在App\Auth上的AlumniAuthProvider.php上:

I want to make custom provider and guard it but I am stuck at AlumniAuthProvider.php on App\Auth:

<?php

namespace App\Auth;

use Illuminate\Contracts\Auth\User as UserContract;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Auth\UserProvider;
use App\Auth\User;

class AlumniAuthProvider implements UserProvider {

    public function alumni()
    {           
    }

    public function retrieveById($identifier)
    {
    }

    public function retrieveByToken($identifier, $token)
    {
    }

    public function updateRememberToken(Authenticatable $user, $token)
    {
    }

    public function retrieveByCredentials(array $credentials)
    {
    }

    public function validateCredentials(Authenticatable $user, array $credentials)
    {       
    }
}

上的

Alumni.php:

<?php

namespace App\Auth;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\Request;

class Alumni implements Authenticatable
{
    public function getAuthIdentifierName()
    {
    }
    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {        
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string  $value
     * @return void
     */
    public function setRememberToken($value)
    {
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
    }
}

如何进行此自定义API登录?

How could I make this custom API login?

在我看来,我编写的这段代码是用于第二次身份验证的,还是我错了?也许还有其他方法可以解决这个问题?

In my opinion this code, which I made, is for second auth, or am I wrong? Maybe is there any other way to solve this problem?

推荐答案

我认为在不使用数据库的情况下进行api登录是一个坏主意,因为每次用户通过另一个系统登录时,都会进行api调用,而这将在创建更多流量时您的系统将会上线.更好的方法是第一次进行api调用,然后将数据存储在数据库中,然后在用户重新登录时从数据库中调用数据.

I think doing api login without database is a bad idea because everytime the user will login through another system the api call will took place and thats will create more traffic when your system will be live. Better way is to make api call for the first time and store data in the database and afterwards call data from the database when user re-logins.

这篇关于在Laravel 5.6中如何在没有数据库的情况下进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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