示例#1
0
 /**
  * Returns the url for the account administration iframe.
  * If the passed account is null, then the url will point to the start page where a new account can be created.
  *
  * @param NostoAccountMetaDataIframeInterface $meta the iframe meta data.
  * @param NostoAccount|null $account the account to return the url for.
  * @param array $params additional parameters to add to the iframe url.
  * @return string the iframe url.
  * @throws NostoException if the url cannot be created.
  */
 public function getUrl(NostoAccountMetaDataIframeInterface $meta, NostoAccountInterface $account = null, array $params = array())
 {
     $defaultParameters = array('lang' => strtolower($meta->getLanguageIsoCode()), 'ps_version' => $meta->getVersionPlatform(), 'nt_version' => $meta->getVersionModule(), 'product_pu' => $meta->getPreviewUrlProduct(), 'category_pu' => $meta->getPreviewUrlCategory(), 'search_pu' => $meta->getPreviewUrlSearch(), 'cart_pu' => $meta->getPreviewUrlCart(), 'front_pu' => $meta->getPreviewUrlFront(), 'shop_lang' => strtolower($meta->getLanguageIsoCodeShop()), 'shop_name' => $meta->getShopName(), 'unique_id' => $meta->getUniqueId(), 'fname' => $meta->getFirstName(), 'lname' => $meta->getLastName(), 'email' => $meta->getEmail());
     if ($account instanceof NostoAccountInterface) {
         $missingScopes = $account->getMissingTokens();
         if (!empty($missingScopes)) {
             $defaultParameters['missing_scopes'] = implode(',', $missingScopes);
         }
     }
     $queryParams = http_build_query(array_merge($defaultParameters, $params));
     if ($account !== null && $account->isConnectedToNosto()) {
         try {
             $url = $account->ssoLogin($meta) . '?' . $queryParams;
         } catch (NostoException $e) {
             // If the SSO fails, we show a "remove account" page to the user in order to
             // allow to remove Nosto and start over.
             // The only case when this should happen is when the api token for some
             // reason is invalid, which is the case when switching between environments.
             $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_UNINSTALL . '?' . $queryParams, array('{platform}' => $meta->getPlatform()));
         }
     } else {
         $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_INSTALL . '?' . $queryParams, array('{platform}' => $meta->getPlatform()));
     }
     return $url;
 }
示例#2
0
 /**
  * Returns the url for the account administration iframe.
  * If the passed account is null, then the url will point to the start page where a new account can be created.
  *
  * @param NostoAccountMetaSingleSignOnInterface $sso the SSO meta data.
  * @param NostoAccountMetaIframeInterface $iframe the iframe meta data.
  * @param NostoAccount|null $account the account to return the url for.
  * @param array $params additional parameters to add to the iframe url.
  * @return string the iframe url.
  * @throws NostoException if the url cannot be created.
  */
 public function getUrl(NostoAccountMetaSingleSignOnInterface $sso, NostoAccountMetaIframeInterface $iframe, NostoAccount $account = null, array $params = array())
 {
     $queryParams = http_build_query(array_merge(array('lang' => $iframe->getLanguage()->getCode(), 'ps_version' => $iframe->getVersionPlatform(), 'nt_version' => $iframe->getVersionModule(), 'product_pu' => $iframe->getPreviewUrlProduct(), 'category_pu' => $iframe->getPreviewUrlCategory(), 'search_pu' => $iframe->getPreviewUrlSearch(), 'cart_pu' => $iframe->getPreviewUrlCart(), 'front_pu' => $iframe->getPreviewUrlFront(), 'shop_lang' => $iframe->getShopLanguage()->getCode(), 'shop_name' => $iframe->getShopName(), 'unique_id' => $iframe->getUniqueId(), 'fname' => $sso->getFirstName(), 'lname' => $sso->getLastName(), 'email' => $sso->getEmail(), 'missing_scopes' => !is_null($account) && !$account->isConnectedToNosto() ? implode(',', $account->getMissingScopes()) : ''), $params));
     if ($account !== null) {
         try {
             $service = new NostoServiceAccount();
             $url = $service->sso($account, $sso);
             $url .= '?' . $queryParams;
         } catch (NostoException $e) {
             // If the SSO fails, we show a "remove account" page to the user in order to
             // allow to remove Nosto and start over.
             // The only case when this should happen is when the api token for some
             // reason is invalid, which is the case when switching between environments.
             $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_UNINSTALL . '?' . $queryParams, array('{platform}' => $sso->getPlatform()));
         }
     } else {
         $url = NostoHttpRequest::buildUri($this->getBaseUrl() . self::IFRAME_URI_INSTALL . '?' . $queryParams, array('{platform}' => $sso->getPlatform()));
     }
     return $url;
 }
示例#3
0
 /**
  * Returns the authorize url to the oauth2 server.
  *
  * @return string the url.
  */
 public function getAuthorizationUrl()
 {
     return NostoHttpRequest::buildUri(self::$baseUrl . self::PATH_AUTH, array('{cid}' => $this->clientId, '{uri}' => urlencode($this->redirectUrl), '{sco}' => implode(' ', $this->scopes), '{iso}' => strtolower($this->languageIsoCode)));
 }
示例#4
0
 /**
  * Returns the authorize url to the oauth2 server.
  *
  * @return string the url.
  */
 public function getAuthorizationUrl()
 {
     $url = NostoHttpRequest::buildUri(self::$baseUrl . self::PATH_AUTH, array('{cid}' => $this->clientId, '{uri}' => urlencode($this->redirectUrl), '{sco}' => implode(' ', $this->scopes), '{iso}' => $this->language->getCode()));
     if ($this->account) {
         $url = NostoHttpRequest::replaceQueryParamInUrl('merchant', $this->account->getName(), $url);
     }
     return $url;
 }
示例#5
0
 /**
  * Tests the "buildUri" helper method.
  */
 public function testHttpRequestBuildUri()
 {
     $uri = NostoHttpRequest::buildUri(sprintf('http://localhost:%d?param1={p1}&param2={p2}', self::CURL_TEST_PORT), array('{p1}' => 'first', '{p2}' => 'second'));
     $this->assertEquals(sprintf('http://localhost:%d?param1=first&param2=second', self::CURL_TEST_PORT), $uri);
 }