Skip to content

Commit 3b5ba2a

Browse files
committed
Merge pull request #6 from WP-API/check-verifier
Check OAuth verifier when generating access token
2 parents 55ec6af + 817c2b8 commit 3b5ba2a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/class-wp-json-authentication-oauth1.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function parse_header( $header ) {
4646

4747
}
4848

49-
public function get_parameters( $require_token = true ) {
49+
public function get_parameters( $require_token = true, $extra = array() ) {
5050
$params = array_merge( $_GET, $_POST );
5151
$params = wp_unslash( $params );
5252

@@ -74,6 +74,10 @@ public function get_parameters( $require_token = true ) {
7474
$param_names[] = 'oauth_token';
7575
}
7676

77+
if ( ! empty( $extra ) ) {
78+
$param_names = array_merge( $param_names, (array) $extra );
79+
}
80+
7781
$errors = array();
7882
$have_one = false;
7983

@@ -193,7 +197,7 @@ public function dispatch( $route ) {
193197
return $this->generate_request_token( $params );
194198

195199
case 'access':
196-
$params = $this->get_parameters();
200+
$params = $this->get_parameters( true, array( 'oauth_verifier' ) );
197201

198202
if ( is_wp_error( $params ) ) {
199203
return $params;
@@ -204,7 +208,8 @@ public function dispatch( $route ) {
204208

205209
return $this->generate_access_token(
206210
$params['oauth_consumer_key'],
207-
$params['oauth_token']
211+
$params['oauth_token'],
212+
$params['oauth_verifier']
208213
);
209214

210215
default:
@@ -377,7 +382,7 @@ public function get_access_token( $oauth_token ) {
377382
* @param string $oauth_token Request token key
378383
* @return WP_Error|array OAuth token data on success, error otherwise
379384
*/
380-
public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
385+
public function generate_access_token( $oauth_consumer_key, $oauth_token, $oauth_verifier ) {
381386
$token = $this->get_request_token( $oauth_token );
382387
if ( is_wp_error( $token ) ) {
383388
return $token;
@@ -388,6 +393,10 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token ) {
388393
return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized' ), array( 'status' => 401 ) );
389394
}
390395

396+
if ( $oauth_verifier !== $token['verifier'] ) {
397+
return new WP_Error( 'json_oauth1_invalid_verifier', __( 'OAuth verifier does not match' ), array( 'status' => 400 ) );
398+
}
399+
391400
$consumer = $this->get_consumer( $oauth_consumer_key );
392401
if ( is_wp_error( $consumer ) ) {
393402
return $consumer;

0 commit comments

Comments
 (0)