From cc34bb48c7243f78e198ad4d8c1806d5fe886a81 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 6 Oct 2013 12:40:58 +0200 Subject: [PATCH] OAuth related syntax fixes, nothing big Making better use of class autoloading too. --- actions/apioauthaccesstoken.php | 10 +++------- actions/apioauthauthorize.php | 11 ++++------- actions/apioauthpin.php | 2 +- actions/apioauthrequesttoken.php | 6 ++---- actions/oauthappssettings.php | 1 - actions/oauthconnectionssettings.php | 3 +-- actions/showapplication.php | 6 +++--- lib/apiauthaction.php | 6 ++---- ...toauthstore.php => apignusocialoauthdatastore.php} | 8 ++++---- lib/{apioauth.php => apioauthaction.php} | 3 +-- lib/error.php | 2 -- lib/{info.php => infoaction.php} | 0 lib/router.php | 6 +++--- plugins/OpenID/OpenIDPlugin.php | 2 +- 14 files changed, 25 insertions(+), 41 deletions(-) rename lib/{statusnetoauthstore.php => apignusocialoauthdatastore.php} (98%) rename lib/{apioauth.php => apioauthaction.php} (96%) rename lib/{info.php => infoaction.php} (100%) diff --git a/actions/apioauthaccesstoken.php b/actions/apioauthaccesstoken.php index 76b06c28a2..f3d64de225 100644 --- a/actions/apioauthaccesstoken.php +++ b/actions/apioauthaccesstoken.php @@ -28,11 +28,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} - -require_once INSTALLDIR . '/lib/apioauth.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Action for getting OAuth token credentials (exchange an authorized @@ -44,7 +40,7 @@ require_once INSTALLDIR . '/lib/apioauth.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiOauthAccessTokenAction extends ApiOauthAction +class ApiOAuthAccessTokenAction extends ApiOAuthAction { protected $reqToken = null; protected $verifier = null; @@ -60,7 +56,7 @@ class ApiOauthAccessTokenAction extends ApiOauthAction { parent::handle($args); - $datastore = new ApiStatusNetOAuthDataStore(); + $datastore = new ApiGNUSocialOAuthDataStore(); $server = new OAuthServer($datastore); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); diff --git a/actions/apioauthauthorize.php b/actions/apioauthauthorize.php index 1755c36be3..baaea6fd9b 100644 --- a/actions/apioauthauthorize.php +++ b/actions/apioauthauthorize.php @@ -31,9 +31,6 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/lib/apioauth.php'; -require_once INSTALLDIR . '/lib/info.php'; - /** * Authorize an OAuth request token * @@ -43,7 +40,7 @@ require_once INSTALLDIR . '/lib/info.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiOauthAuthorizeAction extends Action +class ApiOAuthAuthorizeAction extends ApiOAuthAction { var $oauthTokenParam; var $reqToken; @@ -71,7 +68,7 @@ class ApiOauthAuthorizeAction extends Action $this->password = $this->arg('password'); $this->oauthTokenParam = $this->arg('oauth_token'); $this->mode = $this->arg('mode'); - $this->store = new ApiStatusNetOAuthDataStore(); + $this->store = new ApiGNUSocialOAuthDataStore(); try { $this->app = $this->store->getAppByRequestToken($this->oauthTokenParam); @@ -367,7 +364,7 @@ class ApiOauthAuthorizeAction extends Action $this->elementStart('form', array('method' => 'post', 'id' => 'form_apioauthauthorize', 'class' => 'form_settings', - 'action' => common_local_url('ApiOauthAuthorize'))); + 'action' => common_local_url('ApiOAuthAuthorize'))); $this->elementStart('fieldset'); $this->element('legend', array('id' => 'apioauthauthorize_allowdeny'), // TRANS: Fieldset legend. @@ -613,7 +610,7 @@ class ApiOauthAuthorizeAction extends Action } if ($this->reqToken->verified_callback == 'oob') { - $pin = new ApiOauthPinAction( + $pin = new ApiOAuthPinAction( $title, $msg, $this->reqToken->verifier, diff --git a/actions/apioauthpin.php b/actions/apioauthpin.php index 22fb95adb5..ad4e7947e2 100644 --- a/actions/apioauthpin.php +++ b/actions/apioauthpin.php @@ -42,7 +42,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiOauthPinAction extends InfoAction +class ApiOAuthPinAction extends InfoAction { function __construct($title, $message, $verifier, $desktopMode = false) { diff --git a/actions/apioauthrequesttoken.php b/actions/apioauthrequesttoken.php index 31e6387462..b9346a9e87 100644 --- a/actions/apioauthrequesttoken.php +++ b/actions/apioauthrequesttoken.php @@ -31,8 +31,6 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/lib/apioauth.php'; - /** * Issue temporary OAuth credentials (a request token) * @@ -42,7 +40,7 @@ require_once INSTALLDIR . '/lib/apioauth.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiOauthRequestTokenAction extends ApiOauthAction +class ApiOAuthRequestTokenAction extends ApiOAuthAction { /** * Take arguments for running @@ -75,7 +73,7 @@ class ApiOauthRequestTokenAction extends ApiOauthAction { parent::handle($args); - $datastore = new ApiStatusNetOAuthDataStore(); + $datastore = new ApiGNUSocialOAuthDataStore(); $server = new OAuthServer($datastore); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); diff --git a/actions/oauthappssettings.php b/actions/oauthappssettings.php index c93a0a1580..d6477f6be9 100644 --- a/actions/oauthappssettings.php +++ b/actions/oauthappssettings.php @@ -32,7 +32,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { } require_once INSTALLDIR . '/lib/applicationlist.php'; -require_once INSTALLDIR . '/lib/statusnetoauthstore.php'; /** * Show a user's registered OAuth applications diff --git a/actions/oauthconnectionssettings.php b/actions/oauthconnectionssettings.php index 1ad4a6f60d..43e6b45898 100644 --- a/actions/oauthconnectionssettings.php +++ b/actions/oauthconnectionssettings.php @@ -32,7 +32,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { } require_once INSTALLDIR . '/lib/applicationlist.php'; -require_once INSTALLDIR . '/lib/statusnetoauthstore.php'; /** * Show connected OAuth applications @@ -169,7 +168,7 @@ class OauthconnectionssettingsAction extends SettingsAction $app = Oauth_application::getKV('id', $appUser->application_id); - $datastore = new ApiStatusNetOAuthDataStore(); + $datastore = new ApiGNUSocialOAuthDataStore(); $datastore->revoke_token($appUser->token, 1); $result = $appUser->delete(); diff --git a/actions/showapplication.php b/actions/showapplication.php index b15c830ad8..acee1862f4 100644 --- a/actions/showapplication.php +++ b/actions/showapplication.php @@ -261,13 +261,13 @@ class ShowApplicationAction extends Action $this->element('dd', null, $consumer->consumer_secret); // TRANS: Field label on application page. $this->element('dt', null, _('Request token URL')); - $this->element('dd', null, common_local_url('ApiOauthRequestToken')); + $this->element('dd', null, common_local_url('ApiOAuthRequestToken')); // TRANS: Field label on application page. $this->element('dt', null, _('Access token URL')); - $this->element('dd', null, common_local_url('ApiOauthAccessToken')); + $this->element('dd', null, common_local_url('ApiOAuthAccessToken')); // TRANS: Field label on application page. $this->element('dt', null, _('Authorize URL')); - $this->element('dd', null, common_local_url('ApiOauthAuthorize')); + $this->element('dd', null, common_local_url('ApiOAuthAuthorize')); $this->elementEnd('dl'); $this->element('p', 'note', diff --git a/lib/apiauthaction.php b/lib/apiauthaction.php index 499c502480..54b05b3d52 100644 --- a/lib/apiauthaction.php +++ b/lib/apiauthaction.php @@ -57,8 +57,6 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR . '/lib/apioauth.php'; - /** * Actions extending this class will require auth * @@ -133,7 +131,7 @@ class ApiAuthAction extends ApiAction */ function getOAuthRequest() { - ApiOauthAction::cleanRequest(); + ApiOAuthAction::cleanRequest(); $req = OAuthRequest::from_request(); @@ -160,7 +158,7 @@ class ApiAuthAction extends ApiAction */ function checkOAuthRequest($request) { - $datastore = new ApiStatusNetOAuthDataStore(); + $datastore = new ApiGNUSocialOAuthDataStore(); $server = new OAuthServer($datastore); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); diff --git a/lib/statusnetoauthstore.php b/lib/apignusocialoauthdatastore.php similarity index 98% rename from lib/statusnetoauthstore.php rename to lib/apignusocialoauthdatastore.php index bcf6a180aa..5a0c2a8243 100644 --- a/lib/statusnetoauthstore.php +++ b/lib/apignusocialoauthdatastore.php @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } +if (!defined('GNUSOCIAL')) { exit(1); } require_once 'OAuth.php'; /** * @fixme class doc */ -class ApiStatusNetOAuthDataStore extends OAuthDataStore +class ApiGNUSocialOAuthDataStore extends OAuthDataStore { function lookup_consumer($consumerKey) { @@ -120,7 +120,7 @@ class ApiStatusNetOAuthDataStore extends OAuthDataStore } } - function new_access_token($token, $consumer, $verifier) + function new_access_token($token, $consumer, $verifier = null) { common_debug( sprintf( @@ -405,7 +405,7 @@ class ApiStatusNetOAuthDataStore extends OAuthDataStore $t->verifier = common_good_rand(8); } - $t->created = DB_DataObject_Cast::dateTime(); + $t->created = common_sql_now(); if (!$t->insert()) { return null; } else { diff --git a/lib/apioauth.php b/lib/apioauthaction.php similarity index 96% rename from lib/apioauth.php rename to lib/apioauthaction.php index a93811cc0f..8da7e5c61c 100644 --- a/lib/apioauth.php +++ b/lib/apioauthaction.php @@ -31,7 +31,6 @@ if (!defined('STATUSNET')) { exit(1); } require_once INSTALLDIR . '/lib/apiaction.php'; -require_once INSTALLDIR . '/lib/statusnetoauthstore.php'; /** * Base action for API OAuth enpoints. Clean up the @@ -43,7 +42,7 @@ require_once INSTALLDIR . '/lib/statusnetoauthstore.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ -class ApiOauthAction extends ApiAction +class ApiOAuthAction extends ApiAction { /** * Is this a read-only action? diff --git a/lib/error.php b/lib/error.php index c24f3bbf43..e7bdd05707 100644 --- a/lib/error.php +++ b/lib/error.php @@ -33,8 +33,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } -require_once INSTALLDIR . '/lib/info.php'; - /** * Base class for displaying HTTP errors * diff --git a/lib/info.php b/lib/infoaction.php similarity index 100% rename from lib/info.php rename to lib/infoaction.php diff --git a/lib/router.php b/lib/router.php index 0180594e26..a7b59e6ab4 100644 --- a/lib/router.php +++ b/lib/router.php @@ -787,13 +787,13 @@ class Router $m->connect('api/trends.json', array('action' => 'ApiTrends')); $m->connect('api/oauth/request_token', - array('action' => 'ApiOauthRequestToken')); + array('action' => 'ApiOAuthRequestToken')); $m->connect('api/oauth/access_token', - array('action' => 'ApiOauthAccessToken')); + array('action' => 'ApiOAuthAccessToken')); $m->connect('api/oauth/authorize', - array('action' => 'ApiOauthAuthorize')); + array('action' => 'ApiOAuthAuthorize')); // Admin diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 0e05983806..e48b616f4d 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -738,7 +738,7 @@ class OpenIDPlugin extends Plugin oid_assert_allowed($openid_url); $returnto = common_local_url( - 'ApiOauthAuthorize', + 'ApiOAuthAuthorize', array(), array( 'oauth_token' => $action->arg('oauth_token'),