Exemplo n.º 1
0
 /**
  * @param $id
  * @return \OAuth\OAuth2\Service\AbstractService
  */
 protected function getService($id)
 {
     $credential = $this->getCredentials($id);
     // Setup the credentials for the requests
     $credentials = new Credentials($credential['id'], $credential['secret'], $this->getRootUri() . $this->getCallbackPath($id));
     $serviceFactory = new ServiceFactory();
     $serviceFactory->registerService('IsseHom', '\\Paliari\\Oauth2ClientFacade\\IsseHom');
     $serviceFactory->registerService('IssePro', '\\Paliari\\Oauth2ClientFacade\\IssePro');
     $service = $serviceFactory->createService($id, $credentials, $this->getStorage(), $credential['scopes']);
     return $service;
 }
Exemplo n.º 2
0
 /**
  * Set extra providers based on the configuration settings
  */
 protected function setExtraProviders()
 {
     $providers = Config::get('oauth::extra_providers');
     if (!$providers) {
         return;
     }
     foreach ($providers as $name => $class) {
         $this->serviceFactory->registerService($name, $class);
     }
 }
Exemplo n.º 3
0
 function it_registers_the_provider_if_a_class_is_set_in_the_configuration(Repository $config, ServiceFactory $serviceFactory)
 {
     $serviceFactory->registerService('Bar', 'Namespace\\Of\\Bar')->shouldBeCalledTimes(1);
     $serviceFactory->createService('Bar', Argument::cetera())->shouldBeCalled()->willReturn(new Foo());
     $config->has('oauth.providers.Bar')->willReturn(true);
     $config->has('oauth.providers.Bar.decorators')->willReturn(false);
     $config->has('oauth.providers.Bar.class')->willReturn(true);
     $config->get('oauth.providers.Bar.class')->willReturn('Namespace\\Of\\Bar');
     $config->get('oauth.providers.Bar.consumer_key')->willReturn('foo');
     $config->get('oauth.providers.Bar.consumer_secret')->willReturn('bar');
     $config->get('oauth.providers.Bar.callback_url')->willReturn('http://baz.com/login');
     $this->make('Bar');
 }
Exemplo n.º 4
0
 protected function init($callbackUrl = null)
 {
     if (!$this->init) {
         if (!$this->storage) {
             $this->storage = new Session();
         }
         $uriFactory = new UriFactory();
         $this->currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
         $credentials = new Credentials($this->apiKey, $this->apiSecret, $callbackUrl ? $callbackUrl : $this->currentUri->getAbsoluteUri());
         $serviceFactory = new ServiceFactory();
         $serviceFactory->setHttpClient(new CurlClient());
         $serviceFactory->registerService('DoYouBuzz', 'DoYouBuzz\\ApiHelper\\DoYouBuzzService');
         $this->service = $serviceFactory->createService('DoYouBuzz', $credentials, $this->storage);
         $this->init = true;
     }
 }
Exemplo n.º 5
0
 /**
  * @covers OAuth\ServiceFactory::createService
  * @covers OAuth\ServiceFactory::getFullyQualifiedServiceName
  * @covers OAuth\ServiceFactory::buildV2Service
  * @covers OAuth\ServiceFactory::resolveScopes
  */
 public function testCreateServiceOAuth2RegisteredWithCustomScope()
 {
     $factory = new ServiceFactory();
     $factory->registerService('foo', '\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake');
     $service = $factory->createService('foo', $this->getMock('\\OAuth\\Common\\Consumer\\CredentialsInterface'), $this->getMock('\\OAuth\\Common\\Storage\\TokenStorageInterface'), ['some']);
     $this->assertInstanceOf('\\OAuth\\OAuth2\\Service\\ServiceInterface', $service);
     $this->assertInstanceOf('\\OAuthTest\\Mocks\\OAuth2\\Service\\Fake', $service);
 }
Exemplo n.º 6
0
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>';
    }
}