-
Notifications
You must be signed in to change notification settings - Fork 278
/
Resource.php
44 lines (38 loc) · 1.39 KB
/
Resource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace OAuth2Demo\Server\Controllers;
use Silex\Application;
use Symfony\Component\HttpFoundation\Response;
class Resource
{
// Connects the routes in Silex
public static function addRoutes($routing)
{
$routing->get('/resource', array(new self(), 'resource'))->bind('access');
}
/**
* This is called by the client app once the client has obtained an access
* token for the current user. If the token is valid, the resource (in this
* case, the "friends" of the current user) will be returned to the client
*/
public function resource(Application $app)
{
// get the oauth server (configured in src/OAuth2Demo/Server/Server.php)
$server = $app['oauth_server'];
// get the oauth response (configured in src/OAuth2Demo/Server/Server.php)
$response = $app['oauth_response'];
if (!$server->verifyResourceRequest($app['request'], $response)) {
return $server->getResponse();
} else {
// return a fake API response - not that exciting
// @TODO return something more valuable, like the name of the logged in user
$api_response = array(
'friends' => array(
'john',
'matt',
'jane'
)
);
return new Response(json_encode($api_response));
}
}
}