0

I have a Laravel 4 web application where users can login and edit their profile.

I've created an API package that allows the user to login with their username/password and get a json dump of their profile.

Now, I don't want the API users to use their username/password but instead to use an app_id / app_key from another table in the database.

How to accomplish this with Laravel 4? It would be fantastic if I can create an Auth driver that works the same way Auth:attempt() would so I don't have to change any of my business logic, but I don't know how to inject a new Auth service provider that ONLY works inside of the API package.

4

1 回答 1

0

您可以根据需要更改身份验证设置。您可以像这样在 filters.php 中创建一个过滤器:

Route::filter('api_auth', function()
{
   Config::set('auth.table', 'api_table');
   // you can even change your model
   // Config::set('auth.model', 'Apiuser');
});

并在 routes.php 中的任何路由之前使用,如下所示:

Route::get('user', array('before' => 'api_auth', function()
{
   // some stuff
}));

因此,您可以使用不同的设置并做您想做的事。

顺便说一句,我在 Laravel 3 尝试过这种方法,它奏效了。我查看了 laravel 4 的文档,我看不到任何阻止这项工作的东西。

于 2013-02-22T14:47:08.217 回答