/** * @covers OAuth\Common\Http\Uri\UriFactory::createFromAbsolute */ public function testCreateFromAbsolute() { $factory = new UriFactory(); $uri = $factory->createFromAbsolute('http://example.com'); $this->assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); $this->assertSame('http://example.com', $uri->getAbsoluteUri()); }
function getOrders() { $applicationUrl = 'http://magento2.site'; $consumerKey = '920b324e02330f55c1d53dd19e87c8db'; $consumerSecret = 'e66d927c017765b607ec0cb72663130b'; $storage = new Session(); $uriFactory = new UriFactory(); $serviceFactory = new ServiceFactory(); $serviceFactory->registerService('magento', 'JonnyW\\MagentoOAuth\\OAuth1\\Service\\Magento'); $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER); $currentUri->setQuery(''); $baseUri = $uriFactory->createFromAbsolute($applicationUrl); $credentials = new Credentials($consumerKey, $consumerSecret, $currentUri->getAbsoluteUri()); $magentoService = $serviceFactory->createService('magento', $credentials, $storage, array(), $baseUri); $magentoService->setAuthorizationEndpoint(Magento::AUTHORIZATION_ENDPOINT_ADMIN); if (isset($_GET['rejected'])) { echo '<p>OAuth authentication was cancelled.</p>'; } elseif (isset($_GET['authenticate'])) { // get a request token from magento $token = $magentoService->requestRequestToken(); $url = $magentoService->getAuthorizationUri(array('oauth_token' => $token->getRequestToken())); header('Location: ' . $url); } elseif (!empty($_GET['oauth_token'])) { // Get the stored request token $token = $storage->retrieveAccessToken('Magento'); // Exchange the request token for an access token // Caution: The request access token ovewrites the request token here. // Assume $storage has an access token from now on $magentoService->requestAccessToken($_GET['oauth_token'], $_GET['oauth_verifier'], $token->getRequestTokenSecret()); $url = $currentUri->getRelativeUri() . "?request=products"; header('Location: ' . $url); } elseif (!empty($_GET['request'])) { try { if ($_GET['request'] == "products") { $result = $magentoService->request('/api/rest/products', 'GET', null, array('Accept' => '*/*')); echo 'result: <pre>' . print_r(json_decode($result), true) . '</pre>'; } elseif ($_GET['request'] == "orders") { $result = $magentoService->request('/api/rest/orders', 'GET', null, array('Accept' => '*/*')); echo 'result: <pre>' . print_r(json_decode($result), true) . '</pre>'; } } catch (TokenNotFoundException $e) { $url = $currentUri->getRelativeUri() . '?authenticate=true'; header('Location: ' . $url); } } else { $url = $currentUri->getRelativeUri() . '?authenticate=true'; echo '<a href="' . $url . '" title="Authenticate">Authenticate!</a>'; } }