php 如何在 Laravel 5 中验证 RESTful API?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28829587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to authenticate RESTful API in Laravel 5?
提问by Vaibhav
How to authenticate RESTful API in Laravel 5? I am using Laravel 5 to build a RESTful API & I want to use those API for mobile application.
如何在 Laravel 5 中验证 RESTful API?我正在使用 Laravel 5 构建一个 RESTful API,我想将这些 API 用于移动应用程序。
I have also seen http://laravel.com/docs/5.0/authenticationbut not getting any related example so,please provide me sample example or appropriate link for authenticate RESTful API in Laravel 5.
我也看过http://laravel.com/docs/5.0/authentication但没有得到任何相关的例子,所以请给我提供示例或适当的链接以在 Laravel 5 中验证 RESTful API。
采纳答案by Tarunn
回答by nozzleman
The Concept to use here would be Middleware: To get you started, put this in your API-Controller's ctors:
这里使用的概念是中间件:为了让你开始,把它放在你的 API 控制器的 ctors 中:
public function __construct()
{
// reqires Authentificataion before access
$this->middleware('auth.basic');
}
Your app should then be able to call the resources like
然后,您的应用程序应该能够调用资源,例如
http://user:[email protected]/yourresource/1