summaryrefslogtreecommitdiff
path: root/vendor/lusitanian/oauth/examples/pocket.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-06 06:41:47 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-06 06:41:47 -0500
commitc80c15dcc33a70acc2b177691d33f088f8c2541e (patch)
treebc3e44e35b97b751c145cc5797a0faf356922244 /vendor/lusitanian/oauth/examples/pocket.php
parentc91ff61cdfa8b5eb76783927e5b8710f2a9f2601 (diff)
Include all vendor files in the repo to be easier for people
Diffstat (limited to 'vendor/lusitanian/oauth/examples/pocket.php')
-rw-r--r--vendor/lusitanian/oauth/examples/pocket.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/vendor/lusitanian/oauth/examples/pocket.php b/vendor/lusitanian/oauth/examples/pocket.php
new file mode 100644
index 00000000..b96d2ace
--- /dev/null
+++ b/vendor/lusitanian/oauth/examples/pocket.php
@@ -0,0 +1,63 @@
+<?php
+
+/**
+ * Example of retrieving an authentication token of the Pocket service.
+ *
+ * @author Christian Mayer <thefox21at@gmail.com>
+ * @copyright Copyright (c) 2014 Christian Mayer <thefox21at@gmail.com>
+ * @license http://www.opensource.org/licenses/mit-license.html MIT License
+ */
+
+use OAuth\OAuth2\Service\Pocket;
+use OAuth\Common\Storage\Session;
+use OAuth\Common\Consumer\Credentials;
+use OAuth\Common\Http\Client\CurlClient;
+
+/**
+ * Bootstrap the example
+ */
+require_once __DIR__.'/bootstrap.php';
+
+$step = isset($_GET['step']) ? (int)$_GET['step'] : null;
+$code = isset($_GET['code']) ? $_GET['code'] : null;
+
+// Session storage
+$storage = new Session();
+
+// Setup the credentials for the requests
+$credentials = new Credentials(
+ $servicesCredentials['pocket']['key'],
+ null, // Pocket API doesn't have a secret key. :S
+ $currentUri->getAbsoluteUri().($code ? '?step=3&code='.$code : '')
+);
+
+// Instantiate the Pocket service using the credentials, http client and storage mechanism for the token
+$pocketService = $serviceFactory->createService('Pocket', $credentials, $storage);
+
+switch($step){
+ default:
+ print '<a href="'.$currentUri->getRelativeUri().'?step=1">Login with Pocket</a>';
+
+ break;
+
+ case 1:
+ $code = $pocketService->requestRequestToken();
+ header('Location: '.$currentUri->getRelativeUri().'?step=2&code='.$code);
+
+ break;
+
+ case 2:
+ $url = $pocketService->getAuthorizationUri(array('request_token' => $code));
+ header('Location: '.$url);
+
+ break;
+
+ case 3:
+ $token = $pocketService->requestAccessToken($code);
+ $accessToken = $token->getAccessToken();
+ $extraParams = $token->getExtraParams();
+
+ print 'User: '.$extraParams['username'].'<br />';
+ print 'Access Token: '.$accessToken;
+ break;
+}