Changed RestAuth functions to static for ease-of-access
This commit is contained in:
parent
323f53d6ac
commit
080b2581b6
|
@ -2,15 +2,11 @@
|
||||||
|
|
||||||
class RestAuth
|
class RestAuth
|
||||||
{
|
{
|
||||||
public function verifyAuth($checkApiKey, $checkSession)
|
public static function verifyAuth($checkApiKey, $checkSession)
|
||||||
{
|
{
|
||||||
//Session takes precedence over API key for now:
|
//Session takes precedence over API key for now:
|
||||||
if ($checkSession && $this->verifySession())
|
if ($checkSession && RestAuth::verifySession()
|
||||||
{
|
|| $checkApiKey && RestAuth::verifyAPIKey())
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($checkApiKey && $this->verifyAPIKey())
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +18,10 @@ class RestAuth
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOwnerId()
|
public static function getOwnerId()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->verifySession()) {
|
if (RestAuth::verifySession()) {
|
||||||
$service_user = new Application_Service_UserService();
|
$service_user = new Application_Service_UserService();
|
||||||
return $service_user->getCurrentUser()->getDbId();
|
return $service_user->getCurrentUser()->getDbId();
|
||||||
} else {
|
} else {
|
||||||
|
@ -45,17 +41,13 @@ class RestAuth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function verifySession()
|
private static function verifySession()
|
||||||
{
|
{
|
||||||
$auth = Zend_Auth::getInstance();
|
$auth = Zend_Auth::getInstance();
|
||||||
if ($auth->hasIdentity())
|
return $auth->hasIdentity();
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function verifyAPIKey()
|
private static function verifyAPIKey()
|
||||||
{
|
{
|
||||||
//The API key is passed in via HTTP "basic authentication":
|
//The API key is passed in via HTTP "basic authentication":
|
||||||
// http://en.wikipedia.org/wiki/Basic_access_authentication
|
// http://en.wikipedia.org/wiki/Basic_access_authentication
|
||||||
|
@ -66,14 +58,7 @@ class RestAuth
|
||||||
$encodedRequestApiKey = substr($authHeader, strlen("Basic "));
|
$encodedRequestApiKey = substr($authHeader, strlen("Basic "));
|
||||||
$encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":");
|
$encodedStoredApiKey = base64_encode($CC_CONFIG["apiKey"][0] . ":");
|
||||||
|
|
||||||
if ($encodedRequestApiKey === $encodedStoredApiKey)
|
return ($encodedRequestApiKey === $encodedStoredApiKey);
|
||||||
{
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue