X-Git-Url: https://git-public.kairo.at/?p=authserver.git;a=blobdiff_plain;f=token.php;h=e934b141bf85ec9b59a8af5c2dfcb71e66597145;hp=31bb0cca959877e3db4949fa6ec7b4c110eacc0a;hb=1e976489ad553d7591076833dd41469f4606b9d3;hpb=e6624d81c4ccfb9f8aad62f72b007880dc08eabb diff --git a/token.php b/token.php index 31bb0cc..e934b14 100644 --- a/token.php +++ b/token.php @@ -3,12 +3,20 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -// Simple server based on https://bshaffer.github.io/oauth2-server-php-docs/cookbook +// 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' +// Response is always JSON. -// include our OAuth2 Server object -require_once __DIR__.'/server.php'; +// Include the common auth system files (including the OAuth2 Server object). +require_once(__DIR__.'/authsystem.inc.php'); -// Handle a request for an OAuth2.0 Access Token and send the response to the client -$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); +$errors = $utils->checkForSecureConnection(); +if (!count($errors)) { + // Handle a request for an OAuth2.0 Access Token and send the response to the client + $server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); +} +else { + print(json_encode(array('error' => 'insecure_connection', + 'error_description' => 'Your connection is insecure. Token requests can only be made on secure connections.'))); +} ?>