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']);
56 $verifier = md5($app['secret'].local_user());
57 set_pconfig(local_user(), "oauth", "verifier", $verifier);
59 $tpl = get_markup_template("oauth_authorize_done.tpl");
60 $o = replace_macros($tpl, array(
61 '$title' => t('Authorize application connection'),
62 '$info' => t('Return to your app and insert this Securty Code:'),
74 //TODO: we need login form to redirect to this page
75 notice( t('Please login to continue.') . EOL );
79 $app = oauth_get_client();
80 if (is_null($app)) return "Invalid request. Unknown token.";
83 $tpl = get_markup_template('oauth_authorize.tpl');
84 $o = replace_macros($tpl, array(
85 '$title' => t('Authorize application connection'),
87 '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
92 //echo "<pre>"; var_dump($app); killme();