@@ -62,9 +62,18 @@ public function executeRequest($inputs, $parsedCookie) {
62
62
$ proxyResponse = $ this ->replicateRequest ($ this ->method , $ this ->uri , $ inputs );
63
63
64
64
//Get a new access token from refresh token if exists
65
- $ ret = $ this ->refreshToken ($ proxyResponse , $ inputs , $ parsedCookie );
66
- $ proxyResponse = $ ret ['response ' ];
67
- $ cookie = $ ret ['cookie ' ];
65
+ $ cookie = null ;
66
+ if ($ proxyResponse ->getStatusCode () != 200 ) {
67
+ if (array_key_exists (ProxyAux::REFRESH_TOKEN , $ parsedCookie )) {
68
+ $ ret = $ this ->tryRefreshToken ($ inputs , $ parsedCookie );
69
+ }
70
+ else {
71
+ $ cookie = $ this ->cookieManager ->destroyCookie ();
72
+ }
73
+ }
74
+
75
+ $ proxyResponse = (isset ($ ret )) ? $ ret ['response ' ] : $ proxyResponse ;
76
+ $ cookie = (isset ($ ret )) ? $ ret ['cookie ' ] : $ cookie ;
68
77
break ;
69
78
default :
70
79
$ proxyResponse = $ this ->replicateRequest ($ this ->method , $ this ->uri , $ inputs );
@@ -77,41 +86,37 @@ public function executeRequest($inputs, $parsedCookie) {
77
86
}
78
87
79
88
/**
80
- * @param $proxyResponse
81
89
* @param $inputs
82
90
* @param $parsedCookie
83
91
* @return array
84
92
*/
85
- private function refreshToken ($ proxyResponse , $ inputs , $ parsedCookie ) {
86
- $ cookie = null ;
87
- if ($ proxyResponse ->getStatusCode () != 200 && array_key_exists (ProxyAux::REFRESH_TOKEN , $ parsedCookie )) {
88
- $ this ->callMode = ProxyAux::MODE_REFRESH ;
93
+ private function tryRefreshToken ($ inputs , $ parsedCookie ) {
94
+ $ this ->callMode = ProxyAux::MODE_REFRESH ;
89
95
90
- //TODO: remove and save additional params
96
+ //TODO: remove and save additional params
91
97
92
- //Get a new access token from refresh token
93
- $ inputs = $ this ->removeTokenExtraParams ($ inputs );
94
- $ inputs = $ this ->addRefreshExtraParams ($ inputs , $ parsedCookie );
95
- $ proxyResponse = $ this ->replicateRequest ($ parsedCookie [ProxyAux::COOKIE_METHOD ], $ parsedCookie [ProxyAux::COOKIE_URI ], $ inputs );
98
+ //Get a new access token from refresh token
99
+ $ inputs = $ this ->removeTokenExtraParams ($ inputs );
100
+ $ inputs = $ this ->addRefreshExtraParams ($ inputs , $ parsedCookie );
101
+ $ proxyResponse = $ this ->replicateRequest ($ parsedCookie [ProxyAux::COOKIE_METHOD ], $ parsedCookie [ProxyAux::COOKIE_URI ], $ inputs );
96
102
97
- $ content = $ proxyResponse ->getContent ();
98
- if ($ proxyResponse ->getStatusCode () === 200 && array_key_exists (ProxyAux::ACCESS_TOKEN , $ content )) {
99
- $ this ->callMode = ProxyAux::MODE_TOKEN ;
100
- $ parsedCookie [ProxyAux::ACCESS_TOKEN ] = $ content [ProxyAux::ACCESS_TOKEN ];
101
- $ parsedCookie [ProxyAux::REFRESH_TOKEN ] = $ content [ProxyAux::REFRESH_TOKEN ];
103
+ $ content = $ proxyResponse ->getContent ();
104
+ if ($ proxyResponse ->getStatusCode () === 200 && array_key_exists (ProxyAux::ACCESS_TOKEN , $ content )) {
105
+ $ this ->callMode = ProxyAux::MODE_TOKEN ;
106
+ $ parsedCookie [ProxyAux::ACCESS_TOKEN ] = $ content [ProxyAux::ACCESS_TOKEN ];
107
+ $ parsedCookie [ProxyAux::REFRESH_TOKEN ] = $ content [ProxyAux::REFRESH_TOKEN ];
102
108
103
- //TODO: add additional saved params
109
+ //TODO: add additional saved params
104
110
105
- $ inputs = $ this ->removeRefreshTokenExtraParams ($ inputs );
106
- $ inputs = $ this ->addTokenExtraParams ($ inputs , $ parsedCookie );
107
- $ proxyResponse = $ this ->replicateRequest ($ this ->method , $ this ->uri , $ inputs );
111
+ $ inputs = $ this ->removeRefreshTokenExtraParams ($ inputs );
112
+ $ inputs = $ this ->addTokenExtraParams ($ inputs , $ parsedCookie );
113
+ $ proxyResponse = $ this ->replicateRequest ($ this ->method , $ this ->uri , $ inputs );
108
114
109
- //Set a new cookie with updated access token and refresh token
110
- $ cookie = $ this ->cookieManager ->createCookie ($ parsedCookie );
111
- }
112
- else {
113
- $ cookie = $ this ->cookieManager ->destroyCookie ();
114
- }
115
+ //Set a new cookie with updated access token and refresh token
116
+ $ cookie = $ this ->cookieManager ->createCookie ($ parsedCookie );
117
+ }
118
+ else {
119
+ $ cookie = $ this ->cookieManager ->destroyCookie ();
115
120
}
116
121
117
122
return array (
0 commit comments