首页 > 解决方案 > Laravel - Can no longer use basic auth

问题描述

I used the article below to create JWT auth in my laravel project. But now I can no longer use the Basic auth. Is there a way to use Basic auth as well? I need it for my web interface.

https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps

Kernel file

enter image description here

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;

class AuthController extends Controller
{

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

public function __construct()
{
    $this->middleware('guest', ['except' => 'getLogout']);
}

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => 'required|max:255',
        'email' => 'required|email|max:255|unique:users',
        'password' => 'required|confirmed|min:6',
    ]);
}

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);
}
}

Route::get('auth/login', 'Auth\AuthController@getLogin'); Route::post('auth/login', 'Auth\AuthController@postLogin');

Update: after turning the debug on I got the following error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Trait 'Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers' not found

标签: laravellaravel-5jwt

解决方案


一切看起来都很好,除了使用Tymon\JWTAuth你应该做这些改变

将 api 驱动程序更改为 jwt 而不是令牌,如果您发布代码而不是图像并将默认保护更改为 api,我会发布代码。

对于您的基本身份验证,您应该可以毫无问题地使用它。尝试这样做,如果您无法发布代码,我将发布代码。


推荐阅读