Ошибка входа в систему в laravel 5 (JTW)
Когда дело доходит до доступа к моему логину, у меня возникает следующая ошибка:
{"error":"token_not_provided"}
У меня есть в моем.htaccess:
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
У меня в моем routes.php :
Route::post('/api/login', 'AuthenticateController@authenticate');
Route::get('/api/login', 'AuthenticateController@authenticate');
И у меня есть свой контроллер аутентификации:
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
class AuthenticateController extends Controller
{
public function authenticate(Request $request)
{
// grab credentials from the request
$credentials = $request->only('email', 'password');
try {
// attempt to verify the credentials and create a token for the user
if (! $token = JWTAuth::attempt($credentials)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
} catch (JWTException $e) {
// something went wrong whilst attempting to encode the token
return response()->json(['error' => 'could_not_create_token'], 500);
}
// all good so return the token
return response()->json(compact('token'));
}
Вы можете мне помочь? большое вам спасибо, приветствую
2
Author: Francesco de Guytenaere, 2016-03-04
2 answers
Вам необходимо убедиться, что в вашем представлении есть: {!! csrf_field()!!} и вам не нужно, чтобы оно было скрытым полем в форме.
<form class="form-horizontal" method="post">
@foreach ($errors->all() as $error)
<p class="alert alert-danger">{{ $error }}</p>
@endforeach
{!! csrf_field() !!}
<fieldset>
1
Author: Christopher Govender, 2016-03-04 11:57:15
Каково ваше мнение? Я думаю, тебе нужно что-то добавить на свой клинок.
<input type="hidden" name="_token" value="{{ csrf_token() }}">
Если вы не используете представление и делаете это по внешнему запросу. Затем вы можете просто отключить csrf_token()
Вот ссылка Как отключить CSRF промежуточного программного обеспечения в Laravel
1
Author: Guillermo Tabligan, 2016-03-04 11:37:34