Support for other auth types.

This commit is contained in:
Qiang Xue 2014-03-03 10:18:39 -05:00
parent e9148837ee
commit b61e6d214a

View File

@ -8,7 +8,7 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
public $username; public $username;
public $password; public $password;
public $authKey; public $authKey;
public $apiKey; public $accessToken;
private static $users = [ private static $users = [
'100' => [ '100' => [
@ -16,14 +16,14 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
'username' => 'admin', 'username' => 'admin',
'password' => 'admin', 'password' => 'admin',
'authKey' => 'test100key', 'authKey' => 'test100key',
'apiKey' => '100-apikey', 'accessToken' => '100-token',
], ],
'101' => [ '101' => [
'id' => '101', 'id' => '101',
'username' => 'demo', 'username' => 'demo',
'password' => 'demo', 'password' => 'demo',
'authKey' => 'test101key', 'authKey' => 'test101key',
'apiKey' => '101-apikey', 'accessToken' => '101-token',
], ],
]; ];
@ -38,10 +38,10 @@ class User extends \yii\base\Object implements \yii\web\IdentityInterface
/** /**
* @inheritdoc * @inheritdoc
*/ */
public static function findIdentityByToken($token) public static function findIdentityByAccessToken($token)
{ {
foreach (self::$users as $user) { foreach (self::$users as $user) {
if ($user['apiKey'] === $token) { if ($user['accessToken'] === $token) {
return new static($user); return new static($user);
} }
} }