6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Module\Login;
12 require_once 'include/api.php';
14 function oauth_get_client($request)
18 $params = $request->get_parameters();
19 $token = $params['oauth_token'];
21 $r = q("SELECT `clients`.*
22 FROM `clients`, `tokens`
23 WHERE `clients`.`client_id`=`tokens`.`client_id`
24 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", DBA::escape($token));
26 if (!DBA::isResult($r)) {
33 function api_post(App $a)
36 notice(L10n::t('Permission denied.') . EOL);
40 if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
41 notice(L10n::t('Permission denied.') . EOL);
46 function api_content(App $a)
48 if ($a->cmd == 'api/oauth/authorize') {
50 * api/oauth/authorize interact with the user. return a standard page
53 $a->page['template'] = "minimal";
55 // get consumer/client from request token
57 $request = OAuthRequest::from_request();
58 } catch (Exception $e) {
64 if (x($_POST, 'oauth_yes')) {
65 $app = oauth_get_client($request);
67 return "Invalid request. Unknown token.";
69 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
71 $verifier = md5($app['secret'] . local_user());
72 Config::set("oauth", $verifier, local_user());
74 if ($consumer->callback_url != null) {
75 $params = $request->get_parameters();
77 if (strstr($consumer->callback_url, $glue)) {
80 $a->redirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier));
84 $tpl = get_markup_template("oauth_authorize_done.tpl");
85 $o = replace_macros($tpl, [
86 '$title' => L10n::t('Authorize application connection'),
87 '$info' => L10n::t('Return to your app and insert this Securty Code:'),
95 /// @TODO We need login form to redirect to this page
96 notice(L10n::t('Please login to continue.') . EOL);
97 return Login::form($a->query_string, false, $request->get_parameters());
99 //FKOAuth1::loginUser(4);
101 $app = oauth_get_client($request);
103 return "Invalid request. Unknown token.";
106 $tpl = get_markup_template('oauth_authorize.tpl');
107 $o = replace_macros($tpl, [
108 '$title' => L10n::t('Authorize application connection'),
110 '$authorize' => L10n::t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
111 '$yes' => L10n::t('Yes'),
112 '$no' => L10n::t('No'),