简体   繁体   中英

how to access API routes with middleware auth:api in laravel 5.3?

I am able to access routes declared in the api.php(route) with middleware 'api' . But not able to do the same with the routes that has 'auth:api' . I guess only authenticated users can access the latter route. But when i access it after logging in , it just redirects me to home. how to fix this or am i following wrong procedure ?

Route::get('/user', function () {
echo "Hello";
})->middleware('auth:api');

Route::get('/work',function(){
echo "Hello";
})->middleware('api');

Check Laravel passport, it provides a nice way to implement OAuth2 and once you install passport create password client and make a post request to Oauth/token and get personal access_token.

Once you have the access_token you can make request to middleware auth:api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM