Ejemplo n.º 1
0
 /**
  * Get new AccessToken using provided RefreshToken
  * 
  * @param RefreshToken $refreshToken
  * @return AccessToken
  */
 protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken)
 {
     // Send post request to authentication service
     $params = array('client_id' => $this->getConfig()->getClientId(), 'refresh_token' => $refreshToken->getRefreshToken(), 'grant_type' => 'refresh_token');
     $response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
     $output = $response['output'];
     $httpcode = $response['code'];
     switch ($httpcode) {
         case "200":
             $responseObject = json_decode($output);
             if (isset($responseObject->error)) {
                 // an error occured, the RefreshToken is most likely invalid
                 // delete RefreshToken to retrieve new one on next request
                 $this->getConfig()->getStorage()->deleteRefreshToken();
                 return null;
             }
             // create access token and save it
             $accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
             $this->getConfig()->getStorage()->saveAccessToken($accessToken);
             return $accessToken;
     }
     return null;
 }
 public function saveRefreshToken(RefreshToken $refreshToken)
 {
     $this->deleteRefreshToken();
     $refreshToken->setUserId($this->getUserId());
     $this->getObjectManager()->persist($refreshToken);
     $this->getObjectManager()->flush();
 }