/** * Decodes access token object from array * * @param array $data * * @return Paysera_WalletApi_Entity_MacAccessToken * * @throws InvalidArgumentException */ public function decodeAccessToken($data) { if ($data['token_type'] !== 'mac' || $data['mac_algorithm'] !== 'hmac-sha-256') { throw new InvalidArgumentException('Only mac tokens with hmac-sha-256 algorithm are supported'); } return Paysera_WalletApi_Entity_MacAccessToken::create()->setExpiresAt(time() + $data['expires_in'])->setMacId($data['access_token'])->setMacKey($data['mac_key'])->setRefreshToken(isset($data['refresh_token']) ? $data['refresh_token'] : null); }
/** * @param Paysera_WalletApi_Event_ResponseExceptionEvent $event */ public function onResponseException(Paysera_WalletApi_Event_ResponseExceptionEvent $event) { if ($event->getException()->getErrorCode() === 'invalid_grant') { $options = $event->getOptions(); if (!isset($options['oauth_access_token_retry'])) { $options['oauth_access_token_retry'] = true; $event->setOptions($options); $refreshToken = $this->token->getRefreshToken(); if ($refreshToken !== null) { $newToken = $this->oauthClient->refreshAccessToken($refreshToken); $this->token = $newToken; $this->signer = new Paysera_WalletApi_Auth_Mac($newToken->getMacId(), $newToken->getMacKey()); $event->stopPropagation()->setRepeatRequest(true); $event->getDispatcher()->dispatch(Paysera_WalletApi_Events::AFTER_OAUTH_TOKEN_REFRESH, new Paysera_WalletApi_Event_MacAccessTokenEvent($newToken)); } } } }