/** * Generates a new authentication ticket for a customer account. * * @param string $responseFields Use this field to include those fields which are not included by default. * @param CustomerUserAuthInfo $userAuthInfo The authentication information required to generate an authentication ticket for a customer account. * @return MozuClient */ public static function createUserAuthTicketClient($userAuthInfo, $responseFields = null) { $url = CustomerAuthTicketUrl::createUserAuthTicketUrl($responseFields); $mozuClient = new MozuClient(); $mozuClient->withResourceUrl($url)->withBody($userAuthInfo); return $mozuClient; }
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); } }