+ /*
+ * Show a nice message confirming the authorization
+ * operation was canceled.
+ *
+ * @return nothing
+ */
+ function showCanceled()
+ {
+ $info = new InfoAction(
+ // TRANS: Header for user notification after revoking OAuth access to an application.
+ _('Authorization canceled.'),
+ sprintf(
+ // TRANS: User notification after revoking OAuth access to an application.
+ // TRANS: %s is an OAuth token.
+ _('The request token %s has been revoked.'),
+ $this->oauthTokenParam
+ )
+ );
+
+ $info->showPage();
+ }
+
+ /*
+ * Show a nice message that the authorization was successful.
+ * If the operation is out-of-band, show a pin.
+ *
+ * @return nothing
+ */
+ function showAuthorized()
+ {
+ $title = null;
+ $msg = null;
+
+ if ($this->app->name == 'anonymous') {
+
+ $title =
+ // TRANS: Title of the page notifying the user that an anonymous client application was successfully authorized to access the user's account with OAuth.
+ _('You have successfully authorized the application');
+
+ $msg =
+ // TRANS: Message notifying the user that an anonymous client application was successfully authorized to access the user's account with OAuth.
+ _('Please return to the application and enter the following security code to complete the process.');
+
+ } else {
+
+ $title = sprintf(
+ // TRANS: Title of the page notifying the user that the client application was successfully authorized to access the user's account with OAuth.
+ // TRANS: %s is the authorised application name.
+ _('You have successfully authorized %s'),
+ $this->app->name
+ );
+
+ $msg = sprintf(
+ // TRANS: Message notifying the user that the client application was successfully authorized to access the user's account with OAuth.
+ // TRANS: %s is the authorised application name.
+ _('Please return to %s and enter the following security code to complete the process.'),
+ $this->app->name
+ );
+
+ }
+
+ if ($this->reqToken->verified_callback == 'oob') {
+ $pin = new ApiOauthPinAction(
+ $title,
+ $msg,
+ $this->reqToken->verifier,
+ $this->desktopMode()
+ );
+ $pin->showPage();
+ } else {
+ // NOTE: This would only happen if an application registered as
+ // a web application but sent in 'oob' for the oauth_callback
+ // parameter. Usually web apps will send in a callback and
+ // not use the pin-based workflow.
+
+ $info = new InfoAction(
+ $title,
+ $msg,
+ $this->oauthTokenParam,
+ $this->reqToken->verifier
+ );
+
+ $info->showPage();
+ }
+ }
+
+ /*
+ * Figure out what the callback should be
+ */
+ function getCallback()
+ {
+ $callback = null;
+
+ // Return the verified callback if we have one
+ if ($this->reqToken->verified_callback != 'oob') {
+
+ $callback = $this->reqToken->verified_callback;
+
+ // Otherwise return the callback that was provided when
+ // registering the app
+ if (empty($callback)) {
+
+ common_debug(
+ "No verified callback found for request token, using application callback: "
+ . $this->app->callback_url,
+ __FILE__
+ );
+
+ $callback = $this->app->callback_url;
+ }
+ }
+
+ return $callback;
+ }
+
+ /*
+ * Properly format the callback URL and parameters so it's
+ * suitable for a redirect in the OAuth dance
+ *
+ * @param string $url the URL
+ * @param array $params an array of parameters
+ *
+ * @return string $url a URL to use for redirecting to
+ */
+ function buildCallbackUrl($url, $params)
+ {
+ foreach ($params as $k => $v) {
+ $url = $this->appendQueryVar(
+ $url,
+ OAuthUtil::urlencode_rfc3986($k),
+ OAuthUtil::urlencode_rfc3986($v)
+ );
+ }
+
+ return $url;
+ }
+
+ /*
+ * Append a new query parameter after any existing query
+ * parameters.
+ *
+ * @param string $url the URL
+ * @prarm string $k the parameter name
+ * @param string $v value of the paramter
+ *
+ * @return string $url the new URL with added parameter
+ */
+ function appendQueryVar($url, $k, $v) {
+ $url = preg_replace('/(.*)(\?|&)' . $k . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
+ $url = substr($url, 0, -1);
+ if (strpos($url, '?') === false) {
+ return ($url . '?' . $k . '=' . $v);
+ } else {
+ return ($url . '&' . $k . '=' . $v);
+ }
+ }