Skip to content

Commit 9dcded1

Browse files
committed
Merge pull request WP-API#19 from WP-API/allow-callback-on-authorize
Set the callback on authorization if given
2 parents 9d96836 + 31d885d commit 9dcded1

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
@@ -75,6 +75,13 @@ public function render_page() {
7575
return $this->token;
7676
}
7777

78+
if ( ! empty( $_REQUEST['oauth_callback'] ) ) {
79+
$resp = $authenticator->set_request_token_callback( $this->token['key'], $_REQUEST['oauth_callback'] );
80+
if ( is_wp_error( $resp ) ) {
81+
return $resp;
82+
}
83+
}
84+
7885
if ( $this->token['authorized'] === true ) {
7986
return $this->handle_callback_redirect( $this->token['verifier'] );
8087
}

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)