Laravel 自定义认证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28890409/
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
Laravel custom authentication
提问by Vico
I'm starting to discover Laravel 5, so I might need a bit of your help to understand a few things.
我开始发现 Laravel 5,所以我可能需要你的一些帮助来理解一些事情。
First, I want to develop a login page. It seems that Laravel has a whole authentication system, and I guess I should use it.
首先,我想开发一个登录页面。好像 Laravel 有一个完整的认证系统,我想我应该使用它。
Nevertheless, I want to display a login page (I know how to do this!), but after this, I would like to send the credentials to a server via an API call. The server will then tell me if the user is allowed to log in or not.
尽管如此,我还是想显示一个登录页面(我知道怎么做!),但在此之后,我想通过 API 调用将凭据发送到服务器。然后服务器会告诉我是否允许用户登录。
As far I understand Laravel and authentication, it seems that the authentication system works only with a local DB.
据我了解 Laravel 和身份验证,似乎身份验证系统仅适用于本地数据库。
Can you confirm I need to use a custom authentication driver to do this? I've been following this solutionbut I get this error when loading my page:
您能否确认我需要使用自定义身份验证驱动程序来执行此操作?我一直在关注此解决方案,但在加载我的页面时出现此错误:
FatalErrorException in CustomUserProvider.php line 6:
Interface 'Illuminate\Auth\UserProviderInterface' not found
Any help would be appreciated, feel free to ask me for more information if you need it.
任何帮助将不胜感激,如果您需要,请随时向我询问更多信息。
Thanks
谢谢
采纳答案by silverdr
I tried following the same thread you mentioned and arrived at the very same results. Then I checked the implementation of native UserProviders (Illuminate/Auth/EloquentUserProvider and Illuminate/Auth/DatabaseUserProvider) and ended up using the same set as in EloquentUserProvider:
我尝试按照您提到的同一线程进行操作,并得出了完全相同的结果。然后我检查了原生 UserProviders(Illuminate/Auth/EloquentUserProvider 和 Illuminate/Auth/DatabaseUserProvider)的实现,并最终使用了与 EloquentUserProvider 中相同的集合:
<?php namespace App\Auth;
use Illuminate\Contracts\Auth\UserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
class MyUserProvider implements UserProvider {
// Implementation goes here
}
I believe this to be more correct approach as the suggestions from the forum thread seem to be possibly for an older/beta version of L5.
我相信这是更正确的方法,因为论坛帖子中的建议似乎可能适用于 L5 的旧版/测试版。
回答by Vico
Here is my CustomUserProvider file:
这是我的 CustomUserProvider 文件:
<?php namespace App\Auth;
use Illuminate\Contracts\Auth\UserProvider as UserProviderInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\GenericUser;
class CustomUserProvider implements UserProviderInterface {
It's now working :-)
它现在正在工作:-)