public function verify($action)
 {
     if ($action == "actionaccesstoken") {
         // provide the access token
         $client_id = $_REQUEST["client_id"];
         $client_secret = $_REQUEST["client_secret"];
         $code = $_REQUEST["code"];
         $redirect_uri = $_REQUEST["redirect_uri"];
         $grant_type = $_REQUEST["grant_type"];
         // should be "authorization code"
         // validate the client
         $api = $this->lookupConsumer($client_id, $client_secret);
         if ($api) {
             $token = new DTOAuthToken($this->db->filter(array("type" => 0, "token" => $code, "status" => 1)));
             $token["consumer_id"] = $api["id"];
             $token->updateToAccessToken($this->db);
         }
         exit("access_token={$token["token"]}");
     }
     $this->access_token = $_REQUEST["access_token"];
     //validate the token
     try {
         new DTOAuthToken($this->db->filter(array("token" => $this->access_token, "type" => 1, "status" => 0)));
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
 public function accessToken()
 {
     $tok_str = $this->provider->token;
     try {
         $token = new DTOAuthToken($this->db->where("type=0 AND token='{$tok_str}' AND status=1"));
         $token->updateToAccessToken($this->db);
         exit("oauth_token={$token["token"]}&oauth_token_secret={$token["secret"]}");
     } catch (Exception $e) {
         throw new Exception("Unauthorized token ('{$tok_str}'). Request denied.", DT_ERR_UNAUTHORIZED_TOKEN);
     }
 }
 /** performs standard authentication, authorizing the relevant token if necessary */
 public function actionAuthenticate()
 {
     $u = parent::actionAuthenticate();
     if (isset($u)) {
         try {
             //create oauth token
             $token = DTOAuthToken::upsert($this->db->qb()->fail(), array("type" => 0, "status" => 1, "user_id" => $u["id"]));
             $redirect_uri = $this->params->stringParam("redirect_uri");
             $state = $this->params->stringParam("state");
             $url = $this->appendParams($redirect_uri, array("code" => $token["token"], "state" => $state));
             DTLog::debug($url);
             header('HTTP/1.1 278 Client Redirect', true, 278);
             return array("location" => $url);
         } catch (Exception $e) {
             DTLog::Debug("auth error: " . $e->getMessage());
         }
         //the user failed to authenticate (maybe bad user/pass)
     }
     return $u;
 }