Ejemplo n.º 1
0
 public static function logout(UserAuthTicket $authTicket)
 {
     try {
         $authentication = AppAuthenticator::getInstance();
         //var_dump($authTicket);
         $resourceUrl = static::getLogoutUrl($authTicket);
         $client = new Client(['base_uri' => MozuConfig::$baseAppAuthUrl, 'verify' => false]);
         $headers = ["content-type" => "application/json", Headers::X_VOL_APP_CLAIMS => $authentication->getAppClaim()];
         var_dump($headers);
         $promise = $client->requestAsync("DELETE", $resourceUrl, ['headers' => $headers, 'exceptions' => true]);
         $promise->wait();
     } catch (\Exception $e) {
         HttpHelper::checkError($e);
     }
 }
Ejemplo n.º 2
0
 private function refreshAuthTicket()
 {
     try {
         $requestData = new AuthTicketRequest();
         $requestData->refreshToken = $this->authTicket->refreshToken;
         $client = new Client(['base_uri' => MozuConfig::$baseAppAuthUrl, 'verify' => false]);
         $headers = ["content-type" => "application/json"];
         $body = json_encode($requestData);
         $promise = $client->requestAsync("PUT", AuthTicketUrl::RefreshAppAuthTicketUrl(null)->getUrl(), ['headers' => $headers, 'body' => $body, 'exceptions' => true]);
         $response = $promise->wait();
         $jsonResp = $response->getBody(true);
         $this->authTicket = json_decode($jsonResp);
         $this->setRefreshInterval(true);
     } catch (\Exception $e) {
         HttpHelper::checkError($e);
     }
 }
Ejemplo n.º 3
0
 public static function authenticate(CustomerUserAuthInfo $customerAuthInfo, $tenantId, $siteId)
 {
     try {
         $authentication = AppAuthenticator::getInstance();
         $resourceUrl = CustomerAuthTicketUrl::createUserAuthTicketUrl(null);
         $client = new Client(['base_uri' => static::getAuthUrl($tenantId), 'verify' => false]);
         $headers = ["content-type" => "application/json", Headers::X_VOL_APP_CLAIMS => $authentication->getAppClaim(), Headers::X_VOL_SITE => $siteId];
         $body = json_encode($customerAuthInfo);
         $promise = $client->requestAsync($resourceUrl->getVerb(), $resourceUrl->getUrl(), ['headers' => $headers, 'body' => $body, 'exceptions' => true]);
         $response = $promise->wait();
         $jsonResp = $response->getBody(true);
         $authResponse = json_decode($jsonResp);
         $authProfile = static::setUserAuth($authResponse, $tenantId, $siteId);
         return $authProfile;
     } catch (\Exception $e) {
         HttpHelper::checkError($e);
     }
 }
Ejemplo n.º 4
0
 private function validateContext()
 {
     if ($this->mozuUrl->getLocation() == UrlLocation::TENANT_POD) {
         if ($this->apiContext->getTenantId() < 0) {
             throw new \Exception("TenantId is missing");
         }
         if (trim($this->apiContext->getTenantUrl()) == "") {
             $tenantResource = new TenantResource(new ApiContext());
             $tenant = $tenantResource->getTenant($this->apiContext->getTenantId());
             if ($tenant == null) {
                 throw new \Exception("Tenant " . $this->apiContext->getTenantId() . " Not found");
             }
             $this->baseAddress = HttpHelper::getUrl($tenant->domain);
         } else {
             $this->baseAddress = HttpHelper::getUrl($this->apiContext->getTenantUrl());
         }
     } else {
         if ($this->mozuUrl->getLocation() == UrlLocation::PCI_POD) {
             if ($this->apiContext->getTenantId() < 0) {
                 throw new \Exception("TenantId is missing");
             }
             if (!isset(MozuConfig::$basePciUrl)) {
                 throw new \Exception("MozuConfig basePciUrl is empty. A valid value is required");
             }
             $this->baseAddress = MozuConfig::$basePciUrl;
         } else {
             $authentication = AppAuthenticator::getInstance();
             if ($authentication == null) {
                 throw new \Exception("App is not initialized. Use AppAuthenticator to initialize the app.");
             }
             if (!isset(MozuConfig::$baseAppAuthUrl)) {
                 throw new \Exception("MozuConfig baseAppAuthUrl is empty. A valid value is required");
             }
             $this->baseAddress = MozuConfig::$baseAppAuthUrl;
         }
     }
 }