Skip to content

Commit db280e9

Browse files
committed
Improved code when call refresh token
1 parent 7176e13 commit db280e9

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

src/Andreoli/ApiProxy/ApiProxyServiceProvider.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,20 @@ public function provides() {
7373
*/
7474
private function registerErrorHandlers() {
7575
$this->app->error(function(ProxyException $ex) {
76-
//if (\Request::ajax() && \Request::wantsJson()) {
76+
if (\Request::ajax() && \Request::wantsJson()) {
7777
return new JsonResponse([
7878
'error' => $ex->errorType,
7979
'error_description' => $ex->getMessage()
8080
], $ex->httpStatusCode, $ex->getHttpHeaders()
8181
);
82-
//}
82+
}
8383

84-
/*
8584
return \View::make('api-proxy-laravel::proxy_error', array(
8685
'header' => $ex->getHttpHeaders()[0],
8786
'code' => $ex->httpStatusCode,
8887
'error' => $ex->errorType,
8988
'message' => $ex->getMessage()
9089
));
91-
*/
9290
});
9391
}
9492

src/Andreoli/ApiProxy/Managers/RequestManager.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,17 @@ public function executeRequest($inputs, $parsedCookie) {
9393
private function tryRefreshToken($inputs, $parsedCookie) {
9494
$this->callMode = ProxyAux::MODE_REFRESH;
9595

96-
//TODO: remove and save additional params
97-
9896
//Get a new access token from refresh token
9997
$inputs = $this->removeTokenExtraParams($inputs);
100-
$inputs = $this->addRefreshExtraParams($inputs, $parsedCookie);
101-
$proxyResponse = $this->replicateRequest($parsedCookie[ProxyAux::COOKIE_METHOD], $parsedCookie[ProxyAux::COOKIE_URI], $inputs);
98+
$params = $this->addRefreshExtraParams(array(), $parsedCookie);
99+
$proxyResponse = $this->replicateRequest($parsedCookie[ProxyAux::COOKIE_METHOD], $parsedCookie[ProxyAux::COOKIE_URI], $params);
102100

103101
$content = $proxyResponse->getContent();
104102
if ($proxyResponse->getStatusCode() === 200 && array_key_exists(ProxyAux::ACCESS_TOKEN, $content)) {
105103
$this->callMode = ProxyAux::MODE_TOKEN;
106104
$parsedCookie[ProxyAux::ACCESS_TOKEN] = $content[ProxyAux::ACCESS_TOKEN];
107105
$parsedCookie[ProxyAux::REFRESH_TOKEN] = $content[ProxyAux::REFRESH_TOKEN];
108106

109-
//TODO: add additional saved params
110-
111-
$inputs = $this->removeRefreshTokenExtraParams($inputs);
112107
$inputs = $this->addTokenExtraParams($inputs, $parsedCookie);
113108
$proxyResponse = $this->replicateRequest($this->method, $this->uri, $inputs);
114109

@@ -133,7 +128,7 @@ private function tryRefreshToken($inputs, $parsedCookie) {
133128
*/
134129
private function replicateRequest($method, $uri, $inputs) {
135130
$guzzleResponse = $this->sendGuzzleRequest($method, $uri, $inputs);
136-
$proxyResponse = new ProxyResponse(null, $guzzleResponse->getStatusCode(), $guzzleResponse->getReasonPhrase(), $guzzleResponse->getProtocolVersion(), $this->getResponseContent($guzzleResponse));
131+
$proxyResponse = new ProxyResponse($guzzleResponse->getStatusCode(), $guzzleResponse->getReasonPhrase(), $guzzleResponse->getProtocolVersion(), $this->getResponseContent($guzzleResponse));
137132

138133
return $proxyResponse;
139134
}
@@ -276,17 +271,4 @@ private function removeTokenExtraParams($inputs) {
276271
return $inputs;
277272
}
278273

279-
/**
280-
* @param $inputs
281-
* @return array
282-
*/
283-
private function removeRefreshTokenExtraParams($inputs) {
284-
$inputs = ProxyAux::removeQueryValue($inputs, ProxyAux::GRANT_TYPE);
285-
$inputs = ProxyAux::removeQueryValue($inputs, ProxyAux::REFRESH_TOKEN);
286-
$inputs = ProxyAux::removeQueryValue($inputs, ProxyAux::CLIENT_ID);
287-
$inputs = ProxyAux::removeQueryValue($inputs, ProxyAux::CLIENT_SECRET);
288-
289-
return $inputs;
290-
}
291-
292274
}

src/Andreoli/ApiProxy/Models/ProxyResponse.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,18 @@
1212

1313
class ProxyResponse {
1414

15-
private $clientId = null;
1615
private $statusCode = null;
1716
private $reasonPhrase = null;
1817
private $protocolVersion = null;
1918
private $content = null;
2019

21-
public function __construct($clientId, $statusCode, $reasonPhrase, $protoVersion, $content) {
22-
$this->clientId = $clientId;
20+
public function __construct($statusCode, $reasonPhrase, $protoVersion, $content) {
2321
$this->statusCode = $statusCode;
2422
$this->reasonPhrase = $reasonPhrase;
2523
$this->protocolVersion = $protoVersion;
2624
$this->content = $content;
2725
}
2826

29-
public function setClientId($client) {
30-
$this->clientId = $client;
31-
}
32-
3327
public function setStatusCode($status) {
3428
$this->statusCode = $status;
3529
}
@@ -46,10 +40,6 @@ public function setContent($content) {
4640
$this->content = $content;
4741
}
4842

49-
public function getClientId() {
50-
return $this->clientId;
51-
}
52-
5343
public function getStatusCode() {
5444
return $this->statusCode;
5545
}

0 commit comments

Comments
 (0)