PrplHaz4, on 16 October 2012 - 01:14 PM, said:
Are there any examples of this extension implemented with the token auth scheme described below? Or perhaps an example of an auth adapter?
Extension have one default Auth adapter, which can be rewrited or extended -
https://github.com/p...pters/Basic.php
Your auth scheme can use adapter something like this
namespace rest\service\auth\adapters;
use rest\service\auth\AdapterInterface;
class AccessKey implements AdapterInterface
{
/**
* @var string
*/
public $identityClass = 'application.components.UserIdentity';
/**
* @throws \CHttpException
*/
public function authenticate()
{
if (!isset($_GET['AccessKeyId']) || !($key = $_GET['AccessKeyId'])) {
throw new \CHttpException(401, \Yii::t('ext', 'Undefined AccessKeyId'));
}
if (!isset($_GET['Expires']) || !($expires = $_GET['Expires'])) {
throw new \CHttpException(401, \Yii::t('ext', 'Undefined Expires'));
}
if (!isset($_GET['Signature']) || !($sign = $_GET['Signature'])) {
throw new \CHttpException(401, \Yii::t('ext', 'Undefined Signature'));
}
$user = $this->getUserByAccessKey($key); // some logic matching user by AccessKeyId
if (!$user) {
throw new \CHttpException(401, \Yii::t('ext', 'AccessKeyId not found'));
}
$secretKey = $user->secretAccessKeyID; // user should have own secretAccessKeyID
$validSign = sha1($secretKey . '.' . $_SERVER['REQUEST_URI'] . '.' . $expires); // it's not AWS algo - just for example
if ($sign != $validSign) {
throw new \CHttpException(401, \Yii::t('ext', 'Wrong Signature'));
}
if ($expires > time()) {
throw new \CHttpException(401, \Yii::t('ext', 'AccessKeyId Expired'));
}
// Authenticate \Yii::app()->user
$identityClass = \Yii::import($this->identityClass);
$identity = new $identityClass($user->name, $user->password);
$identity->authenticate();
\Yii::app()->user->login($identity);
}
public function getUserByAccessKey($key)
{
// not implemented
}
}
Be careful, it's is just simple example! I'm not tested it.
Method
getUserByAccessKey and user object not written, because it is the implementation details.
Thank you for your interest, I hope I was able to help.