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/. */
6 // Simple server based on https://bshaffer.github.io/oauth2-server-php-docs/cookbook
8 // Include the common auth system files (including the OAuth2 Server object).
9 require_once(__DIR__.'/authsystem.inc.php');
11 $request = OAuth2\Request::createFromGlobals();
12 $response = new OAuth2\Response();
14 // validate the authorize request
15 if (!$server->validateAuthorizeRequest($request, $response)) {
19 // display an authorization form
23 <label>Do You Authorize TestClient?</label><br />
24 <input type="submit" name="authorized" value="yes">
25 <input type="submit" name="authorized" value="no">
29 // print the authorization code if the user has authorized your client
30 $is_authorized = ($_POST['authorized'] === 'yes');
31 $server->handleAuthorizeRequest($request, $response, $is_authorized);
33 // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client
34 $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40);
35 exit("SUCCESS! Authorization Code: $code");