All we need is JWT for Laravel API Authentication

preview_player
Показать описание
Let's Build a Multi-Purpose Laravel + Vue Application is out now. In this series, you learn everything you need to know about Building a complete web application with Laravel and Vue js. So, I am so excited that so many of you guys like my content and keep inspiring me to create more videos. My goals is to inspire you to write better code and better applications.

Open Source At Github.

Here are the things you will learn in this series:

* How use Vue Router with Laravel
* How to Install AdminLTE 3
* How to Use Font Awesome 5 on Laravel
* How integrate mailchimp with laravel
* How to use Laravel Socialite
* How to Login Using Social Media
* How to Use API in Laravel
* Api Auth with Laravel Passport
* JWT with Laravel Passport and JavaScript Request
* Vue Custom Events
* Vue form with Laravel
* Relational Database with Laravel
* Axios and Ajax Request
* ACL in Laravel
* Online Users list
* And much more...

Tags:

JWT with Laravel,tutorial,coding,laravel,laravel and vue js tutorial,laravel and vuejs,laravel and vue js project,laravel admin panel,laravel adminlte,laravel admin,vue js tutorial,vue js,axios,laravel application development,learn laravel 5.6,learn laravel framework,laravel crud,laravel crud tutorial,spa,laravel how to,laravel tips,coding tips,admin lte laravel 5.6,adminlte with php,laravel api,laravel passport, hosting, cloud, web hosting
Рекомендации по теме
Комментарии
Автор

The best practise for securing routes is using middleware in routes here is an example hope it helps
previously we have:
Route::apiResources([


'user' => 'API\UserController'
]);
now we just need to add this.

Route::group(['middleware' => 'auth:api'], function() {
Route::apiResources([
'user' => 'API\UserController'
]);
});
(benefit of using this method is there might be many controllers in ur project and its not good to go inside every controller and add middleware constructor so best practise is using this method) :-)

technicalcreations
Автор

For those who are getting 401 unauthorized.. open terminal and clear config cache "php artisan config:cache" then refresh the page

fozaibx
Автор

Thank you, for the years, i was always lost with the developer and client oath but now i see you don't even have to use them. adding a simple line does the magic for you.

samwd
Автор

i am getting "message":"Unauthenticated." even tho i have login. What could be the issue

richarddanquah
Автор

thats great !
i made a mistake : i put CreateFreshApiToken in $middleware instead of $middlewareGroups ... i it toke time to find the problem
in angular you should send token each time you make request to server which is very time taking
but how the token send each time automatically? coz of <meta name="csrf-token" content="{{csrf_token()}}" > ???

ghazyy
Автор

is it possible to use normal middleware instead of API ?

mahdimiad
Автор

thanks you so much. i am from Bangladesh watching your tutorial. thank you so much.

Mahmudulhasan-tshm
Автор

why mine is not working
i tried to my other controller and model
the API not showing

santiagotv
Автор

A question: I lost... To use JWT for Laravel API, Should I install Laravel Passport? Are they to diferents things?

IngPedroAraujo
Автор

I've had problem and you have not covered it, finaly after 5 days of research ...
401 error with "Unauthenticated" error. All i had to do was to clear cache:
php artisan config:cache
Hope it saves you a lot of time.

konradkoguciuk
Автор

cant prooced on the next tutorials having problem when authenticated users cant access showing console 404 unauthorized im using laravel 7 and vue 3 please give some solution thanks advance

simeonanunciado
Автор

this is the one that I've been looking for, thanks for sharing.

guilebornas
Автор

Very nice tutorial. Followed it upto this video. Will continue further. Just one question, what we have to do if we want to get response on POSTMAN tool too?
And where do we use the Client Secret we stored in the file?

AslamD
Автор

If I have a public view but only me consume my API. How should I do that? I Trying removing auth from auth: api, but anyone can consume it

eduardobravo
Автор

Hi, whats with normal frontend? For example in frontend i wanna show some data like 10 flowers, i administrate in my backend (u showes us, how i secure it, thx for that)-

the Frontend-Api should be also secured, but i dont know how.


I dont want bots on m api, and i dont want that anyone can access to it. only my vuejs frontend should be!
I want a authorization not a authentication ;)
How i can do this?

hansmeister
Автор

Hi guys I was having the 401 unauthorized problem as well, cleared the cache and nothing happened. What i was doing wrong was pasting " \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class, " ouside the web middleware group. So make sure you paste this inside here
"protected $middlewareGroups = [
'web' => [ ... 'HERE ']
], " at the kernel.php file
Hope someone in the same case this would help.
Thanks for the tutorial by the way, very useful!

pcasi
Автор

after install passport and logout why login always redirect to /js/popper.js.map

rizkysouisay
Автор

I have same problem with 401 unauthorized error. I do exactly your video . After couple of days, I solved my problem, I added
protected static $serialize = true;
in
and amazing! Hoping this help for you. My laravel verion is 5.5. BTW thank @Code Inspire

nnduyquang
Автор

----ERROR 401
Laravel 5.6 | "composer require laravel/passport" --->> will try to install latest version of Passport v9.2...
Laravel 5.6 won't support v9.2... So add this line of code in your "composer.json" file then use "composer update" in the terminal :
"require": {
//other....
"laravel/passport": "^7.0",
},
NOTE: any version below 7.0 and above 9.0 won't work now in Laravel 5.6..
I really appreciate these videos you made, even after a year its still worth it..
Thank You, learning all the way from Sri Lanka...

captainburah
Автор

Thanks for your nice tutorials .
Will you please make some tutorials on APIs? this is tutorial is very good but I meant, if somebody wants to use may APIs for their applications, How do I make permissions for theme?
Authentication is very important I think. I cannot allow somebody else to delete data of my database etc etc.

The way of teaching of yours is very good to me. Please suggest me what to do??
I want to make my APIs for global. Even I want to allow other developer to use my APIs..

NazrulIslam-izsw