Laravel自定义身份验证


Laravel custom authentication

我开始发现Laravel 5,所以我可能需要你的帮助来理解一些事情。

首先,我想开发一个登录页面。看起来Laravel有一个完整的身份验证系统,我想我应该使用它

尽管如此,我想显示一个登录页面(我知道如何做到这一点!),但在此之后,我想通过API调用将凭据发送到服务器。然后服务器会告诉我是否允许用户登录。

就我对Laravel和身份验证的理解而言,身份验证系统似乎只适用于本地DB。

你能确认我需要使用自定义身份验证驱动程序吗?我一直在遵循这个解决方案但我在加载页面时遇到了这个错误:

FatalErrorException in CustomUserProvider.php line 6:
Interface 'Illuminate'Auth'UserProviderInterface' not found

任何帮助都将不胜感激,如果你需要,请随时向我询问更多信息。

感谢

我试着遵循你提到的相同线程,得到了完全相同的结果。然后我检查了本机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
}

我相信这是更正确的方法,因为论坛帖子中的建议似乎是针对L5的旧版/测试版。

这是我的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 {

它现在正在工作:-)