Example #1
0
 private function getCurrentUri()
 {
     $uriFactory = new UriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('');
     return $currentUri;
 }
Example #2
0
 /**
  * Get the Google service instance
  *
  * @access public
  * @return \OAuth\OAuth2\Service\Google
  */
 public function getService()
 {
     $uriFactory = new UriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('controller=user&action=google');
     $storage = new Session(false);
     $credentials = new Credentials(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, $currentUri->getAbsoluteUri());
     $serviceFactory = new ServiceFactory();
     return $serviceFactory->createService('google', $credentials, $storage, array('userinfo_email', 'userinfo_profile'));
 }
Example #3
0
 /**
  * Get the GitHub service instance
  *
  * @access public
  * @return \OAuth\OAuth2\Service\GitHub
  */
 public function getService()
 {
     $uriFactory = new UriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('controller=user&action=gitHub');
     $storage = new Session(false);
     $credentials = new Credentials(GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, $currentUri->getAbsoluteUri());
     $serviceFactory = new ServiceFactory();
     return $serviceFactory->createService('gitHub', $credentials, $storage, array(''));
 }
Example #4
0
 /**
  * EtsyService constructor.
  */
 public function __construct()
 {
     $this->etsyKey = config('app.etsy_api_key');
     $this->etsySecret = config('app.etsy_api_secret');
     $this->etsyCallbackUrl = config('app.etsy_callback_url');
     $this->storage = new Session();
     $uriFactory = new UriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('');
     $this->credentials = new Credentials($this->etsyKey, $this->etsySecret, url($this->etsyCallbackUrl));
     // Instantiate the Etsy service using the credentials, http client and storage mechanism for the token
     $serviceFactory = new \OAuth\ServiceFactory();
     $this->service = $serviceFactory->createService('Etsy', $this->credentials, $this->storage);
 }
 /**
  * Create an oauth service based on type
  *
  * @param  string $type the type of oauth services to create
  */
 public function createService($type, $scopes = ['user'])
 {
     $typeLower = strtolower($type);
     if (!array_key_exists($typeLower, $this->oAuthCredentials)) {
         return false;
     }
     // Create a new instance of the URI class with the current URI, stripping the query string
     $uriFactory = new UriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('');
     // Setup the credentials for the requests
     $credentials = new Credentials($this->oAuthCredentials[$typeLower]['key'], $this->oAuthCredentials[$typeLower]['secret'], $currentUri->getAbsoluteUri() . '/callback');
     // Instantiate the OAuth service using the credentials, http client and storage mechanism for the token
     $this->registeredService = $this->serviceFactory->createService($type, $credentials, $this->storage, $scopes);
 }
Example #6
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;
     }
 }
Example #7
0
 /**
  * Main factory
  *
  * @param string type
  * @param SessionInterface
  * @param array Scope
  * @return Social
  */
 public static function factory($provider = 'facebook', SessionInterface $store, $scopes = array())
 {
     // Create a new instance of the URI class with the current URI,
     // stripping the query string
     $uriFactory = new SocialUriFactory();
     $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
     $currentUri->setQuery('');
     $servicesCredentials = Config::get('auth.social');
     $serviceFactory = new SocialServiceFactory();
     // Session storage
     $storage = new SocialSession($store, false, Config::get('session.cookie'));
     // Setup the credentials for the requests
     $credentials = new SocialCredentials($servicesCredentials[$provider]['key'], $servicesCredentials[$provider]['secret'], $currentUri->getAbsoluteUri());
     $selectedService = $serviceFactory->createService($provider, $credentials, $storage, $scopes);
     return new static($selectedService, $currentUri, $storage, $credentials);
 }
 /**
  * @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());
 }
Example #9
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>';
    }
}
Example #10
0
$csrfToken = new CsrfToken($sessionStorage, new Factory());
/**
 * Setup the GitHub service
 */
$serviceFactory = new ServiceFactory();
$storage = new OauthSession();
/**
 * Return when on CLI
 */
if (php_sapi_name() === 'cli') {
    return;
}
/**
 * Request access token
 */
$uriFactory = new UriFactory();
$currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
$currentUri->setQuery('');
$credentials = new Credentials($githubCredentials['key'], $githubCredentials['secret'], $currentUri->getAbsoluteUri());
$github = $serviceFactory->createService('GitHub', $credentials, $storage, array());
/**
 * Setup the authentication object
 */
$user = new User($sessionStorage, new Auth($dbConnection));
/**
 * Setup the HTML template renderer
 */
$htmlTemplate = new Html(__DIR__ . '/templates', 'page.phtml');
/**
 * Setup the XML template renderer
 */
 protected function getUri()
 {
     $uriFactory = new UriFactory();
     return $uriFactory->createFromSuperGlobalArray($_SERVER);
 }