Skip to content

Commit dbf8246

Browse files
committed
Merge pull request WP-API#17 from WP-API/check-user-auth
Ensure users are logged in when authorizing
2 parents 55a0b55 + ab1a534 commit dbf8246

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function register_hooks() {
3838
* default wp-login handlers.
3939
*/
4040
public function handle_request() {
41+
if ( ! is_user_logged_in() ) {
42+
wp_safe_redirect( wp_login_url( $_SERVER['REQUEST_URI'] ) );
43+
exit;
44+
}
45+
4146
$response = $this->render_page();
4247
if ( is_wp_error( $response ) ) {
4348
$this->display_error( $response );

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ public function authorize_request_token( $key, $user = null ) {
377377
$user = $user->ID;
378378
}
379379

380+
if ( empty( $user ) ) {
381+
return new WP_Error( 'json_oauth1_invalid_user', __( 'Invalid user specified for access token' ) );
382+
}
383+
380384
$token['authorized'] = true;
381385
$token['verifier'] = wp_generate_password( self::VERIFIER_LENGTH, false );
382386
$token['user'] = $user;

0 commit comments

Comments
 (0)