e934b141bf85ec9b59a8af5c2dfcb71e66597145
[authserver.git] / token.php
1 <?php
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 // Called with e.g. curl .../token -d 'grant_type=authorization_code&client_id=testclient&client_secret=testpass&code=&state=f00bar&redirect_uri=http%3A%2F%2Ffake.example.com%2F'
7 // Response is always JSON.
8
9 // Include the common auth system files (including the OAuth2 Server object).
10 require_once(__DIR__.'/authsystem.inc.php');
11
12 $errors = $utils->checkForSecureConnection();
13
14 if (!count($errors)) {
15   // Handle a request for an OAuth2.0 Access Token and send the response to the client
16   $server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send();
17 }
18 else {
19   print(json_encode(array('error' => 'insecure_connection',
20                           'error_description' => 'Your connection is insecure. Token requests can only be made on secure connections.')));
21 }
22 ?>