$con = new Consumer();
$con->consumer_key = $consumerKey;
$con->consumer_secret = $consumerKey;
+ $con->created = common_sql_now();
+
$result = $con->insert();
if (!$result) {
- $this->serverError(_("Could not create anonymous consumer."));
+ // TRANS: Server error displayed when trying to create an anynymous OAuth consumer.
+ $this->serverError(_('Could not create anonymous consumer.'));
}
- $app = new OAuth_application();
- $app->consumer_key = $con->consumer_key;
- $app->name = 'anonymous';
-
- // 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
- $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.'));
+
+ $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;