@@ -53,9 +53,17 @@ public function getRequestToken():AccessToken{
53
53
54
54
$ params ['oauth_signature ' ] = $ this ->getSignature ($ this ->requestTokenURL , $ params , 'POST ' );
55
55
56
+ return $ this ->parseTokenResponse ($ this ->sendRequestTokenRequest ($ params ), true );
57
+ }
58
+
59
+ /**
60
+ * Sends a request to the request token endpoint with the given params
61
+ */
62
+ protected function sendRequestTokenRequest (array $ requestTokenRequestParams ):ResponseInterface {
63
+
56
64
$ request = $ this ->requestFactory
57
65
->createRequest ('POST ' , $ this ->requestTokenURL )
58
- ->withHeader ('Authorization ' , 'OAuth ' .QueryUtil::build ($ params , null , ', ' , '" ' ))
66
+ ->withHeader ('Authorization ' , 'OAuth ' .QueryUtil::build ($ requestTokenRequestParams , null , ', ' , '" ' ))
59
67
->withHeader ('Accept-Encoding ' , 'identity ' ) // try to avoid compression
60
68
->withHeader ('Content-Length ' , '0 ' ) // tumblr requires a content-length header set
61
69
;
@@ -64,7 +72,7 @@ public function getRequestToken():AccessToken{
64
72
$ request = $ request ->withHeader ($ header , $ value );
65
73
}
66
74
67
- return $ this ->parseTokenResponse ( $ this -> http ->sendRequest ($ request), true );
75
+ return $ this ->http ->sendRequest ($ request );
68
76
}
69
77
70
78
/**
@@ -153,18 +161,30 @@ protected function getSignature(
153
161
154
162
/**
155
163
* @inheritDoc
164
+ * @throws \chillerlan\OAuth\Providers\ProviderException
165
+ */
166
+ public function getAccessToken (string $ requestToken , string $ verifier ):AccessToken {
167
+ $ token = $ this ->storage ->getAccessToken ($ this ->serviceName );
168
+
169
+ if ($ requestToken !== $ token ->accessToken ){
170
+ throw new ProviderException ('request token mismatch ' );
171
+ }
172
+
173
+ return $ this ->parseTokenResponse ($ this ->sendAccessTokenRequest ($ token , $ verifier ), false );
174
+ }
175
+
176
+ /**
177
+ * Sends the access token request
156
178
*/
157
- public function getAccessToken ( string $ token , string $ verifier ):AccessToken {
179
+ protected function sendAccessTokenRequest ( AccessToken $ token , string $ verifier ):ResponseInterface {
158
180
159
181
$ request = $ this ->requestFactory
160
182
->createRequest ('POST ' , QueryUtil::merge ($ this ->accessTokenURL , ['oauth_verifier ' => $ verifier ]))
161
183
->withHeader ('Accept-Encoding ' , 'identity ' )
162
184
->withHeader ('Content-Length ' , '0 ' )
163
185
;
164
186
165
- $ request = $ this ->getRequestAuthorization ($ request , $ this ->storage ->getAccessToken ($ this ->serviceName ));
166
-
167
- return $ this ->parseTokenResponse ($ this ->http ->sendRequest ($ request ), false );
187
+ return $ this ->http ->sendRequest ($ this ->getRequestAuthorization ($ request , $ token ));
168
188
}
169
189
170
190
/**
0 commit comments