简体   繁体   中英

How to do auth without database in Laravel 5.6?

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?

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)
    {       
    }
}

and Alumni.php on App\\Auth :

<?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()
    {
    }
}

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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