5 require_once('include/api.php');
7 function oauth_get_client($request){
10 $params = $request->get_parameters();
11 $token = $params['oauth_token'];
13 $r = q("SELECT `clients`.*
14 FROM `clients`, `tokens`
15 WHERE `clients`.`client_id`=`tokens`.`client_id`
16 AND `tokens`.`id`='%s' AND `tokens`.`scope`='request'",
19 if (!dbm::is_result($r))
25 function api_post(App $a) {
28 notice( t('Permission denied.') . EOL);
32 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
33 notice( t('Permission denied.') . EOL);
39 function api_content(App $a) {
40 if ($a->cmd=='api/oauth/authorize'){
42 * api/oauth/authorize interact with the user. return a standard page
45 $a->page['template'] = "minimal";
48 // get consumer/client from request token
50 $request = OAuthRequest::from_request();
51 } catch(Exception $e) {
52 echo "<pre>"; var_dump($e); killme();
56 if (x($_POST,'oauth_yes')){
58 $app = oauth_get_client($request);
59 if (is_null($app)) return "Invalid request. Unknown token.";
60 $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
62 $verifier = md5($app['secret'].local_user());
63 set_config("oauth", $verifier, local_user());
66 if ($consumer->callback_url!=null) {
67 $params = $request->get_parameters();
69 if (strstr($consumer->callback_url,$glue)) $glue="?";
70 goaway($consumer->callback_url.$glue."oauth_token=".OAuthUtil::urlencode_rfc3986($params['oauth_token'])."&oauth_verifier=".OAuthUtil::urlencode_rfc3986($verifier));
76 $tpl = get_markup_template("oauth_authorize_done.tpl");
77 $o = replace_macros($tpl, array(
78 '$title' => t('Authorize application connection'),
79 '$info' => t('Return to your app and insert this Securty Code:'),
90 /// @TODO We need login form to redirect to this page
91 notice( t('Please login to continue.') . EOL );
92 return login(false,$request->get_parameters());
94 //FKOAuth1::loginUser(4);
96 $app = oauth_get_client($request);
97 if (is_null($app)) return "Invalid request. Unknown token.";
102 $tpl = get_markup_template('oauth_authorize.tpl');
103 $o = replace_macros($tpl, array(
104 '$title' => t('Authorize application connection'),
106 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),