4 use Friendica\Core\Config;
5 use Friendica\Database\DBM;
7 require_once('include/api.php');
9 function oauth_get_client($request)
13 $params = $request->get_parameters();
14 $token = $params['oauth_token'];
16 $r = q("SELECT `clients`.*
17 FROM `clients`, `tokens`
18 WHERE `clients`.`client_id`=`tokens`.`client_id`
19 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'", dbesc($token));
21 if (!DBM::is_result($r))
27 function api_post(App $a)
30 notice(t('Permission denied.') . EOL);
34 if (count($a->user) && x($a->user, 'uid') && $a->user['uid'] != local_user()) {
35 notice(t('Permission denied.') . EOL);
40 function api_content(App $a)
42 if ($a->cmd == 'api/oauth/authorize') {
44 * api/oauth/authorize interact with the user. return a standard page
47 $a->page['template'] = "minimal";
49 // get consumer/client from request token
51 $request = OAuthRequest::from_request();
52 } catch (Exception $e) {
58 if (x($_POST, 'oauth_yes')) {
59 $app = oauth_get_client($request);
61 return "Invalid request. Unknown token.";
63 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
65 $verifier = md5($app['secret'] . local_user());
66 Config::set("oauth", $verifier, local_user());
68 if ($consumer->callback_url != null) {
69 $params = $request->get_parameters();
71 if (strstr($consumer->callback_url, $glue)) {
74 goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
78 $tpl = get_markup_template("oauth_authorize_done.tpl");
79 $o = replace_macros($tpl, array(
80 '$title' => t('Authorize application connection'),
81 '$info' => t('Return to your app and insert this Securty Code:'),
89 /// @TODO We need login form to redirect to this page
90 notice( t('Please login to continue.') . EOL );
91 return login(false,$request->get_parameters());
93 //FKOAuth1::loginUser(4);
95 $app = oauth_get_client($request);
97 return "Invalid request. Unknown token.";
100 $tpl = get_markup_template('oauth_authorize.tpl');
101 $o = replace_macros($tpl, array(
102 '$title' => t('Authorize application connection'),
104 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),