-
Notifications
You must be signed in to change notification settings - Fork 279
/
Copy pathToken.php
31 lines (25 loc) · 959 Bytes
/
Token.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
<?php
namespace OAuth2Demo\Server\Controllers;
use Silex\Application;
class Token
{
// Connects the routes in Silex
public static function addRoutes($routing)
{
$routing->post('/token', array(new self(), 'token'))->bind('grant');
}
/**
* This is called by the client app once the client has obtained
* an authorization code from the Authorize Controller (@see OAuth2Demo\Server\Controllers\Authorize).
* If the request is valid, an access token will be returned
*/
public function token(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'];
// let the oauth2-server-php library do all the work!
return $server->handleTokenRequest($app['request'], $response);
}
}