This commit is contained in:
James Barnsley
2017-11-10 16:09:05 +13:00
parent b45486de55
commit 091de03559
6 changed files with 3167 additions and 2607 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,154 +0,0 @@
<?php
/**
* LastFM Authentication proxy
*
* To use:
* 1. Create a LastFM App (https://www.last.fm/api/account/create), and paste in your credentials below
* 2. Save this script to a publicly-accessible server
* 3. Set config in mopidy.conf to point to this script
**/
// LastFM app credentials
define('API_URL','http://ws.audioscrobbler.com/2.0/?format=json');
define('API_KEY','269cc2b1dfb1059a89a2db21ceb81d2a');
define('API_SECRET','1551231f57eb3b73801e31bc0e89ab09');
define('REDIRECT_URI','https://jamesbarnsley.nz/auth_lastfm.php?action=start_session');
// Allow cross-domain requests
header("Access-Control-Allow-Origin: *");
// Set our cookies
if (isset($_GET['app'])){
setcookie('mopidy_iris', $_GET['app'], time()+3600);
}
/* ================================================================================= INIT ================ */
/* ======================================================================================================= */
if (isset($_GET['action'])){
switch ($_GET['action']){
case 'authorize':
header('Location: http://www.last.fm/api/auth/?api_key='.API_KEY.'&cb='.REDIRECT_URI);
exit;
case 'start_session':
$session = startSession($_GET['token']);
// Pass our error back to the popup opener
?>
<script type="text/javascript">
window.opener.postMessage( '<?php echo json_encode($session) ?>', "*");
window.close();
</script>
<?php
break;
case 'sign_request':
$data = $_GET;
$signed = signRequest($data);
echo json_encode($signed);
exit;
default:
echo 'Invalid action specified';
die();
}
} else {
echo "No action specified";
die();
}
/* ================================================================================= GETTERS ============= */
/* ======================================================================================================= */
/**
* Start a session
*
* @param $data = array
* @param $post = boolean (POST request)
**/
function startSession($token){
$ch = curl_init();
if (FALSE === $ch){
throw new Exception('Failed to initialize');
}
$data = signRequest(
array(
"method" => "auth.getSession",
"token" => $token
),
false
);
curl_setopt($ch, CURLOPT_URL,API_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)){
echo 'CURL Error: '. curl_error($ch);
}
curl_close($ch);
$response = json_decode($response, true);
// Append our other important values to successful signings
if (!$response['error']){
$response['api_key'] = API_KEY;
}
return $response;
}
/**
* Perform a signed request
*
* @param $data = array
* @param $post = boolean (POST request)
**/
function signRequest($data = array(), $post = true){
unset($data['action']);
$ch = curl_init();
if (FALSE === $ch){
throw new Exception('Failed to initialize');
}
// Make sure we've got our API key included
$request = array_merge(array("api_key" => API_KEY), $data);
// Loop all the values in our request and add to our signature
$signature = "";
ksort($request);
foreach ($request as $key => $value){
$signature.= $key.$value;
}
// Finalize the signature
$signature.= API_SECRET;
$signature = md5($signature);
$request["api_sig"] = $signature;
return $request;
}

View File

@ -38,7 +38,7 @@
// Release details
// These are automatically injected by build.sh
var build = "1509609058";
var build = "1510283272";
var version = "3.6.1";
// Construct the script tag