6 use Friendica\Core\Config;
7 use Friendica\Core\L10n;
8 use Friendica\Database\DBM;
9 use Friendica\Module\Login;
11 require_once 'include/api.php';
13 function oauth_get_client($request)
17 $params = $request->get_parameters();
18 $token = $params['oauth_token'];
20 $r = q("SELECT `clients`.*
21 FROM `clients`, `tokens`
22 WHERE `clients`.`client_id`=`tokens`.`client_id`
23 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", dbesc($token));
25 if (!DBM::is_result($r)) {
32 function api_post(App $a)
35 notice(L10n::t('Permission denied.') . EOL);
39 if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
40 notice(L10n::t('Permission denied.') . EOL);
45 function api_content(App $a)
47 if ($a->cmd == 'api/oauth/authorize') {
49 * api/oauth/authorize interact with the user. return a standard page
52 $a->page['template'] = "minimal";
54 // get consumer/client from request token
56 $request = OAuthRequest::from_request();
57 } catch (Exception $e) {
63 if (x($_POST, 'oauth_yes')) {
64 $app = oauth_get_client($request);
66 return "Invalid request. Unknown token.";
68 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
70 $verifier = md5($app['secret'] . local_user());
71 Config::set("oauth", $verifier, local_user());
73 if ($consumer->callback_url != null) {
74 $params = $request->get_parameters();
76 if (strstr($consumer->callback_url, $glue)) {
79 goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
83 $tpl = get_markup_template("oauth_authorize_done.tpl");
84 $o = replace_macros($tpl, [
85 '$title' => L10n::t('Authorize application connection'),
86 '$info' => L10n::t('Return to your app and insert this Securty Code:'),
94 /// @TODO We need login form to redirect to this page
95 notice(L10n::t('Please login to continue.') . EOL);
96 return Login::form($a->query_string, false, $request->get_parameters());
98 //FKOAuth1::loginUser(4);
100 $app = oauth_get_client($request);
102 return "Invalid request. Unknown token.";
105 $tpl = get_markup_template('oauth_authorize.tpl');
106 $o = replace_macros($tpl, [
107 '$title' => L10n::t('Authorize application connection'),
109 '$authorize' => L10n::t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
110 '$yes' => L10n::t('Yes'),
111 '$no' => L10n::t('No'),