Skip to content

Commit

Permalink
partial fix for AJAX updates of private
Browse files Browse the repository at this point in the history
Bitbucket repos. Still needs to reload page between AJAX updates. :P
  • Loading branch information
afragen committed Aug 24, 2016
1 parent f25e4d4 commit 0439c1b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GitHub_Updater/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function __construct() {
add_filter( 'extra_theme_headers', array( &$this, 'add_headers' ) );
add_filter( 'extra_plugin_headers', array( &$this, 'add_headers' ) );
add_filter( 'http_request_args', array( 'Fragen\\GitHub_Updater\\API', 'http_request_args' ), 10, 2 );
add_filter( 'http_request_args', array( 'Fragen\\GitHub_Updater\\Bitbucket_API', 'ajax_maybe_authenticate_http' ), 15, 2 );
add_filter( 'upgrader_source_selection', array( &$this, 'upgrader_source_selection' ), 10, 4 );
}

Expand Down
24 changes: 24 additions & 0 deletions src/GitHub_Updater/Bitbucket_API.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,28 @@ public function http_release_asset_auth( $args, $url ) {
*/
protected function add_endpoints( $git, $endpoint ) {}

/**
* Add Basic Authentication $args to http_request_args filter hook
* for private Bitbucket repositories only during AJAX.
*
* @param $args
* @param $url
*
* @return mixed
*/
public static function ajax_maybe_authenticate_http( $args, $url ) {
if ( parent::is_doing_ajax() && ! parent::is_heartbeat() &&
( isset( $_POST['slug'] ) && 1 == parent::$options[ $_POST['slug'] ] &&
false !== stristr( $url, $_POST['slug'] ) )
) {
$username = parent::$options['bitbucket_username'];
$password = parent::$options['bitbucket_password'];
$args['headers']['Authorization'] = 'Basic ' . base64_encode( "$username:$password" );

return $args;
}

return $args;
}

}

0 comments on commit 0439c1b

Please sign in to comment.