Frage

I'm working on a project where I'm trying to implement authentication against external user base for customers, this seems to be working correctly.

Recently there has been added another requirement that some people (not present in the aforementioned base) need to be able to edit parts of pages' content. First thing that comes to mind is to have separate ORM/File Auth driver enabled for those few editors to be able to authenticate them separately.

Is it possible to use two Auth drivers at the same time in Kohana 3.2?

War es hilfreich?

Lösung

Yes, you can use different drivers at once. Just create another instance instead of standard singleton:

// default Auth
$config = Kohana::$config->load('auth');
$auth = new Auth($config);
$user = $auth->get_user();
// special Auth for administration
$config2 = Kohana::$config->load('admin_auth');
$auth2 = new Auth($config2);
$admin = $auth2->get_user();

Restrictions:

  1. You must use differ configs (driver and session_key values must differ). Note that some settings are defined in classes and cant be changed by config (for example, "remember" cookie named authautologin).
  2. You cant share default ORM models (Model_User, Model_Token, Model_Role), because their names are hardcoded. But ORM driver & File driver can be used.

Andere Tipps

Kohana's Auth module does not natively support using two Drivers.

However, you can implement a new Driver yourself very easily. You can follow the instructions for creating a new Driver by copying the existing driver and modifying it, here: http://kohanaframework.org/3.3/guide/auth/driver/develop

The simple thing to do would be to put the following logic in your _login method:

  1. Check the external user database for a valid login
  2. If there is a valid user in the external user database, return true.
  3. If there is no valid user in the external user database, check the local user database instead.
  4. If the user exists in the local database, return true.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top