/**
  * @param TokenInterface $token
  * @param UserProviderInterface $storeProvider
  * @param $providerKey
  * @return PreAuthenticatedToken
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $storeProvider, $providerKey)
 {
     $credentials = $token->getCredentials();
     //verify the shopify signature
     if (!$this->signatureVerifier->isValid($credentials['hmac'], $credentials)) {
         throw new BadCredentialsException('Invalid signature');
     }
     $store = $storeProvider->loadUserByUsername($credentials['shop']);
     //configure the API client to authenticate all outgoing requests with the shopify store's credentials
     $this->shopifyClient->setShopifyStore($store);
     return new PreAuthenticatedToken($store, $credentials, $providerKey, $store->getRoles());
 }
 /**
  * @param GetResponseEvent $event
  * @throws FailedRequestException
  */
 protected function interceptOAuthStep2(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $authCode = $request->get('code');
     $storeName = $request->get('shop');
     $params = array('body' => array('client_id' => $this->config['credentials']['api_key'], 'client_secret' => $this->config['credentials']['shared_secret'], 'code' => $authCode));
     $apiRequest = $this->shopifyClient->http()->createRequest('POST', 'https://' . $storeName . '/admin/oauth/access_token', $params);
     $response = $this->shopifyClient->http()->send($apiRequest);
     if ($response->getStatusCode() != 200) {
         throw new FailedRequestException((string) $response);
     }
     $request->attributes->set('access_token', $response->json(array('object' => true))->access_token);
 }
 /**
  * @param ModifyableRequest $request
  * @param string $rootElement
  * @return array
  * @throws FailedRequestException
  */
 protected function sendPaged(ModifyableRequest $request, $rootElement)
 {
     return $this->api->processPaged($request, $rootElement);
 }