Skip to content

Commit 31d885d

Browse files
committed
Set the callback on authorization if given
1 parent 55a0b55 commit 31d885d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public function render_page() {
7070
return $this->token;
7171
}
7272

73+
if ( ! empty( $_REQUEST['oauth_callback'] ) ) {
74+
$resp = $authenticator->set_request_token_callback( $this->token['key'], $_REQUEST['oauth_callback'] );
75+
if ( is_wp_error( $resp ) ) {
76+
return $resp;
77+
}
78+
}
79+
7380
if ( $this->token['authorized'] === true ) {
7481
return $this->handle_callback_redirect( $this->token['verifier'] );
7582
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ public function generate_request_token( $params ) {
357357
return $data;
358358
}
359359

360+
public function set_request_token_callback( $key, $callback ) {
361+
$token = $this->get_request_token( $key );
362+
if ( is_wp_error( $token ) ) {
363+
return $token;
364+
}
365+
366+
if ( esc_url_raw( $callback ) !== $callback ) {
367+
return new WP_Error( 'json_oauth1_invalid_callback', __( 'Callback URL is invalid' ) );
368+
}
369+
370+
$token['callback'] = $callback;
371+
update_option( 'oauth1_request_' . $key, $token );
372+
return $token['verifier'];
373+
}
374+
360375
/**
361376
* Authorize a request token
362377
*

0 commit comments

Comments
 (0)