0
votes

I am using yii framework for an application and I need a set of users to be authenticated with a remote server.

I have few user roles in my application. for ex:

  • Super Administrator
  • Brand Administrator
  • Customer etc...

All the customer records are in a remote MySQL database. I have to authenticate the customers through my yii application. My yii application will be hosted in a different server.

Please assume that I can place a php script in the remote server to response my post requests.

Do I need to write my own UserIdentity class to do this?

Please help me on this. Thanks

2

2 Answers

2
votes

I don't think you need to put any script in your remote server, all you need is

1. Access the remote Db, and Yii allows the use of [multiple-databases][1].
2. Adjust the model(s) you are using for Authentication/Authorization (usually the User model) to load it's data from the remote database

For the First task:

// protected/main/config.php

return array(
...
'components' => array(
    'db' => array(
        'connectionString' => 'mysql:host=dbserver1;dbname=my1db',
        ...
    ),
    'remotedb' => array(
        'connectionString' => 'mysql:host=adserver2;dbname=advertisingDB',
        'username'         => 'username',
        'password'         => '***********',
        ...
        'class'            => 'CDbConnection'          // DO NOT FORGET THIS!
    ),

For the second task:

For the model(s) you are using to Authenticate & Authorize, you will need to override the getDbConnection() function to load the needed data from the remote server. Check the Wiki for How.

And, Yes. You will need to write your own UserIdentity class, actually its a usual task even if you havn't use a remote Db since it's default logic is only an example and not for real production sites.

GoodLuck!

0
votes

Yes, you will have to rewrite the component UserIdentity and create their own rules authentication.