6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
9 use Friendica\Database\DBA;
10 use Friendica\Module\Login;
12 require_once 'include/api.php';
14 function oauth_get_client(OAuthRequest $request)
16 $params = $request->get_parameters();
17 $token = $params['oauth_token'];
19 $r = q("SELECT `clients`.*
20 FROM `clients`, `tokens`
21 WHERE `clients`.`client_id`=`tokens`.`client_id`
22 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", DBA::escape($token));
24 if (!DBA::isResult($r)) {
31 function api_post(App $a)
34 notice(L10n::t('Permission denied.') . EOL);
38 if (count($a->user) && !empty($a->user['uid']) && $a->user['uid'] != local_user()) {
39 notice(L10n::t('Permission denied.') . EOL);
44 function api_content(App $a)
46 if ($a->cmd == 'api/oauth/authorize') {
48 * api/oauth/authorize interact with the user. return a standard page
51 $a->page['template'] = "minimal";
53 // get consumer/client from request token
55 $request = OAuthRequest::from_request();
56 } catch (Exception $e) {
62 if (!empty($_POST['oauth_yes'])) {
63 $app = oauth_get_client($request);
65 return "Invalid request. Unknown token.";
67 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
69 $verifier = md5($app['secret'] . local_user());
70 Config::set("oauth", $verifier, local_user());
72 if ($consumer->callback_url != null) {
73 $params = $request->get_parameters();
75 if (strstr($consumer->callback_url, $glue)) {
78 $a->internalRedirect($consumer->callback_url . $glue . 'oauth_token=' . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . '&oauth_verifier=' . OAuthUtil::urlencode_rfc3986($verifier));
82 $tpl = Renderer::getMarkupTemplate("oauth_authorize_done.tpl");
83 $o = Renderer::replaceMacros($tpl, [
84 '$title' => L10n::t('Authorize application connection'),
85 '$info' => L10n::t('Return to your app and insert this Securty Code:'),
93 /// @TODO We need login form to redirect to this page
94 notice(L10n::t('Please login to continue.') . EOL);
95 return Login::form($a->query_string, false, $request->get_parameters());
97 //FKOAuth1::loginUser(4);
99 $app = oauth_get_client($request);
101 return "Invalid request. Unknown token.";
104 $tpl = Renderer::getMarkupTemplate('oauth_authorize.tpl');
105 $o = Renderer::replaceMacros($tpl, [
106 '$title' => L10n::t('Authorize application connection'),
108 '$authorize' => L10n::t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
109 '$yes' => L10n::t('Yes'),
110 '$no' => L10n::t('No'),