]> git.mxchange.org Git - friendica.git/blob - mod/api.php
oauth: authorize view, wrong verifier.
[friendica.git] / mod / api.php
1 <?php
2
3 require_once('include/api.php');
4
5 function oauth_get_client(){
6         // get consumer/client from request token
7         try {
8                 $request = OAuthRequest::from_request();
9         } catch(Exception $e) {
10                 echo "<pre>"; var_dump($e); killme();
11         }
12         
13         $params = $request->get_parameters();
14         $token = $params['oauth_token'];
15         
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'",
20                         dbesc($token));
21
22         if (!count($r))
23                 return null;
24         
25         return $r[0];
26 }
27
28 function api_post(&$a) {
29
30         if(! local_user()) {
31                 notice( t('Permission denied.') . EOL);
32                 return;
33         }
34
35         if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
36                 notice( t('Permission denied.') . EOL);
37                 return;
38         }
39
40 }
41
42 function api_content(&$a) {
43         if ($a->cmd=='api/oauth/authorize'){
44                 /* 
45                  * api/oauth/authorize interact with the user. return a standard page
46                  */
47                 
48                 
49                 if (x($_POST,'oauth_yes')){
50                 
51                 
52                         $app = oauth_get_client();
53                         if (is_null($app)) return "Invalid request. Unknown token.";
54                         $consumer = new OAuthConsumer($app['key'], $app['secret']);
55
56                         $verifier = md5($app['secret'].local_user());
57                         set_pconfig(local_user(), "oauth", "verifier", $verifier);
58                         
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:'),
63                                 '$code' => $verifier,
64                         ));
65                 
66                         return $o;
67                 
68                 
69                 }
70         
71                 
72                 
73                 if(! local_user()) {
74                         //TODO: we need login form to redirect to this page
75                         notice( t('Please login to continue.') . EOL );
76                         return login(false);
77                 }
78                 
79                 $app = oauth_get_client();
80                 if (is_null($app)) return "Invalid request. Unknown token.";
81                 
82                 
83                 $tpl = get_markup_template('oauth_authorize.tpl');
84                 $o = replace_macros($tpl, array(
85                         '$title' => t('Authorize application connection'),
86                         '$app' => $app,
87                         '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'),
88                         '$yes'  => t('Yes'),
89                         '$no'   => t('No'),
90                 ));
91                 
92                 //echo "<pre>"; var_dump($app); killme();
93                 
94                 return $o;
95         }
96         
97         echo api_call($a);
98         killme();
99 }
100
101
102