3 require_once('include/api.php');
5 function oauth_get_client(){
6 // get consumer/client from request token
8 $request = OAuthRequest::from_request();
9 } catch(Exception $e) {
10 echo "<pre>"; var_dump($e); killme();
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'",
28 function api_post(&$a) {
31 notice( t('Permission denied.') . EOL);
35 if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
36 notice( t('Permission denied.') . EOL);
42 function api_content(&$a) {
43 if ($a->cmd=='api/oauth/authorize'){
45 * api/oauth/authorize interact with the user. return a standard page
49 if (x($_POST,'oauth_yes')){
52 $app = oauth_get_client();
53 if (is_null($app)) return "Invalid request. Unknown token.";
54 $consumer = new OAuthConsumer($app['key'], $app['secret']);
57 $request = OAuthRequest::from_request();
58 $callback = $request->get_parameter('oauth_callback');
59 $datastore = new FKOAuthDataStore();
60 $new_token = $datastore->new_request_token($consumer, $callback);
62 $tpl = get_markup_template("oauth_authorize_done.tpl");
63 $o = replace_macros($tpl, array(
64 '$title' => t('Authorize application connection'),
65 '$info' => t('Return to your app and insert this Securty Code:'),
66 '$code' => $new_token->key,
77 //TODO: we need login form to redirect to this page
78 notice( t('Please login to continue.') . EOL );
82 $app = oauth_get_client();
83 if (is_null($app)) return "Invalid request. Unknown token.";
86 $tpl = get_markup_template('oauth_authorize.tpl');
87 $o = replace_macros($tpl, array(
88 '$title' => t('Authorize application connection'),
90 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
95 //echo "<pre>"; var_dump($app); killme();