laravel - 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
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
解决方案
一切看起来都很好,除了使用Tymon\JWTAuth
你应该做这些改变
将 api 驱动程序更改为 jwt 而不是令牌,如果您发布代码而不是图像并将默认保护更改为 api,我会发布代码。
对于您的基本身份验证,您应该可以毫无问题地使用它。尝试这样做,如果您无法发布代码,我将发布代码。
推荐阅读
- ajax - 如何使用 AJAX 结果更新 Master detail razor 页面中的模型
- sql - PostgreSQL 计算子查询中的行数
- android - 仅在需要时调整文本视图文本大小以适合文本视图大小
- node.js - 在使用 MessageCollector 达到设置的时间限制后如何触发代码?
- php - 来自popen的PHP pid
- firebase - 由于我的应用程序使用密码身份验证,因此上面的代码将在该字段中给我 null
- azure - 如何在 Azure 托管应用程序 ARM 部署中强制选择服务主体
- c# - 如何仅获取 C# 中两个 DateTimeOffset 之间的时间差,而忽略日期差?
- c++ - std::mutex 的 constexpr 构造函数是如何实现的?
- firebase - Firebase 身份验证 Google 登录以仅允许特定的 google 工作区帐户