RESTfulAPI::auth PHP Method

auth() public method

Handles authentications methods get response from API Authenticator then passes it on to $answer()
public auth ( SS_HTTPRequest $request )
$request SS_HTTPRequest HTTP request
    public function auth(SS_HTTPRequest $request)
    {
        $action = $request->param('Action');
        if ($this->authenticator) {
            $className = get_class($this->authenticator);
            $allowedActions = Config::inst()->get($className, 'allowed_actions');
            if (!$allowedActions) {
                $allowedActions = array();
            }
            if (in_array($action, $allowedActions)) {
                if (method_exists($this->authenticator, $action)) {
                    $response = $this->authenticator->{$action}($request);
                    $response = $this->serializer->serialize($response);
                    return $this->answer($response);
                } else {
                    //let's be shady here instead
                    return $this->error(new RESTfulAPI_Error(403, "Action '{$action}' not allowed."));
                }
            } else {
                return $this->error(new RESTfulAPI_Error(403, "Action '{$action}' not allowed."));
            }
        }
    }