source: trunk/prototype/me.php @ 6528

Revision 6528, 2.2 KB checked in by gustavo, 12 years ago (diff)

Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk

Line 
1<?php
2require_once  (dirname(__FILE__).'/api/controller.php');
3use prototype\api\Config as Config;
4
5$me = Controller::read(array('concept' => 'user', 'service' => 'OpenLDAP'  , 'id' => Config::me('uidNumber')));
6
7if(isset($_POST['refreshToken'])){
8   
9    $ch = curl_init();
10
11    $restConf = parse_ini_file( __DIR__ . '/config/REST.ini', true );
12
13    $param  = 'grant_type=refresh_token';
14    $param .= '&client_id=' . $restConf['oauth']['client_id'];
15    $param .= '&client_secret=' . $restConf['oauth']['client_secret'];
16    $param .= '&refresh_token=' . $_SESSION['oauth']['refresh_token'];
17
18    // set URL and other appropriate options
19    curl_setopt($ch, CURLOPT_URL, $restConf['oauth']['url_token']);
20    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: */*'));
21    curl_setopt($ch, CURLOPT_POST, TRUE);
22    curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
23    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);  //configura para nao imprimir a saida na tela
24    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);//Passe um número long como parâmetro que contêm o limite de tempo, em segundos, que você permite as funções CURL levar.
25
26    // grab URL and pass it to the browser
27    $res = curl_exec($ch);
28
29    // close cURL resource, and free up system resources
30    curl_close($ch);
31    $a = json_decode($res);
32
33    if ( isset($a->access_token) ) {
34        $_SESSION['oauth']['access_token'] = $a->access_token;
35        $_SESSION['oauth']['expires_in'] = $a->expires_in;
36        $_SESSION['oauth']['token_type'] = $a->token_type;
37        $_SESSION['oauth']['scope'] = $a->scope;
38        $_SESSION['oauth']['refresh_token'] = $a->refresh_token;
39        $_SESSION['oauth']['client_secret'] = $restConf['oauth']['client_secret'];
40    }  else {
41        echo json_encode(null);
42        return;
43    }
44}
45
46$me['token'] = $_SESSION['oauth']['access_token'];
47echo json_encode( $me );
48
49// if( !$me )
50//     return;
51//
52// $links = Controller::links();
53//
54// $return = array();
55//
56// foreach( $links as $concept => $link )
57// {
58//     $concepts = array();
59//
60//     foreach( $link as $linkName => $linkTarget )
61//       if( Controller::isConcept( $linkName ) )
62//          $concepts[ $linkName ] = true;
63//
64//      $return[ $concept ] = array( 'concepts' => $concepts, 'links' => $link );
65// }
66//
67// echo json_encode( array( 'me' => $me, 'links' => $return ) );
Note: See TracBrowser for help on using the repository browser.