summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/apioauthauthorize.php45
-rw-r--r--plugins/OpenID/OpenIDPlugin.php95
-rw-r--r--tests/oauth/oauth_post_notice.php2
3 files changed, 123 insertions, 19 deletions
diff --git a/actions/apioauthauthorize.php b/actions/apioauthauthorize.php
index 0e61cdf2c..135c146e5 100644
--- a/actions/apioauthauthorize.php
+++ b/actions/apioauthauthorize.php
@@ -157,9 +157,13 @@ class ApiOauthAuthorizeAction extends Action
// XXX Force credentials check?
- // XXX OpenID
+ // @fixme this should probably use a unified login form handler
+ $user = null;
+ if (Event::handle('StartOAuthLoginCheck', array($this, &$user))) {
+ $user = common_check_user($this->nickname, $this->password);
+ }
+ Event::handle('EndOAuthLoginCheck', array($this, &$user));
- $user = common_check_user($this->nickname, $this->password);
if (empty($user)) {
// TRANS: Form validation error given when an invalid username and/or password was passed to the OAuth API.
$this->showForm(_("Invalid nickname / password!"));
@@ -343,22 +347,27 @@ class ApiOauthAuthorizeAction extends Action
$this->elementEnd('li');
$this->elementEnd('ul');
+ // quickie hack
+ $button = false;
if (!common_logged_in()) {
- $this->elementStart('fieldset');
- // TRANS: Fieldset legend.
- $this->element('legend', null, _m('LEGEND','Account'));
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li');
- // TRANS: Field label on OAuth API authorisation form.
- $this->input('nickname', _('Nickname'));
- $this->elementEnd('li');
- $this->elementStart('li');
- // TRANS: Field label on OAuth API authorisation form.
- $this->password('password', _('Password'));
- $this->elementEnd('li');
- $this->elementEnd('ul');
-
- $this->elementEnd('fieldset');
+ if (Event::handle('StartOAuthLoginForm', array($this, &$button))) {
+ $this->elementStart('fieldset');
+ // TRANS: Fieldset legend.
+ $this->element('legend', null, _m('LEGEND','Account'));
+ $this->elementStart('ul', 'form_data');
+ $this->elementStart('li');
+ // TRANS: Field label on OAuth API authorisation form.
+ $this->input('nickname', _('Nickname'));
+ $this->elementEnd('li');
+ $this->elementStart('li');
+ // TRANS: Field label on OAuth API authorisation form.
+ $this->password('password', _('Password'));
+ $this->elementEnd('li');
+ $this->elementEnd('ul');
+
+ $this->elementEnd('fieldset');
+ }
+ Event::handle('EndOAuthLoginForm', array($this, &$button));
}
$this->element('input', array('id' => 'cancel_submit',
@@ -374,7 +383,7 @@ class ApiOauthAuthorizeAction extends Action
'name' => 'allow',
'type' => 'submit',
// TRANS: Button text that when clicked will allow access to an account by an external application.
- 'value' => _m('BUTTON','Allow')));
+ 'value' => $button ? $button : _m('BUTTON','Allow')));
$this->elementEnd('fieldset');
$this->elementEnd('form');
diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php
index a033a5010..c3dbd3068 100644
--- a/plugins/OpenID/OpenIDPlugin.php
+++ b/plugins/OpenID/OpenIDPlugin.php
@@ -654,4 +654,99 @@ class OpenIDPlugin extends Plugin
_m('Use <a href="http://openid.net/">OpenID</a> to login to the site.'));
return true;
}
+
+ function onStartOAuthLoginForm($action, &$button)
+ {
+ if (common_config('site', 'openidonly')) {
+ // Cancel the regular password login form, we won't need it.
+ $this->showOAuthLoginForm($action);
+ // TRANS: button label for OAuth authorization page when needing OpenID authentication first.
+ $button = _m('BUTTON', 'Continue');
+ return false;
+ } else {
+ // Leave the regular password login form in place.
+ // We'll add an OpenID link at bottom...?
+ return true;
+ }
+ }
+
+ /**
+ * @fixme merge with common code for main OpenID login form
+ * @param HTMLOutputter $action
+ */
+ protected function showOAuthLoginForm($action)
+ {
+ $action->elementStart('fieldset');
+ // TRANS: OpenID plugin logon form legend.
+ $action->element('legend', null, _m('OpenID login'));
+
+ $action->elementStart('ul', 'form_data');
+ $action->elementStart('li');
+ $provider = common_config('openid', 'trusted_provider');
+ $appendUsername = common_config('openid', 'append_username');
+ if ($provider) {
+ $action->element('label', array(), _m('OpenID provider'));
+ $action->element('span', array(), $provider);
+ if ($appendUsername) {
+ $action->element('input', array('id' => 'openid_username',
+ 'name' => 'openid_username',
+ 'style' => 'float: none'));
+ }
+ $action->element('p', 'form_guide',
+ ($appendUsername ? _m('Enter your username.') . ' ' : '') .
+ _m('You will be sent to the provider\'s site for authentication.'));
+ $action->hidden('openid_url', $provider);
+ } else {
+ // TRANS: OpenID plugin logon form field label.
+ $action->input('openid_url', _m('OpenID URL'),
+ '',
+ // TRANS: OpenID plugin logon form field instructions.
+ _m('Your OpenID URL'));
+ }
+ $action->elementEnd('li');
+ $action->elementEnd('ul');
+
+ $action->elementEnd('fieldset');
+ }
+
+ /**
+ * Handle a POST user credential check in apioauthauthorization.
+ * If given an OpenID URL, we'll pass us over to the regular things
+ * and then redirect back here on completion.
+ *
+ * @fixme merge with common code for main OpenID login form
+ * @param HTMLOutputter $action
+ */
+ function onStartOAuthLoginCheck($action, &$user)
+ {
+ $provider = common_config('openid', 'trusted_provider');
+ if ($provider) {
+ $openid_url = $provider;
+ if (common_config('openid', 'append_username')) {
+ $openid_url .= $action->trimmed('openid_username');
+ }
+ } else {
+ $openid_url = $action->trimmed('openid_url');
+ }
+
+ if ($openid_url) {
+ require_once dirname(__FILE__) . '/openid.php';
+ oid_assert_allowed($openid_url);
+
+ $returnto = common_local_url('ApiOauthAuthorize', array(),
+ array('oauth_token' => $action->arg('oauth_token')));
+ common_set_returnto($returnto);
+
+ // This will redirect if functional...
+ $result = oid_authenticate($openid_url,
+ 'finishopenidlogin');
+ if (is_string($result)) { # error message
+ throw new ServerException($result);
+ } else {
+ exit(0);
+ }
+ }
+
+ return true;
+ }
}
diff --git a/tests/oauth/oauth_post_notice.php b/tests/oauth/oauth_post_notice.php
index 5e9d2a7ab..23fc04b53 100644
--- a/tests/oauth/oauth_post_notice.php
+++ b/tests/oauth/oauth_post_notice.php
@@ -23,7 +23,7 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
require_once INSTALLDIR . '/extlib/OAuth.php';
$shortoptions = 't:s:u:';
-$longoptions = array('oauth_token=', 'token_secret=', 'update=');
+$longoptions = array('oauth_token=', 'oauth_token_secret=', 'update=');
$helptext = <<<END_OF_VERIFY_HELP
oauth_post_notice.php [options]