Exemple #1
0
 function lookup_consumer($consumer_key)
 {
     $con = Consumer::staticGet('consumer_key', $consumer_key);
     if (!$con) {
         return null;
     }
     return new OAuthConsumer($con->consumer_key, $con->consumer_secret);
 }
 function lookup_consumer($consumer_key)
 {
     $con = Consumer::staticGet('consumer_key', $consumer_key);
     if (!$con) {
         $con = new Consumer();
         $con->consumer_key = $consumer_key;
         $con->seed = common_good_rand(16);
         $con->created = DB_DataObject_Cast::dateTime();
         if (!$con->insert()) {
             return null;
         }
     }
     return new OAuthConsumer($con->consumer_key, '');
 }
 function lookup_consumer($consumerKey)
 {
     $con = Consumer::staticGet('consumer_key', $consumerKey);
     if (!$con) {
         // Create an anon consumer and anon application if one
         // doesn't exist already
         if ($consumerKey == 'anonymous') {
             common_debug("API OAuth - creating anonymous consumer");
             $con = new Consumer();
             $con->consumer_key = $consumerKey;
             $con->consumer_secret = $consumerKey;
             $con->created = common_sql_now();
             $result = $con->insert();
             if (!$result) {
                 // TRANS: Server error displayed when trying to create an anynymous OAuth consumer.
                 $this->serverError(_('Could not create anonymous consumer.'));
             }
             $app = Oauth_application::getByConsumerKey('anonymous');
             if (!$app) {
                 common_debug("API OAuth - creating anonymous application");
                 $app = new OAuth_application();
                 $app->owner = 1;
                 // XXX: What to do here?
                 $app->consumer_key = $con->consumer_key;
                 $app->name = 'anonymous';
                 $app->icon = 'default-avatar-stream.png';
                 // XXX: Fix this!
                 $app->description = "An anonymous application";
                 // XXX: allow the user to set the access type when
                 // authorizing? Currently we default to r+w for anonymous
                 // OAuth client applications
                 $app->access_type = 3;
                 // read + write
                 $app->type = 2;
                 // desktop
                 $app->created = common_sql_now();
                 $id = $app->insert();
                 if (!$id) {
                     // TRANS: Server error displayed when trying to create an anynymous OAuth application.
                     $this->serverError(_("Could not create anonymous OAuth application."));
                 }
             }
         } else {
             return null;
         }
     }
     return new OAuthConsumer($con->consumer_key, $con->consumer_secret);
 }
 function getConsumer()
 {
     return Consumer::staticGet('consumer_key', $this->consumer_key);
 }