Skip to content

Commit 121ed8b

Browse files
committed
Fixed the nonce check
1 parent 7a70055 commit 121ed8b

File tree

6 files changed

+6
-63
lines changed

6 files changed

+6
-63
lines changed

inc/authentication/namespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function attempt_authentication( $user = null ) {
7575
array(
7676
'status' => WP_Http::FORBIDDEN,
7777
'token' => $token_value,
78-
),
78+
)
7979
);
8080
}
8181

inc/endpoints/class-authorization.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Authorization {
1313
*/
1414
public function register_hooks() {
1515
add_action( 'login_form_' . static::LOGIN_ACTION, array( $this, 'handle_request' ) );
16-
add_action( 'oauth2_authorize_form', array( $this, 'render_page_fields' ) );
1716
}
1817

1918
public function handle_request() {
@@ -22,7 +21,7 @@ public function handle_request() {
2221

2322
switch ( $type ) {
2423
case 'code':
25-
$handler = new Types\Authorization_Code();
24+
$handler = new Types\AuthorizationCode();
2625
break;
2726

2827
case 'token':
@@ -42,8 +41,4 @@ public function handle_request() {
4241
wp_die( $result->get_error_message() );
4342
}
4443
}
45-
46-
public function render_page_fields() {
47-
wp_nonce_field( 'json_oauth2_authorize' );
48-
}
4944
}

inc/tokens/class-token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public function is_valid() {
2929
public function get_meta_key() {
3030
return static::get_meta_prefix() . $this->get_key();
3131
}
32-
public function to_meta_value();
32+
public abstract function to_meta_value();
3333
}

inc/types/class-base.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public function handle_authorisation() {
4646
return $this->render_form( $client );
4747
}
4848

49-
5049
// Check nonce.
5150
$nonce = wp_unslash( $_POST['_wpnonce'] );
5251
if ( ! wp_verify_nonce( $nonce, $this->get_nonce_action( $client ) ) ) {
@@ -56,8 +55,6 @@ public function handle_authorisation() {
5655
);
5756
}
5857

59-
60-
6158
$submit = wp_unslash( $_POST['wp-submit'] );
6259
if ( empty( $submit ) ) {
6360
return new WP_Error();
@@ -118,6 +115,7 @@ public function render_form( Client $client ) {
118115
* @param Client $client Client to generate nonce for.
119116
*/
120117
protected function get_nonce_action( Client $client ) {
121-
return sprintf( 'oauth2_authorize:%s', $client->get_post_id() );
118+
// return sprintf( 'oauth2_authorize:%s', $client->get_post_id() );
119+
return 'json_oauth2_authorize';
122120
}
123121
}

lib/class-wp-rest-oauth2-ui.php

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class WP_REST_OAuth2_UI {
2828
*/
2929
public function register_hooks() {
3030
add_action( 'login_form_oauth2_authorize', array( $this, 'handle_request' ) );
31-
// add_action( 'oauth2_authorize_form', array( $this, 'page_fields' ) );
3231
}
3332

3433
/**
@@ -59,55 +58,6 @@ public function render_page() {
5958
$auth_code->handle_authorisation();
6059
}
6160

62-
/**
63-
* Output required hidden fields
64-
*
65-
* Outputs the required hidden fields for the authorization page, including
66-
* nonce field.
67-
*/
68-
public function page_fields() {
69-
wp_nonce_field( sprintf( 'oauth2_authorize:%s', $this->client->get_post_id() ) );
70-
}
71-
72-
/**
73-
* Handle redirecting the user after authorization
74-
*
75-
* @param string $verifier Verification code
76-
* @return null|WP_Error Null on success, error otherwise
77-
*/
78-
/*public function handle_callback_redirect( $verifier ) {
79-
if ( empty( $this->token['callback'] ) || $this->token['callback'] === 'oob' ) {
80-
// No callback registered, display verification code to the user
81-
login_header( __( 'Access Token', 'rest_oauth1' ) );
82-
echo '<p>' . sprintf( __( 'Your verification token is <code>%s</code>', 'rest_oauth1' ), $verifier ) . '</p>';
83-
login_footer();
84-
85-
return null;
86-
}
87-
88-
$callback = $this->token['callback'];
89-
90-
// Ensure the URL is safe to access
91-
$authenticator = new WP_REST_OAuth1();
92-
if ( ! $authenticator->check_callback( $callback, $this->token['consumer'] ) ) {
93-
return new WP_Error( 'json_oauth1_invalid_callback', __( 'The callback URL is invalid', 'rest_oauth1' ), array( 'status' => 400 ) );
94-
}
95-
96-
$args = array(
97-
'oauth_token' => $this->token['key'],
98-
'oauth_verifier' => $verifier,
99-
'wp_scope' => '*',
100-
);
101-
$args = apply_filters( 'json_oauth2_callback_args', $args, $this->token );
102-
$args = urlencode_deep( $args );
103-
$callback = add_query_arg( $args, $callback );
104-
105-
// Offsite, so skip safety check
106-
wp_redirect( $callback );
107-
108-
return null;
109-
}*/
110-
11161
/**
11262
* Display an error using login page wrapper
11363
*

theme/oauth2-authorize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
* Fires inside the lostpassword <form> tags.
7777
*/
7878
do_action( 'oauth2_authorize_form', $client );
79-
wp_nonce_field( 'oauth2_authorize' );
79+
wp_nonce_field( 'json_oauth2_authorize' );
8080
?>
8181

8282
<p class="submit">

0 commit comments

Comments
 (0)