OAuth related syntax fixes, nothing big

Making better use of class autoloading too.
This commit is contained in:
Mikael Nordfeldth 2013-10-06 12:40:58 +02:00
parent 5974493707
commit cc34bb48c7
14 changed files with 25 additions and 41 deletions

View File

@ -28,11 +28,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('STATUSNET')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
require_once INSTALLDIR . '/lib/apioauth.php';
/** /**
* Action for getting OAuth token credentials (exchange an authorized * 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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiOauthAccessTokenAction extends ApiOauthAction class ApiOAuthAccessTokenAction extends ApiOAuthAction
{ {
protected $reqToken = null; protected $reqToken = null;
protected $verifier = null; protected $verifier = null;
@ -60,7 +56,7 @@ class ApiOauthAccessTokenAction extends ApiOauthAction
{ {
parent::handle($args); parent::handle($args);
$datastore = new ApiStatusNetOAuthDataStore(); $datastore = new ApiGNUSocialOAuthDataStore();
$server = new OAuthServer($datastore); $server = new OAuthServer($datastore);
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();

View File

@ -31,9 +31,6 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once INSTALLDIR . '/lib/apioauth.php';
require_once INSTALLDIR . '/lib/info.php';
/** /**
* Authorize an OAuth request token * 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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiOauthAuthorizeAction extends Action class ApiOAuthAuthorizeAction extends ApiOAuthAction
{ {
var $oauthTokenParam; var $oauthTokenParam;
var $reqToken; var $reqToken;
@ -71,7 +68,7 @@ class ApiOauthAuthorizeAction extends Action
$this->password = $this->arg('password'); $this->password = $this->arg('password');
$this->oauthTokenParam = $this->arg('oauth_token'); $this->oauthTokenParam = $this->arg('oauth_token');
$this->mode = $this->arg('mode'); $this->mode = $this->arg('mode');
$this->store = new ApiStatusNetOAuthDataStore(); $this->store = new ApiGNUSocialOAuthDataStore();
try { try {
$this->app = $this->store->getAppByRequestToken($this->oauthTokenParam); $this->app = $this->store->getAppByRequestToken($this->oauthTokenParam);
@ -367,7 +364,7 @@ class ApiOauthAuthorizeAction extends Action
$this->elementStart('form', array('method' => 'post', $this->elementStart('form', array('method' => 'post',
'id' => 'form_apioauthauthorize', 'id' => 'form_apioauthauthorize',
'class' => 'form_settings', 'class' => 'form_settings',
'action' => common_local_url('ApiOauthAuthorize'))); 'action' => common_local_url('ApiOAuthAuthorize')));
$this->elementStart('fieldset'); $this->elementStart('fieldset');
$this->element('legend', array('id' => 'apioauthauthorize_allowdeny'), $this->element('legend', array('id' => 'apioauthauthorize_allowdeny'),
// TRANS: Fieldset legend. // TRANS: Fieldset legend.
@ -613,7 +610,7 @@ class ApiOauthAuthorizeAction extends Action
} }
if ($this->reqToken->verified_callback == 'oob') { if ($this->reqToken->verified_callback == 'oob') {
$pin = new ApiOauthPinAction( $pin = new ApiOAuthPinAction(
$title, $title,
$msg, $msg,
$this->reqToken->verifier, $this->reqToken->verifier,

View File

@ -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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiOauthPinAction extends InfoAction class ApiOAuthPinAction extends InfoAction
{ {
function __construct($title, $message, $verifier, $desktopMode = false) function __construct($title, $message, $verifier, $desktopMode = false)
{ {

View File

@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once INSTALLDIR . '/lib/apioauth.php';
/** /**
* Issue temporary OAuth credentials (a request token) * 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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiOauthRequestTokenAction extends ApiOauthAction class ApiOAuthRequestTokenAction extends ApiOAuthAction
{ {
/** /**
* Take arguments for running * Take arguments for running
@ -75,7 +73,7 @@ class ApiOauthRequestTokenAction extends ApiOauthAction
{ {
parent::handle($args); parent::handle($args);
$datastore = new ApiStatusNetOAuthDataStore(); $datastore = new ApiGNUSocialOAuthDataStore();
$server = new OAuthServer($datastore); $server = new OAuthServer($datastore);
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();

View File

@ -32,7 +32,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
} }
require_once INSTALLDIR . '/lib/applicationlist.php'; require_once INSTALLDIR . '/lib/applicationlist.php';
require_once INSTALLDIR . '/lib/statusnetoauthstore.php';
/** /**
* Show a user's registered OAuth applications * Show a user's registered OAuth applications

View File

@ -32,7 +32,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
} }
require_once INSTALLDIR . '/lib/applicationlist.php'; require_once INSTALLDIR . '/lib/applicationlist.php';
require_once INSTALLDIR . '/lib/statusnetoauthstore.php';
/** /**
* Show connected OAuth applications * Show connected OAuth applications
@ -169,7 +168,7 @@ class OauthconnectionssettingsAction extends SettingsAction
$app = Oauth_application::getKV('id', $appUser->application_id); $app = Oauth_application::getKV('id', $appUser->application_id);
$datastore = new ApiStatusNetOAuthDataStore(); $datastore = new ApiGNUSocialOAuthDataStore();
$datastore->revoke_token($appUser->token, 1); $datastore->revoke_token($appUser->token, 1);
$result = $appUser->delete(); $result = $appUser->delete();

View File

@ -261,13 +261,13 @@ class ShowApplicationAction extends Action
$this->element('dd', null, $consumer->consumer_secret); $this->element('dd', null, $consumer->consumer_secret);
// TRANS: Field label on application page. // TRANS: Field label on application page.
$this->element('dt', null, _('Request token URL')); $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. // TRANS: Field label on application page.
$this->element('dt', null, _('Access token URL')); $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. // TRANS: Field label on application page.
$this->element('dt', null, _('Authorize URL')); $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->elementEnd('dl');
$this->element('p', 'note', $this->element('p', 'note',

View File

@ -57,8 +57,6 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once INSTALLDIR . '/lib/apioauth.php';
/** /**
* Actions extending this class will require auth * Actions extending this class will require auth
* *
@ -133,7 +131,7 @@ class ApiAuthAction extends ApiAction
*/ */
function getOAuthRequest() function getOAuthRequest()
{ {
ApiOauthAction::cleanRequest(); ApiOAuthAction::cleanRequest();
$req = OAuthRequest::from_request(); $req = OAuthRequest::from_request();
@ -160,7 +158,7 @@ class ApiAuthAction extends ApiAction
*/ */
function checkOAuthRequest($request) function checkOAuthRequest($request)
{ {
$datastore = new ApiStatusNetOAuthDataStore(); $datastore = new ApiGNUSocialOAuthDataStore();
$server = new OAuthServer($datastore); $server = new OAuthServer($datastore);
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();

View File

@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } if (!defined('GNUSOCIAL')) { exit(1); }
require_once 'OAuth.php'; require_once 'OAuth.php';
/** /**
* @fixme class doc * @fixme class doc
*/ */
class ApiStatusNetOAuthDataStore extends OAuthDataStore class ApiGNUSocialOAuthDataStore extends OAuthDataStore
{ {
function lookup_consumer($consumerKey) 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( common_debug(
sprintf( sprintf(
@ -405,7 +405,7 @@ class ApiStatusNetOAuthDataStore extends OAuthDataStore
$t->verifier = common_good_rand(8); $t->verifier = common_good_rand(8);
} }
$t->created = DB_DataObject_Cast::dateTime(); $t->created = common_sql_now();
if (!$t->insert()) { if (!$t->insert()) {
return null; return null;
} else { } else {

View File

@ -31,7 +31,6 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once INSTALLDIR . '/lib/apiaction.php'; require_once INSTALLDIR . '/lib/apiaction.php';
require_once INSTALLDIR . '/lib/statusnetoauthstore.php';
/** /**
* Base action for API OAuth enpoints. Clean up the * 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 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ApiOauthAction extends ApiAction class ApiOAuthAction extends ApiAction
{ {
/** /**
* Is this a read-only action? * Is this a read-only action?

View File

@ -33,8 +33,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1); exit(1);
} }
require_once INSTALLDIR . '/lib/info.php';
/** /**
* Base class for displaying HTTP errors * Base class for displaying HTTP errors
* *

View File

@ -787,13 +787,13 @@ class Router
$m->connect('api/trends.json', array('action' => 'ApiTrends')); $m->connect('api/trends.json', array('action' => 'ApiTrends'));
$m->connect('api/oauth/request_token', $m->connect('api/oauth/request_token',
array('action' => 'ApiOauthRequestToken')); array('action' => 'ApiOAuthRequestToken'));
$m->connect('api/oauth/access_token', $m->connect('api/oauth/access_token',
array('action' => 'ApiOauthAccessToken')); array('action' => 'ApiOAuthAccessToken'));
$m->connect('api/oauth/authorize', $m->connect('api/oauth/authorize',
array('action' => 'ApiOauthAuthorize')); array('action' => 'ApiOAuthAuthorize'));
// Admin // Admin

View File

@ -738,7 +738,7 @@ class OpenIDPlugin extends Plugin
oid_assert_allowed($openid_url); oid_assert_allowed($openid_url);
$returnto = common_local_url( $returnto = common_local_url(
'ApiOauthAuthorize', 'ApiOAuthAuthorize',
array(), array(),
array( array(
'oauth_token' => $action->arg('oauth_token'), 'oauth_token' => $action->arg('oauth_token'),