4 use Friendica\Core\Config;
6 require_once('include/api.php');
8 function oauth_get_client($request){
11 $params = $request->get_parameters();
12 $token = $params['oauth_token'];
14 $r = q("SELECT `clients`.*
15 FROM `clients`, `tokens`
16 WHERE `clients`.`client_id`=`tokens`.`client_id`
17 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'",
20 if (!dbm::is_result($r))
26 function api_post(App $a) {
29 notice( t('Permission denied.') . EOL);
33 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
34 notice( t('Permission denied.') . EOL);
40 function api_content(App $a) {
41 if ($a->cmd=='api/oauth/authorize'){
43 * api/oauth/authorize interact with the user. return a standard page
46 $a->page['template'] = "minimal";
49 // get consumer/client from request token
51 $request = OAuthRequest::from_request();
52 } catch(Exception $e) {
53 echo "<pre>"; var_dump($e); killme();
57 if (x($_POST,'oauth_yes')){
59 $app = oauth_get_client($request);
60 if (is_null($app)) return "Invalid request. Unknown token.";
61 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
63 $verifier = md5($app['secret'].local_user());
64 Config::set("oauth", $verifier, local_user());
67 if ($consumer->callback_url!=null) {
68 $params = $request->get_parameters();
70 if (strstr($consumer->callback_url,$glue)) $glue="?";
71 goaway($consumer->callback_url.$glue."oauth_token=".OAuthUtil::urlencode_rfc3986($params['oauth_token'])."&oauth_verifier=".OAuthUtil::urlencode_rfc3986($verifier));
77 $tpl = get_markup_template("oauth_authorize_done.tpl");
78 $o = replace_macros($tpl, array(
79 '$title' => t('Authorize application connection'),
80 '$info' => t('Return to your app and insert this Securty Code:'),
91 /// @TODO We need login form to redirect to this page
92 notice( t('Please login to continue.') . EOL );
93 return login(false,$request->get_parameters());
95 //FKOAuth1::loginUser(4);
97 $app = oauth_get_client($request);
98 if (is_null($app)) return "Invalid request. Unknown token.";
103 $tpl = get_markup_template('oauth_authorize.tpl');
104 $o = replace_macros($tpl, array(
105 '$title' => t('Authorize application connection'),
107 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),