4 use Friendica\Core\Config;
5 use Friendica\Database\DBM;
6 use Friendica\Module\Login;
8 require_once('include/api.php');
10 function oauth_get_client($request)
14 $params = $request->get_parameters();
15 $token = $params['oauth_token'];
17 $r = q("SELECT `clients`.*
18 FROM `clients`, `tokens`
19 WHERE `clients`.`client_id`=`tokens`.`client_id`
20 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", dbesc($token));
22 if (!DBM::is_result($r))
28 function api_post(App $a)
31 notice(t('Permission denied.') . EOL);
35 if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
36 notice(t('Permission denied.') . EOL);
41 function api_content(App $a)
43 if ($a->cmd == 'api/oauth/authorize') {
45 * api/oauth/authorize interact with the user. return a standard page
48 $a->page['template'] = "minimal";
50 // get consumer/client from request token
52 $request = OAuthRequest::from_request();
53 } catch (Exception $e) {
59 if (x($_POST, 'oauth_yes')) {
60 $app = oauth_get_client($request);
62 return "Invalid request. Unknown token.";
64 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
66 $verifier = md5($app['secret'] . local_user());
67 Config::set("oauth", $verifier, local_user());
69 if ($consumer->callback_url != null) {
70 $params = $request->get_parameters();
72 if (strstr($consumer->callback_url, $glue)) {
75 goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
79 $tpl = get_markup_template("oauth_authorize_done.tpl");
80 $o = replace_macros($tpl, [
81 '$title' => t('Authorize application connection'),
82 '$info' => t('Return to your app and insert this Securty Code:'),
90 /// @TODO We need login form to redirect to this page
91 notice(t('Please login to continue.') . EOL);
92 return Login::form($a->query_string, false, $request->get_parameters());
94 //FKOAuth1::loginUser(4);
96 $app = oauth_get_client($request);
98 return "Invalid request. Unknown token.";
101 $tpl = get_markup_template('oauth_authorize.tpl');
102 $o = replace_macros($tpl, [
103 '$title' => t('Authorize application connection'),
105 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),