Skip to content

Instantly share code, notes, and snippets.

@stillatmylinux
Created March 14, 2019 15:20
Show Gist options
  • Save stillatmylinux/949c6758850b78f42ef75c094e7ccde6 to your computer and use it in GitHub Desktop.
Save stillatmylinux/949c6758850b78f42ef75c094e7ccde6 to your computer and use it in GitHub Desktop.
<?php
$consumer_key = '';
$consumer_secret = '';
// If the $_GET parameters are present, use those first.
if ( ! empty( $_GET['consumer_key'] ) && ! empty( $_GET['consumer_secret'] ) ) {
$consumer_key = $_GET['consumer_key']; // WPCS: sanitization ok.
$consumer_secret = $_GET['consumer_secret']; // WPCS: sanitization ok.
}
// if( !isset($_SERVER['PHP_AUTH_USER']) )
// {
// if (isset($_SERVER['HTTP_AUTHORIZATION']) && (strlen($_SERVER['HTTP_AUTHORIZATION']) > 0)){
// list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
// if( strlen($_SERVER['PHP_AUTH_USER']) == 0 || strlen($_SERVER['PHP_AUTH_PW']) == 0 )
// {
// unset($_SERVER['PHP_AUTH_USER']);
// unset($_SERVER['PHP_AUTH_PW']);
// }
// }
// }
// If the above is not present, we will do full basic auth.
if ( ! $consumer_key && ! empty( $_SERVER['PHP_AUTH_USER'] ) && ! empty( $_SERVER['PHP_AUTH_PW'] ) ) {
$consumer_key = $_SERVER['PHP_AUTH_USER']; // WPCS: sanitization ok.
$consumer_secret = $_SERVER['PHP_AUTH_PW']; // WPCS: sanitization ok.
}
echo '<pre>';
var_dump( array(
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret
) );
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment