Ejemplo n.º 1
0
 /**
  * @covers Mozu\Api\Security\Authentication::getAuthTicket
  * @todo Implement testGetAuthTicket().
  */
 public function testGetAuthTicket()
 {
     $this->log->info('Testing getAuthTicket');
     $authentication = AppAuthenticator::getInstance();
     $this->assertNotNull($authentication->getAuthTicket());
     $this->assertNotNull($authentication->getAuthTicket()->accessToken);
     $this->assertNotNull($authentication->getAuthTicket()->refreshToken);
     $this->assertNotNull($authentication->getAuthTicket()->accessTokenExpiration);
     $this->assertNotNull($authentication->getAuthTicket()->refreshTokenExpiration);
 }
Ejemplo n.º 2
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.º 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
 public function auth()
 {
     try {
         $this->log->info("Authenticating...");
         $appAuthInfo = new AppAuthInfo();
         $appAuthInfo->sharedSecret = $this->sharedSecret;
         $appAuthInfo->applicationId = $this->applicationId;
         MozuConfig::$baseAppAuthUrl = $this->baseUrl;
         $this->log->info($this->baseUrl);
         $this->log->info("Base Auth Url : " . MozuConfig::$baseAppAuthUrl);
         $this->log->info('Authenticating...');
         AppAuthenticator::initialize($appAuthInfo);
         $this->log->info('Authentication done...');
         $appAuthenticator = AppAuthenticator::getInstance();
         $this->log->info("Access Token : " . $appAuthenticator->getAccessToken());
     } catch (\Exception $e) {
         $this->log->error("Exception : code - " . $e->getCode() . ", message - " . $e->getMessage() . ", correlationid - " . $e->getCorrelationId());
         throw $e;
     }
 }
Ejemplo n.º 5
0
 private function addRequestHeaders(RequestInterface $request)
 {
     $this->logger->info("Setting request headers");
     $authentication = AppAuthenticator::getInstance();
     if (!isset($authentication)) {
         throw new \Exception("Authentication is not initialized");
     }
     $this->logger->info("App Claim : " . $authentication->getAppClaim());
     $request = $request->withHeader(Headers::X_VOL_APP_CLAIMS, $authentication->getAppClaim());
     $request = $request->withHeader(Headers::X_VOL_VERSION, Version::$apiVersion);
     if (isset($this->contentType)) {
         $request = $request->withHeader(Headers::CONTENT_TYPE, $this->contentType);
     }
     if (!$this->isStreamContent) {
         $request = $request->withHeader('Content-Type', 'application/json; charset=utf-8');
     }
     if ($this->apiContext != null && $this->apiContext->getUserAuthTicket() != null) {
         $this->setUserAuth();
         $request = $request->withHeader(Headers::X_VOL_USER_CLAIMS, $this->apiContext->getUserAuthTicket());
     }
     $request = $request->withHeader("Accept-Encoding", "gzip, deflate");
     foreach ($this->headers as $name => $value) {
         $request = $request->withHeader($name, $value);
     }
     if ($this->requestBody != null) {
         $request = $request->withHeader("Content-Length", strlen($this->requestBody));
     }
     return $request;
 }