6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\Module\Login;
13 require_once 'include/api.php';
15 function oauth_get_client($request)
19 $params = $request->get_parameters();
20 $token = $params['oauth_token'];
22 $r = q("SELECT `clients`.*
23 FROM `clients`, `tokens`
24 WHERE `clients`.`client_id`=`tokens`.`client_id`
25 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", DBA::escape($token));
27 if (!DBA::isResult($r)) {
34 function api_post(App $a)
37 notice(L10n::t('Permission denied.') . EOL);
41 if (count($a->user) && !empty($a->user['uid']) && $a->user['uid'] != local_user()) {
42 notice(L10n::t('Permission denied.') . EOL);
47 function api_content(App $a)
49 if ($a->cmd == 'api/oauth/authorize') {
51 * api/oauth/authorize interact with the user. return a standard page
54 $a->page['template'] = "minimal";
56 // get consumer/client from request token
58 $request = OAuthRequest::from_request();
59 } catch (Exception $e) {
65 if (!empty($_POST['oauth_yes'])) {
66 $app = oauth_get_client($request);
68 return "Invalid request. Unknown token.";
70 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
72 $verifier = md5($app['secret'] . local_user());
73 Config::set("oauth", $verifier, local_user());
75 if ($consumer->callback_url != null) {
76 $params = $request->get_parameters();
78 if (strstr($consumer->callback_url, $glue)) {
81 $a->internalRedirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier));
85 $tpl = Renderer::getMarkupTemplate("oauth_authorize_done.tpl");
86 $o = Renderer::replaceMacros($tpl, [
87 '$title' => L10n::t('Authorize application connection'),
88 '$info' => L10n::t('Return to your app and insert this Securty Code:'),
96 /// @TODO We need login form to redirect to this page
97 notice(L10n::t('Please login to continue.') . EOL);
98 return Login::form($a->query_string, false, $request->get_parameters());
100 //FKOAuth1::loginUser(4);
102 $app = oauth_get_client($request);
104 return "Invalid request. Unknown token.";
107 $tpl = Renderer::getMarkupTemplate('oauth_authorize.tpl');
108 $o = Renderer::replaceMacros($tpl, [
109 '$title' => L10n::t('Authorize application connection'),
111 '$authorize' => L10n::t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
112 '$yes' => L10n::t('Yes'),
113 '$no' => L10n::t('No'),