Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function ssoLogin(NostoAccountMetaDataIframeInterface $meta)
 {
     $token = $this->getApiToken('sso');
     if ($token === null) {
         return false;
     }
     $request = new NostoHttpRequest();
     $request->setUrl(NostoHttpRequest::$baseUrl . NostoHttpRequest::PATH_SSO_AUTH);
     $request->setReplaceParams(array('{platform}' => $meta->getPlatform(), '{email}' => $meta->getEmail()));
     $request->setContentType('application/x-www-form-urlencoded');
     $request->setAuthBasic('', $token->getValue());
     $response = $request->post(http_build_query(array('fname' => $meta->getFirstName(), 'lname' => $meta->getLastName())));
     $result = $response->getJsonResult();
     if ($response->getCode() !== 200) {
         Nosto::throwHttpException('Unable to login employee to Nosto with SSO token.', $request, $response);
     }
     if (empty($result->login_url)) {
         throw new NostoException('No "login_url" returned when logging in employee to Nosto');
     }
     return $result->login_url;
 }