Created
December 23, 2016 05:34
-
-
Save scofennell/24f3cd88fcfbac14bf756e1c9facb4b9 to your computer and use it in GitHub Desktop.
Basic auth creds for Bitbucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Authenticate all of our calls to Bitbucket, so that we can access private repos. | |
* | |
* @param array $args The current args for http requests. | |
* @param string $url The url to which the current http request is going. | |
* @return array $args, filtered to include BB basic auth. | |
*/ | |
public function authenticate_http( $args, $url ) { | |
// Find out the url to Bitbucket. | |
$call = new LXB_GE_Call( 'web', FALSE ); | |
$bb_url = $call -> get_url(); | |
// If we're not calling a Bitbucket download, don't bother. | |
if( ! stristr( $url, $bb_url ) ) { return $args; } | |
if( ! stristr( $url, '.zip' ) ) { return $args; } | |
// Okay, time to append basic auth to the args. | |
$creds = $this -> creds; | |
$args['headers']['Authorization'] = "Basic $creds"; | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment