From e6624d81c4ccfb9f8aad62f72b007880dc08eabb Mon Sep 17 00:00:00 2001 From: Robert Kaiser Date: Fri, 30 Sep 2016 16:46:09 +0200 Subject: [PATCH] add example files to auth server --- authorize.php | 39 +++++++++++++++++++++++++++++++++++++++ resource.php | 18 ++++++++++++++++++ server.php | 31 +++++++++++++++++++++++++++++++ token.php | 14 ++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 authorize.php create mode 100644 resource.php create mode 100644 server.php create mode 100644 token.php diff --git a/authorize.php b/authorize.php new file mode 100644 index 0000000..23c9308 --- /dev/null +++ b/authorize.php @@ -0,0 +1,39 @@ +validateAuthorizeRequest($request, $response)) { + $response->send(); + die; +} +// display an authorization form +if (empty($_POST)) { + exit(' +
+
+ + +
'); +} + +// print the authorization code if the user has authorized your client +$is_authorized = ($_POST['authorized'] === 'yes'); +$server->handleAuthorizeRequest($request, $response, $is_authorized); +if ($is_authorized) { + // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); + exit("SUCCESS! Authorization Code: $code"); +} +$response->send(); + +?> diff --git a/resource.php b/resource.php new file mode 100644 index 0000000..fdd5a91 --- /dev/null +++ b/resource.php @@ -0,0 +1,18 @@ +verifyResourceRequest(OAuth2\Request::createFromGlobals())) { + $server->getResponse()->send(); + die; +} +echo json_encode(array('success' => true, 'message' => 'You accessed my APIs!')); + +?> diff --git a/server.php b/server.php new file mode 100644 index 0000000..20f22b0 --- /dev/null +++ b/server.php @@ -0,0 +1,31 @@ + $dsn, 'username' => $username, 'password' => $password)); + +// Pass a storage object or array of storage objects to the OAuth2 server class +$server = new OAuth2\Server($storage); + +// Add the "Client Credentials" grant type (it is the simplest of the grant types) +$server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage)); + +// Add the "Authorization Code" grant type (this is where the oauth magic happens) +$server->addGrantType(new OAuth2\GrantType\AuthorizationCode($storage)); + +?> diff --git a/token.php b/token.php new file mode 100644 index 0000000..31bb0cc --- /dev/null +++ b/token.php @@ -0,0 +1,14 @@ +handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); + +?> -- 2.35.3