0
votes

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

1
Why cannot you use it? What errors do you get? What changes did you make to your kernel.php try posting your kernel fileDhiraj
@zuif - added the kernel file. I tried signing in with the auth form and it won't let me. But if I install a sepearate instance of laravel and use the same backend I can login.user9465677
Can you also post your config auth.php file, and also post your controller where you are trying to use the basic authDhiraj
@zuif - just added. Please see attached.user9465677
Please don't post pictures of code and put the code itself into your question/answer. Pictures will get deleted over time by most image hosting providers and this means the content of your question/answer is lost. It also prevents other users from copying the code (i.e. when they want to test it).Namoshek

1 Answers

0
votes

Everything looks fine, except to useTymon\JWTAuth you should make these changes

Change the api driver to jwt instead of token, I would have posted the code if you would have posted the code instead of an image and change the default guard to be api.

And for your basic auth you should be able to use it without a problem. Try doing it, if you could not post the code and I'll post the code.